diff options
| author | Tyge Løvset <[email protected]> | 2023-01-18 10:39:48 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-01-18 10:39:48 +0100 |
| commit | e879cf117e34aa269cbdd6d73b63325d1e92da7d (patch) | |
| tree | 22b8c448c41a77a4bdfe59c01e1706d72963c615 /docs/cspan_api.md | |
| parent | 17a70908cab0e4064e4913d4f1a109569d24295f (diff) | |
| download | STC-modified-e879cf117e34aa269cbdd6d73b63325d1e92da7d.tar.gz STC-modified-e879cf117e34aa269cbdd6d73b63325d1e92da7d.zip | |
Reverted to use self pointers instead of values, as cspan is not a pure view, but can modify its elements.
Diffstat (limited to 'docs/cspan_api.md')
| -rw-r--r-- | docs/cspan_api.md | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/docs/cspan_api.md b/docs/cspan_api.md index a491185e..2865a1a5 100644 --- a/docs/cspan_api.md +++ b/docs/cspan_api.md @@ -21,27 +21,27 @@ using_cspan4(S, ValueType); // define span types S, S2, S3, S4 w Note that `cspan_make()`, `cmake_from*()`, `cspan_atN()`, `and cspan_subspanN()` require a (safe) cast to its span-type on assignment, but not on initialization of a span variable. All functions are type-safe, and arguments are side-effect safe, except for SpanType arg. which must not have side-effects. ```c -SpanType{N} cspan_make(ValueType* data, size_t xdim, ...); // make N-dimensional cspan -SpanType cspan_from(STCContainer* cnt); // create a 1D cspan from a compatible STC container -SpanType cspan_from_array(ValueType array[]); // create a 1D cspan from a C array -SpanType cspan_from_list(T ValueType, {val0, val1, ...}); // create a 1D cspan from an initializer list -SpanType& cspan_literal(T SpanType, {val0, val1, ...}); // create a 1D cspan compound literal from init list +SpanType{N} cspan_make(ValueType* data, size_t xdim, ...); // make N-dimensional cspan +SpanType cspan_from(STCContainer* cnt); // create a 1D cspan from a compatible STC container +SpanType cspan_from_array(ValueType array[]); // create a 1D cspan from a C array +SpanType cspan_from_list(T ValueType, {val0, val1, ...}); // create a 1D cspan from an initializer list +SpanType& cspan_literal(T SpanType, {val0, val1, ...}); // create a 1D cspan compound literal from init list -void cspan_resize(SpanType{N}* self, size_t xdim, ...); // change the extent of each dimension +void cspan_resize(SpanType{N}* self, size_t xdim, ...); // change the extent of each dimension -size_t cspan_size(SpanType{N} spn); // return number of elements -unsigned cspan_rank(SpanType{N} spn); // return number of dimensions -size_t cspan_index(SpanType{N} spn, size_t x, ...); // index of element +size_t cspan_size(const SpanType{N}* self); // return number of elements +unsigned cspan_rank(const SpanType{N}* self); // return number of dimensions +size_t cspan_index(const SpanType{N}* self, size_t x, ...); // index of element -ValueType* cspan_at(SpanType{N} spn, size_t x, ...); // at(): num of args decides input SpanType{N}. -SpanType cspan_at2(SpanType2 spn, size_t x); // return a 1D subarray cspan. -SpanType{N} cspan_at3(SpanType3 spn, size_t x, ...); // atN(): N decides input SpanType{N}, -SpanType{N} cspan_at4(SpanType4 spn, size_t x, ...); // and num of args decides returned SpanType{N}. +ValueType* cspan_at(SpanType{N}* self, size_t x, ...); // at(): num of args decides input SpanType{N}. +SpanType cspan_at2(SpanType2* self, size_t x); // return a 1D subarray cspan. +SpanType{N} cspan_at3(SpanType3* self, size_t x, ...); // atN(): N decides input SpanType, +SpanType{N} cspan_at4(SpanType4* self, size_t x, ...); // and num of args decides returned SpanType{N}. -SpanType cspan_subspan(SpanType spn, size_t offset, size_t count); // return a slice of a 1D cspan -SpanType2 cspan_subspan2(SpanType2 spn, size_t offset, size_t count); // return a slice of a 2D cspan -SpanType3 cspan_subspan3(SpanType3 spn, size_t offset, size_t count); // return a slice of a 3D cspan -SpanType4 cspan_subspan4(SpanType4 spn, size_t offset, size_t count); // return a slice of a 4D cspan +SpanType cspan_subspan(const SpanType* self, size_t offset, size_t count); // return a slice of a 1D cspan +SpanType2 cspan_subspan2(const SpanType2 self, size_t offset, size_t count); // return a slice of a 2D cspan +SpanType3 cspan_subspan3(const SpanType3 self, size_t offset, size_t count); // return a slice of a 3D cspan +SpanType4 cspan_subspan4(const SpanType4 self, size_t offset, size_t count); // return a slice of a 4D cspan SpanType{N}_iter SpanType_begin(const SpanType{N}* self); SpanType{N}_iter SpanType_end(const SpanType{N}* self); @@ -73,15 +73,15 @@ int main() // define "span3[xd][yd][zd]" FS3 span3 = cspan_make(vec.data, xd, yd, zd); - *cspan_at(span3, 4, 3, 2) = 3.14f; - printf("index: %d", (int)cspan_index(span3, 4, 3, 2)); + *cspan_at(&span3, 4, 3, 2) = 3.14f; + printf("index: %d", (int)cspan_index(&span3, 4, 3, 2)); - FS span1 = cspan_at3(span3, 4, 3); + FS span1 = cspan_at3(&span3, 4, 3); printf("\niterate span1: "); c_FOREACH (i, FS, span1) printf("%g ", *i.ref); - FS2 span2 = cspan_at3(span3, 4); + FS2 span2 = cspan_at3(&span3, 4); printf("\niterate span2: "); c_FOREACH (i, FS2, span2) printf("%g ", *i.ref); @@ -90,15 +90,15 @@ int main() c_FORRANGE (i, span3.dim[0]) { c_FORRANGE (j, span3.dim[1]) { c_FORRANGE (k, span3.dim[2]) - printf(" %2g", *cspan_at(span3, i, j, k)); + printf(" %2g", *cspan_at(&span3, i, j, k)); printf(" |"); } puts(""); } - printf("%g\n", *cspan_at(span3, 4, 3, 2)); - printf("%g\n", *cspan_at(span2, 3, 2)); - printf("%g\n", *cspan_at(span1, 2)); + printf("%g\n", *cspan_at(&span3, 4, 3, 2)); + printf("%g\n", *cspan_at(&span2, 3, 2)); + printf("%g\n", *cspan_at(&span1, 2)); } } ``` |
