RWalib C Array Library User Guide > Relational Operations > alibEq
  

alibEq
Applies the == operator element-wise to scalar or array arguments. Like most of the relational operations, this routine returns a Boolean array of 0's and 1's. alibCount and alibFind can be used to count and retrieve the indices of the true values (the 1's). Often a Boolean array is combined with another as input to one of the logical array operations, which in turn produces another Boolean array. The PV-WAVE API for this routine is the operator EQ.
Prototypes
void alibEqb( wvlong m, wvlong n, UCHAR *p, UCHAR *q, UCHAR *r )
void alibEqs( wvlong m, wvlong n, short *p, short *q, UCHAR *r )
void alibEqi( wvlong m, wvlong n, int *p, int *q, UCHAR *r )
void alibEql( wvlong m, wvlong n, wvlong *p, wvlong *q, UCHAR *r )
void alibEqf( wvlong m, wvlong n, float *p, float *q, UCHAR *r )
void alibEqd( wvlong m, wvlong n, double *p, double *q, UCHAR *r )
void alibEqc( wvlong m, wvlong n, COMPLEX *p, COMPLEX *q, UCHAR *r )
void alibEqz( wvlong m, wvlong n, DCOMPLEX *p, DCOMPLEX *q, UCHAR *r )
Parameters
m — (Input) The number of elements in the first array operand. A value of 0 indicates that the first operand is a scalar.
n — (Input) The number of elements in the second array operand. A value of 0 indicates that the second operand is a scalar. If both operands are arrays then n must equal m.
*p — (Input) The pointer to the first operand.
*q — (Input) The pointer to the second operand.
*r — (Input/Output) The destination array. On return, array r contains the the result of applying == to the two operands, element-wise. For UCHAR inputs this operation can be done in-place, i.e., r can equal p or q.
Example 1
This example is straight-forward, using UCHAR and COMPLEX arrays.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
   /* make up some data for the examples */
   UCHAR *b, *c;
   UCHAR    b0[6]={2,0,1,0,2,0}, b1[6]={1,0,1,2,1,0};
   COMPLEX  c0[6]={1,0,0,0,0,1,0,0,1,0,0,0}, c1[6]={0,1,0,0,0,1,1,0,0,1,0,0};
   /* make output arrays */
   b = (UCHAR*)malloc(6*sizeof(UCHAR));
   c = (UCHAR*)malloc(6*sizeof(UCHAR));
   printf( "\n\n show vectors b0 and b1, and show matrices c0 and c1" );
      alibinit( NULL, NULL, NULL, NULL );
      alibPrintArrayb( 1, 1, 1, 6, b0, NULL );
      alibPrintArrayb( 1, 1, 1, 6, b1, NULL );
      alibPrintArrayc( 1, 1, 2, 3, c0, NULL );
      alibPrintArrayc( 1, 1, 2, 3, c1, NULL );
   printf( "\n\n show where b0 equals b1[1] and where c0 equals c1[1]" );
      alibEqb( 6, 0, b0, &b1[1], b );
      alibEqc( 6, 0, c0, &c1[1], c );
      alibPrintArrayb( 1, 1, 1, 6, b, NULL );
      alibPrintArrayb( 1, 1, 2, 3, c, NULL );
   printf( "\n\n show where b1 equals b0[2] and where c1 equals c0[2]" );
      alibEqb( 0, 6, &b0[2], b1, b );
      alibEqc( 0, 6, &c0[2], c1, c );
      alibPrintArrayb( 1, 1, 1, 6, b, NULL );
      alibPrintArrayb( 1, 1, 2, 3, c, NULL );
   printf( "\n\n show where b1 equals b0 and where c1 equals c0" );
      alibEqb( 6, 6, b0, b1, b );
      alibEqc( 6, 6, c0, c1, c );
      alibPrintArrayb( 1, 1, 1, 6, b, NULL );
      alibPrintArrayb( 1, 1, 2, 3, c, NULL );
}
 
Output:
 
 show vectors b0 and b1, and show matrices c0 and c1
 
   2   0   1   0   2   0
 
   1   0   1   2   1   0
 
(  1.000e+00,  0.000e+00) (  0.000e+00,  0.000e+00) (  0.000e+00,  1.000e+00) 
(  0.000e+00,  0.000e+00) (  1.000e+00,  0.000e+00) (  0.000e+00,  0.000e+00) 
 
(  0.000e+00,  1.000e+00) (  0.000e+00,  0.000e+00) (  0.000e+00,  1.000e+00) 
(  1.000e+00,  0.000e+00) (  0.000e+00,  1.000e+00) (  0.000e+00,  0.000e+00) 
 
 show where b0 equals b1[1] and where c0 equals c1[1]
 
   0   1   0   1   0   1
 
   0   1   0
   1   0   1
 
 show where b1 equals b0[2] and where c1 equals c0[2]
 
   1   0   1   0   1   0
 
   1   0   1
   0   1   0
 
 show where b1 equals b0 and where c1 equals c0
 
   0   1   1   0   0   1
 
   0   1   1
   0   0   1
 
Example 2
This example shows how to retrieve the indices where the elements in one array occur in a second array but do not occur in a third array. The alibEqb-alibAndb sequence is done in-place.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
   UCHAR b[5]={0,1,1,2,4}, b0[4]={3,4,5,1}, b1[3]={4,0,2}, j0[5], j1[5], z=0;
   wvlong n, *k;
   alibinit( NULL, NULL, NULL, NULL );
   alibIntersectSb( 5, 4, b, b0, j0 );
   alibIntersectSb( 5, 3, b, b1, j1 );
   alibEqb( 5, 0, j1, &z, j1 );
   alibAndb( 5, 5, j0, j1, j1 );
   n = alibCountb( 5, j1 );
   k = (wvlong*)malloc(n*sizeof(wvlong));
   alibFindb( n, j1, k );
   alibPrintArrayl( 1, 1, 1, n, k, NULL );
}
 
Output:
 
                    1                    2

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.