function_mapping.h
Method for applying functions element-wise.
- Author
Brian Jackson (bjack205@gmail.com)
- Date
2022-01-30
- Copyright
Copyright (c) 2022
Functions
-
enum slap_ErrorCode slap_Map(Matrix mat, sfloat (*function)(sfloat))
Applies a function element-wise to every element in the matrix.
Applies
mat[k] = function(mat[k])for all elements- Parameters:
mat – A valid matrix (can be dense or strided)
function – A function pointer that takes and returns a sfloat
- Returns:
-
enum slap_ErrorCode slap_BinaryMap(Matrix C, Matrix A, Matrix B, sfloat (*function)(sfloat, sfloat))
Applies a function element-wise to a pair of matrices.
Given a function pointer \(c = f(x,y)\), this function applies this operation element-wise, storing the output in C.
The matrices must all be the same size (but can have different strides).
The matrices can be aliased.
Example
For more details, see thesfloat binary_op(sfloat x, sfloat y) { return 2 * x - y * x; } int main() { // Initialize matrices ... slap_BinaryMap(C, A, B, binary_op); // Clean-up operations ... }BinaryMaptest intest/matrix_test.cpp.- Parameters:
C – [out] Destination matrix
A – [in] Input matrix, provides first arguments to function
B – [in] Input matrix, provides second arguments to function
function – A function that takes two sfloat and returns a sfloat