1
0
forked from leto/LeMA

Transpose now returns Matrix object

This commit is contained in:
Leto 2024-12-24 14:08:43 +01:00
parent 78a8185e19
commit e0d6d480da
2 changed files with 11 additions and 16 deletions

View File

@ -5,15 +5,11 @@ int main()
{
srand(time(0));
Matrix a(3,1);
Matrix a(3,2);
a.Randomize();
Matrix b = a;
a.Print("A");
b.Print("B");
a.Add(&b).Print("A + B");
a.Transpose().Print("Transposed");
return 0;
}

View File

@ -27,7 +27,7 @@ class Matrix{
inline void Print(std::string_view);
inline void Transpose();
inline Matrix Transpose();
// --- Operators
// Assign
@ -168,18 +168,17 @@ void Matrix::Set(float value){
}
// Transpose a matrix
void Matrix::Transpose(){
std::vector<std::vector<float>> buffer = this->values;
this->values = {};
Matrix Matrix::Transpose(){
// Transposed matrix size is inverted
Matrix result(this->values[0].size(), this->values.size());
// Invert matrix size
for(int m = 0; m < buffer[0].size(); m++){
std::vector<float> row = {};
for(int n = 0; n < buffer.size(); n++){
row.push_back(buffer[n][m]);
for(int m = 0; m < result.values.size(); m++){
for(int n = 0; n < result.values[m].size(); n++){
result.values[m][n] = this->values[n][m];
}
this->values.push_back(row);
}
return result;
}
// Randomize a matrix from 0.0F to 10.0F