summaryrefslogtreecommitdiffhomepage
path: root/docs/cspan_api.md
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-01-18 10:15:33 +0100
committerTyge Løvset <[email protected]>2023-01-18 10:15:33 +0100
commit17a70908cab0e4064e4913d4f1a109569d24295f (patch)
treef4c4181873d6ed456b1d9382a8bd832d93c1d07f /docs/cspan_api.md
parentb6dea03f0c4b9aece389c8133f7e5f94e12bd8e6 (diff)
downloadSTC-modified-17a70908cab0e4064e4913d4f1a109569d24295f.tar.gz
STC-modified-17a70908cab0e4064e4913d4f1a109569d24295f.zip
using_cspanN(S, T, R) now defines S, S1, S2.. (not S1)
Diffstat (limited to 'docs/cspan_api.md')
-rw-r--r--docs/cspan_api.md52
1 files changed, 26 insertions, 26 deletions
diff --git a/docs/cspan_api.md b/docs/cspan_api.md
index 15125e78..a491185e 100644
--- a/docs/cspan_api.md
+++ b/docs/cspan_api.md
@@ -13,47 +13,47 @@ See the c++ classes [std::span](https://en.cppreference.com/w/cpp/container/span
using_cspan(SpanType, ValueType, Rank); // define SpanType with ValueType elements.
// Rank is number of dimensions (max 4)
// Shorthands:
-using_cspan2(S, ValueType); // define span types S1, S2 with Ranks 1, 2.
-using_cspan3(S, ValueType); // define span types S1, S2, S3 with Ranks 1, 2, 3.
-using_cspan4(S, ValueType); // define span types S1.., S4 with Ranks 1, 2, 3, 4.
+using_cspan2(S, ValueType); // define span types S, S2 with ranks 1, 2.
+using_cspan3(S, ValueType); // define span types S, S2, S3 with ranks 1, 2, 3.
+using_cspan4(S, ValueType); // define span types S, S2, S3, S4 with ranks 1, 2, 3, 4.
```
## Methods
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 cspan_make(ValueType* data, size_t xdim, ...); // make N-dimensional cspan
+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* 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 spn); // return number of elements
-unsigned cspan_rank(SpanType spn); // return number of dimensions
-size_t cspan_index(SpanType spn, size_t x, ...); // index of element
+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
+
+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 spn, size_t x, ...); // return value pointer from a 1D, 2D, 3D or 4D cspan
-SpanType1 cspan_at2(SpanType2 spn, size_t x); // return a 1D subarray cspan
-SpanType cspan_at3(SpanType3 spn, size_t x, ...); // return a 2D or 1D subarray cspan
-SpanType cspan_at4(SpanType4 spn, size_t x, ...); // return a 3D, 2D or 1D subarray cspan
-
-SpanType1 cspan_subspan1(SpanType1 spn, size_t offset, size_t count); // return a slice of a 1D cspan
+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_iter SpanType_begin(const SpanType* self);
-SpanType_iter SpanType_end(const SpanType* self);
-void SpanType_next(SpanType_iter* it);
+SpanType{N}_iter SpanType_begin(const SpanType{N}* self);
+SpanType{N}_iter SpanType_end(const SpanType{N}* self);
+void SpanType_next(SpanType{N}_iter* it);
```
## Types
-| Type name | Type definition | Used to represent... |
-|:-----------------|:-----------------------------------------------------|:---------------------|
-| SpanType | `struct { ValueType *data; uint32_t dim[RANK]; }` | The SpanType |
-| SpanType`_value` | `ValueType` | The ValueType |
-| SpanType`_iter` | `struct { ValueType *ref; ... }` | Iterator type |
+| Type name | Type definition | Used to represent... |
+|:--------------------|:-----------------------------------------------|:---------------------|
+| SpanType{N} | `struct { ValueType *data; uint32_t dim[N]; }` | SpanType with rank N |
+| SpanType{N}`_value` | `ValueType` | The ValueType |
+| SpanType{N}`_iter` | `struct { ValueType *ref; ... }` | Iterator type |
## Example
```c
@@ -62,7 +62,7 @@ void SpanType_next(SpanType_iter* it);
#include <stc/cstack.h>
#include <stc/cspan.h>
-using_cspan3(FS, float); // Shorthand to define span types FS1, FS2, and FS3.
+using_cspan3(FS, float); // Shorthand to define span types FS, FS2, and FS3.
int main()
{
@@ -76,9 +76,9 @@ int main()
*cspan_at(span3, 4, 3, 2) = 3.14f;
printf("index: %d", (int)cspan_index(span3, 4, 3, 2));
- FS1 span1 = cspan_at3(span3, 4, 3);
+ FS span1 = cspan_at3(span3, 4, 3);
printf("\niterate span1: ");
- c_FOREACH (i, FS1, span1)
+ c_FOREACH (i, FS, span1)
printf("%g ", *i.ref);
FS2 span2 = cspan_at3(span3, 4);
@@ -90,7 +90,7 @@ int main()
c_FORRANGE (i, span3.dim[0]) {
c_FORRANGE (j, span3.dim[1]) {
c_FORRANGE (k, span3.dim[2])
- printf(" %g", *cspan_at(span3, i, j, k));
+ printf(" %2g", *cspan_at(span3, i, j, k));
printf(" |");
}
puts("");