diff --git a/include/matioCpp/MultiDimensionalArray.h b/include/matioCpp/MultiDimensionalArray.h index 29f45c82..b8dea3f1 100644 --- a/include/matioCpp/MultiDimensionalArray.h +++ b/include/matioCpp/MultiDimensionalArray.h @@ -110,6 +110,11 @@ class matioCpp::MultiDimensionalArray : public matioCpp::Variable * @brief Get the index in the vectorized array corresponding to the provided indices * @param el The desider element * @warning It checks if the element is in the bounds only in debug mode. + * + * Since the array is stored in column-major, an element (i,j,k,l,..) of an array + * of dimensions (n,m,p,k,...) corresponds to a row index + * equal to i + j*n + k*n*m + l*n*m*p +... + * * @return the index in the vectorized array corresponding to the provided indices */ index_type rawIndexFromIndices(const std::vector& el) const; @@ -150,7 +155,7 @@ class matioCpp::MultiDimensionalArray : public matioCpp::Variable /** * @brief Resize the vector. - * @param newSize The new size. + * @param newDimensions The new dimensions. * * @warning This requires to allocate memory for twice the new size. * @warning Previous data is lost. diff --git a/include/matioCpp/impl/MultiDimensionalArray.tpp b/include/matioCpp/impl/MultiDimensionalArray.tpp index b9937531..f3018a5e 100644 --- a/include/matioCpp/impl/MultiDimensionalArray.tpp +++ b/include/matioCpp/impl/MultiDimensionalArray.tpp @@ -57,7 +57,6 @@ matioCpp::MultiDimensionalArray::MultiDimensionalArray(const std::string &nam template matioCpp::MultiDimensionalArray::MultiDimensionalArray(const std::string &name, const std::vector::index_type> &dimensions, matioCpp::MultiDimensionalArray::const_pointer inputVector) { - matioCpp::MultiDimensionalArray::index_type totalElements = 1; for (matioCpp::MultiDimensionalArray::index_type dim : dimensions) { if (dim == 0) @@ -65,8 +64,6 @@ matioCpp::MultiDimensionalArray::MultiDimensionalArray(const std::string &nam std::cerr << "[ERROR][matioCpp::MultiDimensionalArray::MultiDimensionalArray] Zero dimension detected." << std::endl; assert(false); } - - totalElements *= dim; } initializeVariable(name, @@ -131,8 +128,8 @@ bool matioCpp::MultiDimensionalArray::fromVectorizedArray(const std::vector typename matioCpp::MultiDimensionalArray::index_type matioCpp::MultiDimensionalArray::rawIndexFromIndices(const std::vector::index_type> &el) const { - assert(dimensions().size() && numberOfElements() && "[matioCpp::MultiDimensionalArray::rawIndexFromIndices] The array is empty."); - assert(el.size() == dimensions().size() && "[matioCpp::MultiDimensionalArray::rawIndexFromIndices] The input vector el should have the same number of dimensions of the array."); + assert(dimensions().size() > 0 && numberOfElements() > 0 && "[matioCpp::MultiDimensionalArray::rawIndexFromIndices] The array is empty."); + assert(el.size() > 0 == dimensions().size() > 0 && "[matioCpp::MultiDimensionalArray::rawIndexFromIndices] The input vector el should have the same number of dimensions of the array."); assert(el[0] < dimensions()[0] && "[matioCpp::MultiDimensionalArray::operator()] The required element is out of bounds."); typename matioCpp::MultiDimensionalArray::index_type index = 0; @@ -159,7 +156,7 @@ bool matioCpp::MultiDimensionalArray::fromOther(const matioCpp::Variable &oth if (other.isComplex()) { - std::cerr << "[matioCpp::MultiDimensionalArray::fromOther] The input variable is complex, this is not." << std::endl; + std::cerr << "[matioCpp::MultiDimensionalArray::fromOther] Cannot copy a complex a variable to a non-complex one." << std::endl; return false; } @@ -183,7 +180,7 @@ bool matioCpp::MultiDimensionalArray::fromOther(matioCpp::Variable &&other) if (other.isComplex()) { - std::cerr << "[matioCpp::MultiDimensionalArray::fromOther] The input variable is complex, this is not." << std::endl; + std::cerr << "[matioCpp::MultiDimensionalArray::fromOther] Cannot copy a complex a variable to a non-complex one." << std::endl; return false; } diff --git a/include/matioCpp/impl/Vector.tpp b/include/matioCpp/impl/Vector.tpp index dc143e5d..25a46880 100644 --- a/include/matioCpp/impl/Vector.tpp +++ b/include/matioCpp/impl/Vector.tpp @@ -98,7 +98,7 @@ bool matioCpp::Vector::fromOther(const matioCpp::Variable &other) if (other.isComplex()) { - std::cerr << "[matioCpp::Vector::fromOther] The input variable is complex, this is not." << std::endl; + std::cerr << "[matioCpp::Vector::fromOther] Cannot copy a complex a variable to a non-complex one." << std::endl; return false; } @@ -122,7 +122,7 @@ bool matioCpp::Vector::fromOther(matioCpp::Variable &&other) if (other.isComplex()) { - std::cerr << "[matioCpp::Vector::fromOther] The input variable is complex, this is not." << std::endl; + std::cerr << "[matioCpp::Vector::fromOther] Cannot copy a complex a variable to a non-complex one." << std::endl; return false; }