Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
5 Views

Sum of powers

Is there any method to compute sum of powers without using extra space?
P.S. I need this to compute p-norm of the vector.
0 Kudos
12 Replies
Highlighted
Employee
5 Views

Hi,

Here are list of power functions implemented in IPP as per IEEE-754 standard.

http://software.intel.com/sites/products/documentation/hpc/ipp/ipps/ipps_ch12/ch12_Intro.html

Regards,

Naveen Gv

0 Kudos
Highlighted
Beginner
5 Views

Thanks.
But I need to compute the following:
s = pow(a[0], p) + pow(a[1], p) + ... + pow(a[n - 1], p)
To calculate such a sum I need an extra space because I can't destroy the original content of the array:
1. Use Powx function to compute powers:
b = pow(a, p), i = 0 .. n - 1
2. Use Sumfunction to compute sum:
s = b[0] + b[1] + ... + b[n - 1]
In certain situations I should also compute absolute values before computing powers.
The question was whether I could compute such sums without utilizing an extra space. Do you have any suggestions how to do it?
0 Kudos
Highlighted
Employee
5 Views

Hello,

It does not look easy with IPP function call. If the code cares about the memory use it will cause, can it use a small temporary data block, for example, 128size ofdata? Calculate the first 128 data first, then next 128 data,etc.

Thanks,
Chao
0 Kudos
Highlighted
Beginner
5 Views

Hello,

It does not look easy with IPP function call. If the code cares about the memory use it will cause, can it use a small temporary data block, for example, 128size ofdata? Calculate the first 128 data first, then next 128 data,etc.

Thanks,
Chao

What about MKL + IPP? Maybe using these two libraries it's possible to accomplish the required result?
0 Kudos
Highlighted
Employee
5 Views


MKL vdPowx( n, a, b, y ) support in-place operation. You may call this function, put the out-put value into a, then sum the a value.

Thanks,
Chao

0 Kudos
Highlighted
Beginner
5 Views


MKL vdPowx( n, a, b, y ) support in-place operation. You may call this function, put the out-put value into a, then sum the a value.

Thanks,
Chao

I know about this, but this function will destroy the original content of the array. I'd like to find a way to compute sum of powers without using additional buffer. Of course, I can do it in the following manner:
double sum = 0.0;
for (int i = 0; i < n; ++i)
{
sum += pow(a, x);
}
But I was hoping to find a way to do it faster by using MKL and IPP.
0 Kudos
Highlighted
5 Views

Hello,

I think it should be possible to achieve that with call of two IPP functions (ippsPowx and ippsSum) something like pseudo code below


// allocate memory for vector ofresulted power values
// n - is lenght of vector
pow_a_x = ippMalloc(n*sizeof(Ipp32f))

Ipp32f x; //value of power you want to raise elements of vector a

//raise eachelements of vector a to power x
ippsPowx_32f_A24(a, x, pow_a_x);

Ipp32f sum;
// compute sum of elements of array pow_a_x
ippsSum_32f(pow_a_x, n, ∑, ippAlgHintAccurate);

Function ippsPowx declared in ippvm.h and function ippsSum decleared in ipps.h file. You will need to link with ipps.lib and ippvm.lib libraries.

Regards,
Vladimir
0 Kudos
Highlighted
Beginner
5 Views

Hello,

I think it should be possible to achieve that with call of two IPP functions (ippsPowx and ippsSum) something like pseudo code below


// allocate memory for vector ofresulted power values
// n - is lenght of vector
pow_a_x = ippMalloc(n*sizeof(Ipp32f))

Ipp32f x; //value of power you want to raise elements of vector a

//raise eachelements of vector a to power x
ippsPowx_32f_A24(a, x, pow_a_x);

Ipp32f sum;
// compute sum of elements of array pow_a_x
ippsSum_32f(pow_a_x, n, ∑, ippAlgHintAccurate);

Function ippsPowx declared in ippvm.h and function ippsSum decleared in ipps.h file. You will need to link with ipps.lib and ippvm.lib libraries.

Regards,
Vladimir

Thanks. But you have not read my posts carefully. The question is if I can compute sum of powers without allocating extra array and without destroying the content of original array.
Currently I have several alternatives:
1. Allocate full length array and use MKL/IPP in the way similar to the one you proposed.
2. Do it manually. No extra space is required.
3. Allocate small array and compute the sum of powers by blocks (thanks to Chao Y for proposition).
It seems strange that such libraries like MKL and IPP doesn't have required functionality.
0 Kudos
Highlighted
5 Views

Oh, yes. I did not notice you already consider that variant. But I do not thinkit is really strange that libraries does not have this particular variant implemented as single call. More important they provide you with building blocks which are primitive enough that you may construct any variant. That is more flexible approach, I think.

Vladimir
0 Kudos
Highlighted
Beginner
5 Views

You are right, but in some situations (i.e. like this) there are not enough building blocks to perform required operations efficiently.
P. S. By the way, Intel IPP library has routines for computing L1, L2 or infinity norm, but has no routine to compute the general case (I mean p-norm).
0 Kudos
Highlighted
Beginner
5 Views

Vitali,

are you bound to MKL/IPP?? Otherwise you could program a simple loop using intrinsics and short vector math library, see compiler documentation. You only need _mm_pow_pd, _mm_add_pd and a final _mm_hadd_pd.

Best regards, TJ
0 Kudos
Highlighted
Beginner
5 Views

Quoting TJ04
Vitali,

are you bound to MKL/IPP?? Otherwise you could program a simple loop using intrinsics and short vector math library, see compiler documentation. You only need _mm_pow_pd, _mm_add_pd and a final _mm_hadd_pd.

Best regards, TJ

TJ,

I am afraid that I'm bound to MKL+IPP (we don't use Intel Compiler), but in any case thanks for information.
Best regards,
Vitali.
0 Kudos