From fb64bca385424e291798679cb1b296d6c24ce4ab Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Wed, 2 Jul 2025 15:03:04 +0200 Subject: [PATCH] Code is completely ported (I think) --- LinearAlgebra/Matrix.cpp | 13 +++++++++++-- LinearAlgebra/Matrix.h | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/LinearAlgebra/Matrix.cpp b/LinearAlgebra/Matrix.cpp index 6709b23..e792a36 100644 --- a/LinearAlgebra/Matrix.cpp +++ b/LinearAlgebra/Matrix.cpp @@ -52,6 +52,12 @@ Matrix1 Matrix1::Slice(int start, int stop) { return result; } +void Matrix1::UpdateSlice(int start, int stop, const Matrix1& m) const { + for (int ix = start; ix < stop; ix++) { + this->data[ix] = m.data[ix - start]; + } +} + const float& Matrix1::operator()(int ix) const { return data[ix]; } @@ -76,7 +82,7 @@ Matrix2::Matrix2(int nRows, int nCols) : nRows(nRows), nCols(nCols) { } } -Matrix2::Matrix2(float* data, int nRows, int nCols) +Matrix2::Matrix2(int nRows, int nCols, float* data) : nRows(nRows), nCols(nCols), data(data) { this->nValues = nRows * nCols; this->externalData = true; @@ -161,7 +167,6 @@ float& Matrix2::operator()(int row, int col) { return data[row + this->nCols + col]; } - void Matrix2::Clear() { for (int ix = 0; ix < this->nValues; ix++) this->data[ix] = 0; @@ -311,6 +316,10 @@ Matrix2 Matrix2::Slice(int rowStart, int rowStop, int colStart, int colStop) { return r; } +void Matrix2::UpdateSlice(int rowStart, int rowStop, const Matrix2& m) const { + UpdateSlice(rowStart, rowStop, 0, this->nCols, m); +} + void Matrix2::UpdateSlice(int rowStart, int rowStop, int colStart, diff --git a/LinearAlgebra/Matrix.h b/LinearAlgebra/Matrix.h index de677de..9f4d92b 100644 --- a/LinearAlgebra/Matrix.h +++ b/LinearAlgebra/Matrix.h @@ -25,6 +25,7 @@ class Matrix1 { float& operator()(int ix); Matrix1 Slice(int start, int stop); + void UpdateSlice(int start, int stop, const Matrix1& m) const; void Set(unsigned int start, unsigned int stop, float value) { if (stop > this->size) @@ -58,7 +59,7 @@ class Matrix2 { Matrix2(); Matrix2(int nRows, int nCols); - Matrix2(float* data, int nRows, int nCols); + Matrix2(int nRows, int nCols, float* data); Matrix2(const Matrix2& m); Matrix2& operator=(const Matrix2& other); @@ -135,6 +136,7 @@ class Matrix2 { Matrix2 Slice(int rawStart, int rowStop, int colStart, int colStop); + void UpdateSlice(int rowStart, int rowStop, const Matrix2& m) const; void UpdateSlice(int rowStart, int rowStop, int colStart,