Use memcpy now for copying data and indicate how the data is stored

This commit is contained in:
Kinar 2023-12-14 08:56:38 -08:00
parent 6fab3a8b85
commit f4bbfef674

View File

@ -27,13 +27,13 @@ void CppConvertToMatrix(const Eigen::MatrixXf& in, ::Matrix* out) {
out->cols = in.cols(); out->cols = in.cols();
out->data = new float[out->rows * out->cols]; out->data = new float[out->rows * out->cols];
// Copy data from Eigen matrix to C-style matrix. // Copies data from an Eigen matrix (default column-major) to a C-style
// This operation copies the elements sequentially as they appear in the Eigen // matrix, preserving the sequence of elements as per the Eigen matrix's
// matrix's internal storage, regardless of whether it's stored in row-major // internal storage (column-major order by default).
// or column-major order and ensures the integrity of data during the if (!in.IsRowMajor) {
// transfer. // Safe to use memcpy when the Eigen matrix is in its default column-major
for (int i = 0; i < out->rows * out->cols; ++i) { // order.
out->data[i] = in.data()[i]; memcpy(out->data, in.data(), sizeof(float) * out->rows * out->cols);
} }
} }