This would be a variadic function with signature:
matrix build_matrix(int I, int J, Fn f, T1 arg1,...TN argN) (name up for debate)
where Fn is a function (int, int, T1, ..., TN) => real
It returns a matrix M such that M[i,j] = f(i,j, arg1, ... argN)
The real advantage to this function is that it can do local autodiff, which will improve memory usage/locality and allow us to have the returned matrix be a SoA matrix (cf #2344 (comment)).
Once implemented, build_[row]_vector is the obvious extension.
This would be a variadic function with signature:
matrix build_matrix(int I, int J, Fn f, T1 arg1,...TN argN)(name up for debate)where
Fnis a function(int, int, T1, ..., TN) => realIt returns a matrix
Msuch thatM[i,j] = f(i,j, arg1, ... argN)The real advantage to this function is that it can do local autodiff, which will improve memory usage/locality and allow us to have the returned matrix be a SoA matrix (cf #2344 (comment)).
Once implemented,
build_[row]_vectoris the obvious extension.