mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-03-07 18:27:40 +08:00
Handle empty tensors in the print functions
This commit is contained in:
parent
de32f8d656
commit
c58df31747
@ -26,10 +26,15 @@ struct TensorPrinter {
|
|||||||
typedef typename internal::remove_const<typename Tensor::Scalar>::type Scalar;
|
typedef typename internal::remove_const<typename Tensor::Scalar>::type Scalar;
|
||||||
typedef typename Tensor::Index Index;
|
typedef typename Tensor::Index Index;
|
||||||
const Index total_size = internal::array_prod(tensor.dimensions());
|
const Index total_size = internal::array_prod(tensor.dimensions());
|
||||||
const Index first_dim = Eigen::internal::array_get<0>(tensor.dimensions());
|
if (total_size == 0) {
|
||||||
static const int layout = Tensor::Layout;
|
os << "Empty tensor of rank " << Rank;
|
||||||
Map<const Array<Scalar, Dynamic, Dynamic, layout> > matrix(const_cast<Scalar*>(tensor.data()), first_dim, total_size/first_dim);
|
}
|
||||||
os << matrix;
|
else {
|
||||||
|
const Index first_dim = Eigen::internal::array_get<0>(tensor.dimensions());
|
||||||
|
static const int layout = Tensor::Layout;
|
||||||
|
Map<const Array<Scalar, Dynamic, Dynamic, layout> > matrix(const_cast<Scalar*>(tensor.data()), first_dim, total_size/first_dim);
|
||||||
|
os << matrix;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -41,8 +46,13 @@ struct TensorPrinter<Tensor, 1> {
|
|||||||
typedef typename internal::remove_const<typename Tensor::Scalar>::type Scalar;
|
typedef typename internal::remove_const<typename Tensor::Scalar>::type Scalar;
|
||||||
typedef typename Tensor::Index Index;
|
typedef typename Tensor::Index Index;
|
||||||
const Index total_size = internal::array_prod(tensor.dimensions());
|
const Index total_size = internal::array_prod(tensor.dimensions());
|
||||||
Map<const Array<Scalar, Dynamic, 1> > array(const_cast<Scalar*>(tensor.data()), total_size);
|
if (total_size == 0) {
|
||||||
os << array;
|
os << "Empty tensor of rank 1";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Map<const Array<Scalar, Dynamic, 1> > array(const_cast<Scalar*>(tensor.data()), total_size);
|
||||||
|
os << array;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user