RWalib C Array Library User Guide > Searches and Intersections > alibCount
  

alibCount
Counts the nonzero (true) values in an array. The PV-WAVE API for this routine is the WHERE Function.
Prototypes
wvlong alibCountb( wvlong n, UCHAR *b )
wvlong alibCounts( wvlong n, short *b )
wvlong alibCounti( wvlong n, int *b )
wvlong alibCountl( wvlong n, wvlong *b )
wvlong alibCountf( wvlong n, float *b )
wvlong alibCountd( wvlong n, double *b )
wvlong alibCountc( wvlong n, COMPLEX *b )
wvlong alibCountz( wvlong n, DCOMPLEX *b )
Parameters
n — (Input) The number of elements in the source array.
*b — (Input) The source array.
Return value
The number of nonzero elements in the source array.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
   /* make some example data */
   UCHAR    b[ 8] = {0,1,0,2,0,3,0,4};
   COMPLEX  c[16] = {0,0,0,1,0,0,2,0,0,0,3,4,0,0,0,0};
   wvlong nb, nc;
   printf( "\n print the real and complex arrays \n" );
   printf( " and the number of nonzero elements in each" );
      alibinit( NULL, NULL, NULL, NULL );
      alibPrintArrayb( 1, 1, 1, 8, b, NULL );
      alibPrintArrayc( 1, 1, 1, 8, c, NULL );
      nb = alibCountb( 8, b );
      nc = alibCountc( 8, c );
   printf( "\n number of nonzero elements in b: %4lld \n", nb );
   printf( "\n number of nonzero elements in c: %4lld \n", nc );
}
 
Output:
 
 print the real and complex arrays 
 and the number of nonzero elements in each
 
   0   1   0   2   0   3   0   4
 
(  0.000e+00,  0.000e+00) (  0.000e+00,  1.000e+00) (  0.000e+00,  0.000e+00) 
(  2.000e+00,  0.000e+00) (  0.000e+00,  0.000e+00) (  3.000e+00,  4.000e+00) 
(  0.000e+00,  0.000e+00) (  0.000e+00,  0.000e+00) 
 
 number of nonzero elements in b:    4 
 
 number of nonzero elements in c:    3 

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.