CUDA
C/C++    Fortran   

Set operations: union, unique, intersection, ...

Functions

array setunique (const array &input)
 unique values
void setunique (array &values, array &indices, array &locations, const array &input)
array setunion (const array &A, const array &B)
 union of two vectors
void setunion (array &U, array &IA, array &IB, const array &A, const array &B)
 union of two vectors and their indices
array setintersect (const array &A, const array &B)
 intersection of two vectors
void setintersect (array &U, array &IA, array &IB, const array &A, const array &B)
 intersection of two vectors and their indices

Function Documentation

array af::setunique ( const array &  input)

unique values

       array input = constant(1,5, 1);
       input(1, 0) = 3;
       input(2, 0) = 2;
       input(3, 0) = 3;
       print(input);             // 1 3 2 3 1
       array values = setunique(input);
       print(values);            // 1 2 3
Parameters:
[in]inputtreated as vector
Returns:
unique values
void af::setunique ( array &  values,
array &  indices,
array &  locations,
const array &  input 
)
       array input = constant(1,5, 1);
       input(1, 0) = 3;
       input(2, 0) = 2;
       input(3, 0) = 3;
       print(input);             // 1 3 2 3 1
       array values, indices, locations;
       setunique(values, indices, locations, input);
       print(values);            // 1 2 3
       print(indices);           // 0 2 1
       print(locations);         // 0 2 1 2 0
       print(input(indices));    // 1 2 3 --> same as values
       print(values(locations)); // 1 3 2 3 1 --> same as input

unique elements in a vector and their indicies

Parameters:
[out]values,:The unique values from the input vector
[out]indices,:The index of the first instance of the unique value
[out]locations,:Location of each input element in the unique values vector
[in]input
array af::setunion ( const array &  A,
const array &  B 
)

union of two vectors

       array a = array(seq(5));
       array b = array(seq(5))-2*constant(1,5);
       print(a);  //  0  1  2  3  4
       print(b);  // -2 -1  0  1  2
       array c = setunion(a,b);
       print(c);  // -2 -1  0  1  2  3  4
Parameters:
[in]A
[in]B
Returns:
union of A and B
void af::setunion ( array &  U,
array &  IA,
array &  IB,
const array &  A,
const array &  B 
)

union of two vectors and their indices

       array a = array(seq(5));
       array b = array(seq(5))-2*constant(1,5);
       print(a);  //  0  1  2  3  4
       print(b);  // -2 -1  0  1  2
       array u, idxa, idxb;
       setunion(u, idxa, idxb, a, b);
       print(u);  // -2 -1  0  1  2  3  4
       print(idxa);  // 0 1 2 3 4
       print(idxb);  // 0 1
Parameters:
[out]Uvalues found in either A or B
[out]IAindices of values present in A
[out]IBindices of values present in B but not in A
[in]A
[in]B
array af::setintersect ( const array &  A,
const array &  B 
)

intersection of two vectors

       array a = array(seq(5));
       array b = array(seq(5))-2*constant(1,5);
       print(a);  //  0  1  2  3  4
       print(b);  // -2 -1  0  1  2
       array c = setunion(a,b);
       print(c);  //  0  1  2
Parameters:
[in]A
[in]B
Returns:
values found in both vectors
void af::setintersect ( array &  U,
array &  IA,
array &  IB,
const array &  A,
const array &  B 
)

intersection of two vectors and their indices

       array a = array(seq(5));
       array b = array(seq(5))-2*constant(1,5);
       print(a);  //  0  1  2  3  4
       print(b);  // -2 -1  0  1  2
       array i, idxa, idxb;
       setintersect(i, idxa, idxb, a, b);
       print(i);  // 0 1 2
       print(idxa);  // 0 1 2
       print(idxb);  // 2 3 4
Parameters:
[out]Uvalues found in both A and B
[out]IAThe indices of values in A present in B
[out]IBThe indices of values in B present in A
[in]A
[in]B