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