Hi all, what is a safe and efficient way to sum the contents of an array
or a matrix, skipping any possible NANs or INFs?

Thanks,
RS

Re: Excluding NAN entries when summing an array by Abdo

Abdo
Thu Sep 21 10:16:14 CDT 2006

"RS" <rsina_no.ssppaamm@comcast.net> wrote in message
news:oMWdnczBh4sQBo_YnZ2dnUVZ_vidnZ2d@comcast.com...
> Hi all, what is a safe and efficient way to sum the contents of an array
> or a matrix, skipping any possible NANs or INFs?

What type/container of array/matrix are you using? How are you summing the
entries up?

--
Abdo Haji-Ali
Programmer
In|Framez



Re: Excluding NAN entries when summing an array by RS

RS
Thu Sep 21 09:30:56 CDT 2006

Abdo Haji-Ali wrote:
> "RS" <rsina_no.ssppaamm@comcast.net> wrote in message
> news:oMWdnczBh4sQBo_YnZ2dnUVZ_vidnZ2d@comcast.com...
>> Hi all, what is a safe and efficient way to sum the contents of an array
>> or a matrix, skipping any possible NANs or INFs?
>
> What type/container of array/matrix are you using? How are you summing the
> entries up?
>

Hi Abdo,

I am using the Blitz class arrays. But never mind that. How about just
sums on simple arrays, something similar to

double mysum(double *my_array,int n)
{
double sum=0;
for(int i=0;i<n;i++)
sum+=my_array[i]; //modify this to skip possible NANs and INFs
return sum;
}

I am new to VC7 (2003). Is there an "is_nan" utility or function that we
can test the contents of a number with?

Thanks,
RS

Re: Excluding NAN entries when summing an array by RS

RS
Thu Sep 21 09:33:38 CDT 2006

Abdo Haji-Ali wrote:
> "RS" <rsina_no.ssppaamm@comcast.net> wrote in message
> news:oMWdnczBh4sQBo_YnZ2dnUVZ_vidnZ2d@comcast.com...
>> Hi all, what is a safe and efficient way to sum the contents of an array
>> or a matrix, skipping any possible NANs or INFs?
>
> What type/container of array/matrix are you using? How are you summing the
> entries up?
>

Hi Abdo,

I am using the Blitz class arrays. But never mind that. How about just
sums on simple arrays, something similar to

double mysum(double *my_array,int n)
{
double sum=0;
for(int i=0;i<n;i++)
sum+=my_array[i]; //modify this to skip possible NANs and INFs
return sum;
}

I am new to VC7 (2003). Is there an "is_nan" utility or function that we
can test the contents of a number with?

Thanks,
RS

Re: Excluding NAN entries when summing an array by Alex

Alex
Thu Sep 21 09:40:38 CDT 2006

RS wrote:
>>> Hi all, what is a safe and efficient way to sum the contents of an array
>>> or a matrix, skipping any possible NANs or INFs?
>>
>> What type/container of array/matrix are you using? How are you summing
>> the
>> entries up?
>>
>
> Hi Abdo,
>
> I am using the Blitz class arrays. But never mind that. How about just
> sums on simple arrays, something similar to
>
> double mysum(double *my_array,int n)
> {
> double sum=0;
> for(int i=0;i<n;i++)
> sum+=my_array[i]; //modify this to skip possible NANs and INFs
> return sum;
> }
>
> I am new to VC7 (2003). Is there an "is_nan" utility or function that we
> can test the contents of a number with?

#include <float.h>

double mysum(double *my_array,int n)
{
double sum=0;
for(int i=0;i<n;i++)
sum += (_finite(my_array[i]) ? my_array[i] : 0);
return sum;
}

HTH
Alex