[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-gsl] How to do power and exponent of a vector?
From: |
John D Lamb |
Subject: |
Re: [Help-gsl] How to do power and exponent of a vector? |
Date: |
Sat, 08 Apr 2006 07:57:10 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050921 |
James Bergstra wrote:
>> I want to use gsl to do power of a vector (eg vectorA^0.8) and
>>also exponent of a vector (eg. exp(vectorA)). How can I do this without
>>using loops?
>
> I've written an extension that has exp, and other math.h-ish functions for
> vectors and
> matrices.
>
> http://www-etud.iro.umontreal.ca/~bergstrj/msl/html/index.html
That would explain your interest in streaming SIMD extensions. :-)
It's diffilcult to avoid loops altogether, but you could hide them in a
generic funtion like:
int map( double (*function)( double ), gsl_vector* a, const gsl_vector* b ){
int i;
for( i = 0; i < b->size; ++i )
gsl_vector_set( a, i, function( gsl_vector_get( b, i ) ) );
return 0;
}
I haven't added the usual checks that a and b are nonzero and have the
same size.
Then use (for example) map( exp, a, b ) to do the work.
If you really want to avoid loops you could rewrite this as a recursive
function - in this case it won't look good.
--
JDL