Skip to content

Commit bb5e2f1

Browse files
if empty trange1, ptr is nullptr using Eigen3.5.x but 0 using Eigen3.4.x
1 parent 0e8f5f2 commit bb5e2f1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/TiledArray/tensor/tensor.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,14 @@ class Tensor {
185185
: range_(range), nbatch_(nbatch) {
186186
size_t size = range_.volume() * nbatch;
187187
allocator_type allocator;
188+
#if EIGEN_HAS_MAJOR_VERSION_5
189+
// Eigen 3.5.x returns nullptr if size=0
190+
auto* ptr = (!size && range_.rank())
191+
? static_cast<allocator_type::pointer>(std::malloc(size))
192+
: allocator.allocate(size);
193+
#else
188194
auto* ptr = allocator.allocate(size);
195+
#endif
189196
// default construct elements of data only if can have any effect ...
190197
if constexpr (!std::is_trivially_default_constructible_v<T>) {
191198
// .. and requested
@@ -1186,10 +1193,10 @@ class Tensor {
11861193
bool empty = this->empty();
11871194
auto range = this->range_;
11881195
auto nbatch = this->nbatch_;
1189-
ar & empty;
1196+
ar& empty;
11901197
if (!empty) {
1191-
ar & range;
1192-
ar & nbatch;
1198+
ar& range;
1199+
ar& nbatch;
11931200
if constexpr (madness::is_input_archive_v<Archive>) {
11941201
*this = Tensor(std::move(range), nbatch, default_construct{true});
11951202
}

0 commit comments

Comments
 (0)