Hello,
The interface to structures such as matrices and vectors allows one to
perform shifting (add, subtract) and scaling (multiply, divide) of all
values in a structure given a constant.
In general, it would be useful to have an abstraction for applying an
arbitrary transform to all elements of a structure. Right now, the user
has two choices:
1) use the get/set routines in a (nested if necessary) loop, e.g.,
for (i = 0; ...)
for (j = 0; ...)
gsl_matrix_set(matrix, i, j,
transform(gsl_matrix_get(matrix, i, j), ...));
2) do the same but accessing the underlying representation directly.
While 2) should be more efficient, it's rather inadvisable. But, 1) is
mostly boilerplate code, and is potentially inefficient if get/set are
not inlined.
My suggestion would be to have an extra routine in the interface, e.g.,
gsl_matrix_apply(gsl_matrix *m, double (*transform)(double x, void
*pars), void *pars);
The task above would then be simply solved with
gsl_matrix_apply(matrix, transform, ...);
The user code is greatly reduced and more readable, and the operation is
likely to be faster than in 1) without exposing implementation details,
as in 2). But, of course, there would be the extra burden for the
developers to implement this consistently for all structure/data type
combinations (trivial though time consuming).
I can of course implement this for my project, but a more portable
solution is preferable. Or, perhaps, I have overlooked in the docs a
functionality like this already implemented?
Regards,
Wacek
--
Waclaw Kusnierczyk
Bioinformatics and Gene Regulation Group
Department of Computer and Information Science
Norwegian University of Science and Technology
Sem Saelands vei 7, 7491 Trondheim, Norway
Theoretical Plant Modeling Lab, iPlant G2P Modeling Tools WG
Department of Agronomy
Kansas State University
Throckmorton Plant Sciences Center, Manhattan, KS 66506, USA
_______________________________________________
Help-gsl mailing list
Help-gsl@gnu.org
https://lists.gnu.org/mailman/listinfo/help-gsl