help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-gsl] applying arbitrary matrix (vector, ...) transforms


From: Waclaw Kusnierczyk
Subject: [Help-gsl] applying arbitrary matrix (vector, ...) transforms
Date: Thu, 16 Jun 2011 09:47:35 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]