summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/multidim.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-01-14 00:05:33 +0100
committerTyge Løvset <[email protected]>2023-01-14 00:08:57 +0100
commitc5e071c622d6f460aa1ad07b6543ceaaed5209fc (patch)
treed5aad0ee32f47d57301cce8ded60226bd328c98b /misc/examples/multidim.c
parentbb92cdbeaa279d8ef90dff0cf088585a50e7d52c (diff)
downloadSTC-modified-c5e071c622d6f460aa1ad07b6543ceaaed5209fc.tar.gz
STC-modified-c5e071c622d6f460aa1ad07b6543ceaaed5209fc.zip
Merged cmspan into cspan. cspan is now multi-dimensional array view (also 1-dimensional).
Diffstat (limited to 'misc/examples/multidim.c')
-rw-r--r--misc/examples/multidim.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/misc/examples/multidim.c b/misc/examples/multidim.c
index 044693be..2cf16b7f 100644
--- a/misc/examples/multidim.c
+++ b/misc/examples/multidim.c
@@ -1,12 +1,14 @@
// Example from https://en.cppreference.com/w/cpp/container/mdspan
#define i_val int
#include <stc/cstack.h>
-#include <stc/algo/cmspan.h>
+#include <stc/algo/cspan.h>
#include <stdio.h>
-using_cmspan(ispan1, int, 1);
-using_cmspan(ispan2, int, 2);
-using_cmspan(ispan3, int, 3);
-
+
+using_cspan(ispan1, int, 1);
+using_cspan(ispan2, int, 2);
+using_cspan(ispan3, int, 3);
+
+
int main()
{
cstack_int v = {0};
@@ -14,20 +16,20 @@ int main()
cstack_int_push(&v, *i.ref);
// View data as contiguous memory representing 12 ints
- ispan1 ms1 = cmspan_make(v.data, 12);
+ ispan1 ms1 = cspan_make(v.data, 12);
// View data as contiguous memory representing 2 rows of 6 ints each
- ispan2 ms2 = cmspan_make(v.data, 2, 6);
+ ispan2 ms2 = cspan_make(v.data, 2, 6);
// View the same data as a 3D array 2 x 3 x 2
- ispan3 ms3 = cmspan_make(v.data, 2, 3, 2);
+ ispan3 ms3 = cspan_make(v.data, 2, 3, 2);
// write data using 2D view
- for(unsigned i=0; i != ms2.dim[0]; i++)
- for(unsigned j=0; j != ms2.dim[1]; j++)
- *cmspan_at(&ms2, i, j) = i*1000 + j;
+ for (unsigned i=0; i != ms2.dim[0]; i++)
+ for (unsigned j=0; j != ms2.dim[1]; j++)
+ *cspan_at(&ms2, i, j) = i*1000 + j;
// print data using 1D view
- for(unsigned i=0; i != ms1.dim[0]; i++)
- printf(" %d", *cmspan_at(&ms1, i));
+ for (unsigned i=0; i != ms1.dim[0]; i++)
+ printf(" %d", *cspan_at(&ms1, i));
puts("");
c_FOREACH (i, ispan1, ms1)
@@ -35,13 +37,13 @@ int main()
puts("");
// read back using 3D view
- for(unsigned i=0; i != ms3.dim[0]; i++)
+ for (unsigned i=0; i != ms3.dim[0]; i++)
{
printf("slice @ i = %u\n", i);
- for(unsigned j=0; j != ms3.dim[1]; j++)
+ for (unsigned j=0; j != ms3.dim[1]; j++)
{
- for(unsigned k=0; k != ms3.dim[2]; k++)
- printf("%d ", *cmspan_at(&ms3, i, j, k));
+ for (unsigned k=0; k != ms3.dim[2]; k++)
+ printf("%d ", *cspan_at(&ms3, i, j, k));
puts("");
}
}