diff options
| author | Tyge Løvset <[email protected]> | 2023-01-27 14:39:02 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-01-27 14:39:02 +0100 |
| commit | 5c1b1616f5a20a54c32e57b0bea49f366441356b (patch) | |
| tree | a9f03820446339fce6bb6b04136be7cf92aa3776 /misc/examples/multidim.c | |
| parent | 0c7e627aa27ba42b9a9a4472a4f1cdf857c1a833 (diff) | |
| download | STC-modified-5c1b1616f5a20a54c32e57b0bea49f366441356b.tar.gz STC-modified-5c1b1616f5a20a54c32e57b0bea49f366441356b.zip | |
Added stride to cspan (md), prepared for cspan_slice() function.
Diffstat (limited to 'misc/examples/multidim.c')
| -rw-r--r-- | misc/examples/multidim.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/misc/examples/multidim.c b/misc/examples/multidim.c index 8a5492dc..d69a04fb 100644 --- a/misc/examples/multidim.c +++ b/misc/examples/multidim.c @@ -9,15 +9,27 @@ using_cspan3(ispan, int); int main() { cstack_int v = {0}; - c_FORLIST (i, unsigned, {1,2,3,4,5,6,7,8,9,10,11,12}) + c_FORLIST (i, unsigned, {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}) cstack_int_push(&v, *i.ref); - // View data as contiguous memory representing 12 ints + // View data as contiguous memory representing 24 ints ispan ms1 = cspan_from(&v); + + // View the same data as a 3D array 2 x 3 x 4 + ispan3 ms3 = cspan_multidim(v.data, 2, 2, 6); + // View data as contiguous memory representing 2 rows of 6 ints each - ispan2 ms2 = cspan_multidim(v.data, 2, 6); - // View the same data as a 3D array 2 x 3 x 2 - ispan3 ms3 = cspan_multidim(v.data, 2, 3, 2); + ispan2 ms2 = cspan_at3(&ms3, 0); + ms2.data = cspan_at(&ms2, 1, 1); + ms2.dim[0] = 2; + ms2.dim[1] = 3; + for (unsigned i=0; i != ms2.dim[0]; i++) { + for (unsigned j=0; j != ms2.dim[1]; j++) + printf(" %2d", *cspan_at(&ms2, i, j)); + puts(""); + } + + ms2 = (ispan2)cspan_at3(&ms3, 0); // write data using 2D view for (unsigned i=0; i != ms2.dim[0]; i++) |
