diff --git a/stim/math/matrix.h b/stim/math/matrix.h index 2405539..533e4e9 100644 --- a/stim/math/matrix.h +++ b/stim/math/matrix.h @@ -51,28 +51,24 @@ public: matrix(size_t rows, size_t cols) { R = rows; C = cols; - if (R * C == 0) - M = NULL; - else - M = new T[R * C]; + M = NULL; + if (R * C > 0) + M = (T*) malloc(R * C * sizeof(T)); } - matrix(size_t rows, size_t cols, T* data) { + matrix(size_t rows, size_t cols, const T* data) { R = rows; C = cols; - if (R * C == 0) - M = NULL; - else - M = new T[R * C]; + M = NULL; + if (R * C > 0) + M = (T*)malloc(R * C * sizeof(T)); memcpy(M, data, R * C * sizeof(T)); } matrix(const matrix& cpy){ - - if (cpy.R * cpy.C == 0) - M = NULL; - else - M = new T[cpy.R * cpy.C]; + M = NULL; + if (cpy.R * cpy.C > 0) + M = (T*)malloc(cpy.R * cpy.C * sizeof(T)); memcpy(M, cpy.M, cpy.R * cpy.C * sizeof(T)); R = cpy.R; @@ -222,6 +218,12 @@ public: return result; } + // Reshapes the matrix in place + void reshape(size_t rows, size_t cols) { + R = rows; + C = cols; + } + ///Calculate and return the determinant of the matrix T det() const { if (R != C) { -- libgit2 0.21.4