From fba09a5c402637099ff3ff0069f07c9532229f80 Mon Sep 17 00:00:00 2001 From: LeLeLeLeto Date: Mon, 30 Dec 2024 21:46:11 +0100 Subject: [PATCH] Added passing a function as parameter --- matrices.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/matrices.h b/matrices.h index 57f6c03..2df6e37 100644 --- a/matrices.h +++ b/matrices.h @@ -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++){