I'm working on an open source scientific library (written in C) and one of the operations we want to support is to have a "consumer" copy out arbitrary slices of a multidimensional array from a "producer". For example, let's suppose we have a 4x5 2D array (I apologize for the formatting):
10, 20, 30, 40
50, 60, 70, 80
90, 100, 110, 120
130, 140, 150, 160
170, 180, 190, 200
These are exposed though as a linear array of size 20: 10, 20, 30, 40, 50, 60,..., 200
The user code basically passes in offsets and counts (basically coordinates)that it wants to select:
start[2] = {0, 2} (x start, y start)
count[2] = {3, 2} (x count, y count)
This means that for the x dimension, starting at the 0 position, give me 3 (x coordinate ranges are [0:2], and for the y dimension, starting at position 2, give me 2 (y coordinate ranges then are [3,4]).
This should result in
130, 140, 150, 170, 180, 190
copied into the users buffer (which will be of length 6).
So what is known: we know the dimension sizes of the array (4x5), the number of dimensions (2), and the "coordinates" that the user wants.
The array dimensions can be any number of dimensions... 1, 2, 3.. 6? 100? as it's quite common in scientific apps to have very large dimensions for your arrays.
This is C code, and I honestly can't think of an algorithm and turn it into code to solve the problem. I come from a biology background, so I'm not too experienced with the algorithmic thinking side of coding.
Dos anyone have any suggestions on how to solve this? Much help is appreciated!