summaryrefslogtreecommitdiffhomepage
path: root/docs/cspan_api.md
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-01 10:12:22 +0100
committerTyge Løvset <[email protected]>2023-02-01 10:12:22 +0100
commita8998a52082f86a71bf152c5baa9ebc005871142 (patch)
treee231d86dba26d1495b893432fde7db17ac3eac08 /docs/cspan_api.md
parent6ce6ef3307e52db5813d3c8d6a2cba52df06daf8 (diff)
downloadSTC-modified-a8998a52082f86a71bf152c5baa9ebc005871142.tar.gz
STC-modified-a8998a52082f86a71bf152c5baa9ebc005871142.zip
Update docs formatting and README.md
Diffstat (limited to 'docs/cspan_api.md')
-rw-r--r--docs/cspan_api.md43
1 files changed, 22 insertions, 21 deletions
diff --git a/docs/cspan_api.md b/docs/cspan_api.md
index 8f6f695f..70587f3e 100644
--- a/docs/cspan_api.md
+++ b/docs/cspan_api.md
@@ -9,43 +9,44 @@ The **cspan** is templated non-owning multi-dimensional view of an array. See th
```c
#include <stc/cspan.h>
-using_cspan(SpanType, ValueType, Rank); // define SpanType with ValueType elements.
- // Rank is number of dimensions (max 4)
+using_cspan(SpanType, ValueType); // define a 1-d SpanType with ValueType elements.
+using_cspan(SpanTypeN, ValueType, Rank); // define multi-dimensional span with Rank.
+ // Rank is number of dimensions (max 5)
// Shorthands:
-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.
+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.
+using_cspan5(S, ValueType); // define span types S, S2, .., S5 with ranks 1, 2, 3, 4, 5.
```
## Methods
Note that `cspan_md()`, `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
-SpanTypeN cspan_md(ValueType* data, intptr_t xdim, ...); // create a multi-dimensional cspan
-SpanType cspan_make(T SpanType, {v1, v2, ...}); // make a 1d-dimensional cspan from values
-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
-
-intptr_t cspan_size(const SpanTypeN* self); // return number of elements
-unsigned cspan_rank(const SpanTypeN* self); // return number of dimensions
-intptr_t cspan_index(const SpanTypeN* self, intptr_t x, ...); // index of element
+SpanTypeN cspan_md(ValueType* data, intptr_t xdim, ...); // create a multi-dimensional cspan
+SpanType cspan_make(T SpanType, {v1, v2, ...}); // make a 1d-dimensional cspan from values
+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
+
+intptr_t cspan_size(const SpanTypeN* self); // return number of elements
+unsigned cspan_rank(const SpanTypeN* self); // return number of dimensions
+intptr_t cspan_index(const SpanTypeN* self, intptr_t x, ..); // index of element
-ValueType* cspan_at(SpanTypeN* self, intptr_t x, ...); // at(): num of args specifies rank of input span.
+ValueType* cspan_at(SpanTypeN* self, intptr_t x, ...); // at(): num of args specifies rank of input span.
ValueType* cspan_front(SpanTypeN* self);
ValueType* cspan_back(SpanTypeN* self);
// return a subspan of lower rank:
-SpanType cspan_submd2(SpanType2* self, intptr_t x); // return a 1d subspan from a 2d span.
-SpanTypeN cspan_submd3(SpanType3* self, intptr_t x, ...); // return a 1d or 2d subspan from a 3d span.
-SpanTypeN cspan_submd4(SpanType4* self, intptr_t x, ...); // number of args determines rank of output span.
+SpanType cspan_submd2(SpanType2* self, intptr_t x); // return a 1d subspan from a 2d span.
+SpanTypeN cspan_submd3(SpanType3* self, intptr_t x, ...); // return a 1d or 2d subspan from a 3d span.
+SpanTypeN cspan_submd4(SpanType4* self, intptr_t x, ...); // number of args determines rank of output span.
+SpanTypeN cspan_submd5(SpanType5* self, intptr_t x, ...);
- // return a sliced span of same rank:
-void cspan_slice(SpanTypeN* self, {x0,x1}, {y0,y1},...); // slice multidim span into a md subspan.
+void cspan_slice(SpanTypeN* self, {x0,x1}, {y0,y1},...); // slice a span to make it a subspan of same rank
- // return a subspan of same rank. Like e.g. cspan_slice(&ms3, {offset, offset+count}, {0}, {0});
+ // return a subspan of same rank. Similar to e.g. cspan_slice(&ms3, {offset, offset+count}, {0}, {0});
SpanType cspan_subspan(const SpanType* self, intptr_t offset, intptr_t count);
SpanType2 cspan_subspan2(const SpanType2 self, intptr_t offset, intptr_t count);
SpanType3 cspan_subspan3(const SpanType3 self, intptr_t offset, intptr_t count);
-SpanType4 cspan_subspan4(const SpanType4 self, intptr_t offset, intptr_t count);
SpanTypeN_iter SpanType_begin(const SpanTypeN* self);
SpanTypeN_iter SpanType_end(const SpanTypeN* self);