diff options
| author | Tyge Løvset <[email protected]> | 2023-01-25 08:37:23 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-01-25 08:37:23 +0100 |
| commit | af4c2d6d2f3353364632701ef8208a9dcbe18623 (patch) | |
| tree | b79be8e7953e5a8219aa7db55ebc6358145dcbbc | |
| parent | 782ab14cac327134614188676a196fcfcb9d0ba1 (diff) | |
| download | STC-modified-af4c2d6d2f3353364632701ef8208a9dcbe18623.tar.gz STC-modified-af4c2d6d2f3353364632701ef8208a9dcbe18623.zip | |
Reverted cspan_subdim*() to cspan_at*(). Added cspan_flatten() constructor.
| -rw-r--r-- | docs/cspan_api.md | 11 | ||||
| -rw-r--r-- | include/stc/cspan.h | 19 | ||||
| -rw-r--r-- | misc/examples/multidim.c | 2 |
3 files changed, 18 insertions, 14 deletions
diff --git a/docs/cspan_api.md b/docs/cspan_api.md index d6caff4e..ce9236c3 100644 --- a/docs/cspan_api.md +++ b/docs/cspan_api.md @@ -25,6 +25,7 @@ SpanTypeN cspan_make(ValueType* data, size_t xdim, ...); // make 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_flatten(SpanTypeN* span); // create a 1D cspan from a multidim span void cspan_resize(SpanTypeN* self, size_t xdim, ...); // change the extent of each dimension size_t cspan_size(const SpanTypeN* self); // return number of elements @@ -35,9 +36,9 @@ ValueType* cspan_at(SpanTypeN* self, size_t x, ...); // at(): ValueType* cspan_front(SpanTypeN* self); ValueType* cspan_back(SpanTypeN* self); -SpanType cspan_subdim2(SpanType2* self, size_t x); // return a cspan from a 2D SpanType. -SpanTypeN cspan_subdim3(SpanType3* self, size_t x, ...); // subdimN(): N decides input SpanType, -SpanTypeN cspan_subdim4(SpanType4* self, size_t x, ...); // and num of args decides returned SpanTypeN. +SpanType cspan_at2(SpanType2* self, size_t x); // return a cspan from a 2D SpanType. +SpanTypeN cspan_at3(SpanType3* self, size_t x, ...); // atN(): N decides input SpanType, +SpanTypeN cspan_at4(SpanType4* self, size_t x, ...); // and num of args decides returned SpanTypeN. // return a subspan of same rank: SpanType cspan_subspan(const SpanType* self, size_t offset, size_t count); @@ -79,12 +80,12 @@ int main() *cspan_at(&span3, 4, 3, 2) = 3.14159f; printf("index: %d", (int)cspan_index(&span3, 4, 3, 2)); - Span span1 = cspan_subdim3(&span3, 4, 3); + Span span1 = cspan_at3(&span3, 4, 3); printf("\niterate span1: "); c_FOREACH (i, Span, span1) printf("%g ", *i.ref); - Span2 span2 = cspan_subdim3(&span3, 4); + Span2 span2 = cspan_at3(&span3, 4); printf("\niterate span2: "); c_FOREACH (i, Span2, span2) printf("%g ", *i.ref); diff --git a/include/stc/cspan.h b/include/stc/cspan.h index 5ba408a8..2b600a2a 100644 --- a/include/stc/cspan.h +++ b/include/stc/cspan.h @@ -94,6 +94,9 @@ int demo2() { #define cspan_init(SpanType, ...) \ {.data=(SpanType##_value[])__VA_ARGS__, .dim={sizeof((SpanType##_value[])__VA_ARGS__)/sizeof(SpanType##_value)}} +#define cspan_flatten(span) \ + {.data=(span)->data, .dim={(uint32_t)cspan_size(span)}} + /* create a cspan from a cvec, cstack, cdeq, cqueue, or cpque (heap) */ #define cspan_from(container) \ {.data=(container)->data, .dim={(uint32_t)(container)->_len}} @@ -124,19 +127,19 @@ int demo2() { #define cspan_subspan4(self, offset, count) \ {.data=cspan_at(self, offset, 0, 0, 0), .dim={count, (self)->dim[1], (self)->dim[2], (self)->dim[3]}} -#define cspan_subdim4(...) c_MACRO_OVERLOAD(cspan_subdim4, __VA_ARGS__) -#define cspan_subdim3(...) c_MACRO_OVERLOAD(cspan_subdim3, __VA_ARGS__) -#define cspan_subdim2(self, x) \ +#define cspan_at4(...) c_MACRO_OVERLOAD(cspan_at4, __VA_ARGS__) +#define cspan_at3(...) c_MACRO_OVERLOAD(cspan_at3, __VA_ARGS__) +#define cspan_at2(self, x) \ {.data=cspan_at(self, x, 0), .dim={(self)->dim[1]}} -#define cspan_subdim3_2(self, x) \ +#define cspan_at3_2(self, x) \ {.data=cspan_at(self, x, 0, 0), .dim={(self)->dim[1], (self)->dim[2]}} -#define cspan_subdim3_3(self, x, y) \ +#define cspan_at3_3(self, x, y) \ {.data=cspan_at(self, x, y, 0), .dim={(self)->dim[2]}} -#define cspan_subdim4_2(self, x) \ +#define cspan_at4_2(self, x) \ {.data=cspan_at(self, x, 0, 0, 0), .dim={(self)->dim[1], (self)->dim[2], (self)->dim[3]}} -#define cspan_subdim4_3(self, x, y) \ +#define cspan_at4_3(self, x, y) \ {.data=cspan_at(self, x, y, 0, 0), .dim={(self)->dim[2], (self)->dim[3]}} -#define cspan_subdim4_4(self, x, y, z) \ +#define cspan_at4_4(self, x, y, z) \ {.data=cspan_at(self, x, y, z, 0), .dim={(self)->dim[3]}} STC_INLINE size_t _cspan_i1(const uint32_t dim[1], uint32_t x) diff --git a/misc/examples/multidim.c b/misc/examples/multidim.c index 69f818cc..3eef1497 100644 --- a/misc/examples/multidim.c +++ b/misc/examples/multidim.c @@ -31,7 +31,7 @@ int main() puts(""); // or iterate a subspan... - ispan2 sub = cspan_subdim3(&ms3, 1); + ispan2 sub = cspan_at3(&ms3, 1); printf("sub: "); c_FOREACH (i, ispan2, sub) printf(" %d", *i.ref); |
