cross_between

The cross_between operator produces a result array from a set of specified regions of a source array.

Synopsis

cross_between( source_array, region_array )

Summary

cross_between returns an output array with the same schema and values as source_array when those values are within the coordinate intervals specified in the region_array.  Any values outside of the intervals given in region_array will not appear in the output array.

source_array is an n-dimensional array and region_array is a one-dimensional array with 2n attributes (two for each dimension in source_array, datatype int64) containing no empty cells and no null values. Each cell of the region_array describes one contiguous n-dimensional interval of the source array:  the first n attributes specify the lower-bound coordinates of the interval while the remaining n attributes specify the upper-bound coordinates of the interval.

For example, if source_array is a two dimensional matrix, the following cell of region array would define the 2x2 matrix in the upper left of the source_array: [(0,0,1,1)] and this cell would define the 3x3 matrix in the upper left: [(0,0,2,2)].

If you want the result array to include m regions from the source array, region_array will have m cells. Any cell that falls within any of the regions is included in the result array. While each region defines a contiguous set of cells, the complete set of regions themselves need not be contiguous. The regions can overlap; that is, a cell can be included in multiple regions. The output is an array of the same shape as input, where all cells outside of the given regions are marked empty.

You can use the cross_between operator in the FROM clause of an AQL SELECT statement, as a stand-alone operator in a AFL statement, or as an operand within other SciDB operators.

If region_array has replicated distribution, cross_between can be faster.

Example

To select eight cells (in three regions) from a 16-cell array, do the following:

  1. Create and populate a 4×4 array called cbB:

    AFL% create array cbB <attrB1:double>[i=0:3; j=0:3];
    AFL% store(build(cbB,j+1+4*i),cbB); 
  2. Create and populate an array defining three regions of cbB:

    AFL% create array rB <iLo:int64,jLo:int64,iHi:int64,jHi:int64>[rBi=0:2]
    AFL% store(build(rB, '[(0,0,1,1),(1,0,3,0),(2,3,3,3)]',true),rB) 

     
    Note that two of the regions overlap at cell (1,0).
     

  3. Display the contents of the source array:

    AFL% scan(cbB);  


    The output is:

    {i,j} attrB1
    {0,0} 1
    {0,1} 2
    {0,2} 3
    {0,3} 4
    {1,0} 5
    {1,1} 6
    {1,2} 7
    {1,3} 8
    {2,0} 9
    {2,1} 10
    {2,2} 11
    {2,3} 12
    {3,0} 13
    {3,1} 14
    {3,2} 15
    {3,3} 16 

     

  4. Perform the cross_between:

    AFL% cross_between(cbB,rB);  


    The output is:

    {i,j} attrB1
    {0,0} 1
    {0,1} 2
    {1,0} 5
    {1,1} 6
    {2,0} 9
    {2,3} 12
    {3,0} 13
    {3,3} 16Â