Performance improvements
This commit is contained in:
parent
2062e4a71c
commit
5fddebd1bc
@ -3,7 +3,7 @@
|
||||
|
||||
namespace LinearAlgebra {
|
||||
|
||||
#pragma region Matrix1
|
||||
#pragma region Matrix1
|
||||
|
||||
Matrix1::Matrix1(int size) : size(size) {
|
||||
if (this->size == 0)
|
||||
@ -97,6 +97,11 @@ Matrix2 Matrix2::Zero(int nRows, int nCols) {
|
||||
return r;
|
||||
}
|
||||
|
||||
void Matrix2::Clear() {
|
||||
for (int ix = 0; ix < this->nValues; ix++)
|
||||
this->data[ix] = 0;
|
||||
}
|
||||
|
||||
Matrix2 Matrix2::Identity(int size) {
|
||||
return Diagonal(1, size);
|
||||
}
|
||||
@ -129,7 +134,8 @@ Matrix2 Matrix2::Transpose() const {
|
||||
|
||||
for (uint rowIx = 0; rowIx < this->nRows; rowIx++) {
|
||||
for (uint colIx = 0; colIx < this->nCols; colIx++)
|
||||
r.data[colIx * this->nCols + rowIx] = this->data[rowIx * this->nCols + colIx];
|
||||
r.data[colIx * this->nCols + rowIx] =
|
||||
this->data[rowIx * this->nCols + colIx];
|
||||
}
|
||||
return r;
|
||||
}
|
||||
@ -177,10 +183,7 @@ Matrix2 LinearAlgebra::Matrix2::operator*(const Matrix2& B) const {
|
||||
return r;
|
||||
}
|
||||
|
||||
Matrix2 Matrix2::Slice(int rowStart,
|
||||
int rowStop,
|
||||
int colStart,
|
||||
int colStop) {
|
||||
Matrix2 Matrix2::Slice(int rowStart, int rowStop, int colStart, int colStop) {
|
||||
Matrix2 r = Matrix2(rowStop - rowStart, colStop - colStart);
|
||||
|
||||
int resultRowIx = 0;
|
||||
@ -194,14 +197,25 @@ Matrix2 Matrix2::Slice(int rowStart,
|
||||
}
|
||||
|
||||
void Matrix2::UpdateSlice(int rowStart,
|
||||
int rowStop,
|
||||
int colStart,
|
||||
int colStop,
|
||||
const Matrix2& m) const {
|
||||
for (int i = rowStart; i < rowStop; i++) {
|
||||
for (int j = colStart; j < colStop; j++)
|
||||
this->data[i * this->nCols + j] =
|
||||
m.data[(i - rowStart) * m.nCols + (j - colStart)];
|
||||
int rowStop,
|
||||
int colStart,
|
||||
int colStop,
|
||||
const Matrix2& m) const {
|
||||
// for (int i = rowStart; i < rowStop; i++) {
|
||||
// for (int j = colStart; j < colStop; j++)
|
||||
// this->data[i * this->nCols + j] =
|
||||
// m.data[(i - rowStart) * m.nCols + (j - colStart)];
|
||||
// }
|
||||
|
||||
int rRowDataIx = rowStart * this->nCols;
|
||||
int mRowDataIx = 0;
|
||||
for (int rowIx = rowStart; rowIx < rowStop; rowIx++) {
|
||||
rRowDataIx = rowIx * this->nCols;
|
||||
// rRowDataIx += this->nCols;
|
||||
mRowDataIx += m.nCols;
|
||||
for (int colIx = colStart; colIx < colStop; colIx++) {
|
||||
this->data[rRowDataIx + colIx] = m.data[mRowDataIx + (colIx - colStart)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,7 +243,7 @@ Matrix2 LinearAlgebra::Matrix2::Omega(const Vector3& v) {
|
||||
// Matrix2
|
||||
#pragma endregion
|
||||
|
||||
} // namespace LinearAlgbra
|
||||
} // namespace LinearAlgebra
|
||||
|
||||
template <>
|
||||
MatrixOf<float>::MatrixOf(unsigned int rows, unsigned int cols) {
|
||||
|
@ -39,6 +39,7 @@ class Matrix2 {
|
||||
Matrix2 Clone() const;
|
||||
|
||||
static Matrix2 Zero(int nRows, int nCols);
|
||||
void Clear();
|
||||
|
||||
static Matrix2 Identity(int size);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user