Skip to content

Commit d9dd6a6

Browse files
committed
Fix bug in Eigen to NumPy functions (row major vs. col major confusion)
1 parent f95cc64 commit d9dd6a6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/utils/MathUtils.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ inline void npy_save(const std::string & fname,
347347
unsigned int rows = static_cast<unsigned int>(obj.rows());
348348
unsigned int cols = static_cast<unsigned int>(obj.cols());
349349
const unsigned int shape[] = {rows, cols};
350-
cnpy::npy_save(fname, obj.data(), shape, 2, "w", obj.IsRowMajor);
350+
bool colMajor = obj.IsRowMajor ? false : true;
351+
cnpy::npy_save(fname, obj.data(), shape, 2, "w", colMajor);
351352
}
352353

353354
/*! \brief Save Eigen object to a compressed NumPy file
@@ -366,8 +367,9 @@ inline void npz_save(const std::string & fname, const std::string & name,
366367
unsigned int rows = static_cast<unsigned int>(obj.rows());
367368
unsigned int cols = static_cast<unsigned int>(obj.cols());
368369
const unsigned int shape[] = {rows, cols};
370+
bool colMajor = obj.IsRowMajor ? false : true;
369371
std::string mode = overwrite ? "w" : "a";
370-
cnpy::npz_save(fname, name, obj.data(), shape, 2, mode, obj.IsRowMajor);
372+
cnpy::npz_save(fname, name, obj.data(), shape, 2, mode, colMajor);
371373
}
372374

373375
/*! \brief Load NpyArray object into Eigen object

0 commit comments

Comments
 (0)