Compare commits

...

2 Commits

Author SHA1 Message Date
LeLeLeLeto
fba09a5c40 Added passing a function as parameter 2024-12-30 21:46:11 +01:00
LeLeLeLeto
7a2b42e06d Updated gitignore for windows 2024-12-30 21:45:51 +01:00
2 changed files with 15 additions and 1 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
build/*
.vscode/*
main.cpp
main.cpp
main.exe

View File

@ -27,6 +27,8 @@ class Matrix{
inline Matrix Substract(float);
inline Matrix Substract(const Matrix*);
inline Matrix Function(float (*f)(float));
inline void Print(std::string_view);
inline Matrix Transpose();
@ -74,6 +76,17 @@ Matrix Matrix::operator*(float value){
return this->Multiply(value);
}
Matrix Matrix::Function(float (*f)(float)){
Matrix result = this;
for(int m = 0; m < result.values.size(); m++){
for(int n = 0; n < result.values[m].size(); n++){
// Execute function on every value
result.values[m][n] = f(result.values[m][n]);
}
}
return result;
}
// Constructs a zero matrix
Matrix::Matrix(int rows, int cols){
for(int m = 0; m < rows; m++){