diff options
| author | Tyge Løvset <[email protected]> | 2023-01-16 06:41:40 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-01-16 06:41:40 +0100 |
| commit | 7e397856b9964d7e29d4ed5e8d7034bb5db28dfa (patch) | |
| tree | 20483ca71386619f8eac8c88648c175823015f9c | |
| parent | b94be0e98bd2d802784c36e0011013edb580f6f8 (diff) | |
| download | STC-modified-7e397856b9964d7e29d4ed5e8d7034bb5db28dfa.tar.gz STC-modified-7e397856b9964d7e29d4ed5e8d7034bb5db28dfa.zip | |
Final cspan API change: cspan_reshape() => cspan_resize().
| -rw-r--r-- | docs/cspan_api.md | 16 | ||||
| -rw-r--r-- | include/stc/cspan.h | 44 |
2 files changed, 30 insertions, 30 deletions
diff --git a/docs/cspan_api.md b/docs/cspan_api.md index 2cb4dc73..d0805ae7 100644 --- a/docs/cspan_api.md +++ b/docs/cspan_api.md @@ -22,9 +22,9 @@ using_cspan4(S, ValueType); // d SpanType 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_literal(SpanType, {val1, val2, ...}); // create a 1D cspan compound literal +SpanType& cspan_literal(T SpanType, {val1, val2, ...}); // create a 1D cspan compound literal -void cspan_reshape(const SpanType* self, size_t xdim, ...); // change the extent of each dimension +void cspan_resize(const SpanType* self, size_t xdim, ...); // change the extent of each dimension size_t cspan_size(const SpanType* self); // return number of elements unsigned cspan_rank(const SpanType* self); // return number of dimensions @@ -38,15 +38,15 @@ SpanType4 cspan_slice4(SpanType4* self, size_t x0, size_t width); // g // Ex usage 1: MySpan2 ms2 = cspan_3to2(&ms3, ms3.dim[0]-1); // Ex usage 2: ms2 = (MySpan2)cspan_3to2(&ms3, 0); -SpanType3 cspan_4to3(SpanType4* self, size_t x); // return a 3D subspan -SpanType2 cspan_4to2(SpanType4* self, size_t x, size_t y); // return a 2D subspan -SpanType1 cspan_4to1(SpanType4* self, size_t x, size_t y, size_t z); // return a 1D subspan -SpanType2 cspan_3to2(SpanType3* self, size_t x); // return a 2D subspan -SpanType1 cspan_3to1(SpanType3* self, size_t x, size_t y); // return a 1D subspan SpanType1 cspan_2to1(SpanType2* self, size_t x); // return a 1D subspan +SpanType1 cspan_3to1(SpanType3* self, size_t x, size_t y); // return a 1D subspan +SpanType2 cspan_3to2(SpanType3* self, size_t x); // return a 2D subspan +SpanType1 cspan_4to1(SpanType4* self, size_t x, size_t y, size_t z); // return a 1D subspan +SpanType2 cspan_4to2(SpanType4* self, size_t x, size_t y); // return a 2D subspan +SpanType3 cspan_4to3(SpanType4* self, size_t x); // return a 3D subspan SpanType_iter SpanType_begin(const SpanType* self); -SpanTyåe_iter SpanType_end(const SpanType* self); +SpanType_iter SpanType_end(const SpanType* self); void SpanType_next(SpanType_iter* it); ``` ## Types diff --git a/include/stc/cspan.h b/include/stc/cspan.h index 1a432a4d..9b6893be 100644 --- a/include/stc/cspan.h +++ b/include/stc/cspan.h @@ -81,11 +81,11 @@ int demo2() { #define using_cspan3(Self, T) using_cspan2(Self, T); using_cspan(Self##3, T, 3) #define using_cspan4(Self, T) using_cspan3(Self, T); using_cspan(Self##4, T, 4) -#define cspan_check_rank(self, rank) c_STATIC_ASSERT(cspan_rank(self) == rank) +#define cspan_rank_ok(self, rank) c_STATIC_ASSERT(cspan_rank(self) == rank) #define cspan_literal(S, ...) \ - ((S){.data = (S##_value[])__VA_ARGS__, \ - .dim = {sizeof((S##_value[])__VA_ARGS__)/sizeof(S##_value)}}) + (c_INIT(S){.data = (S##_value[])__VA_ARGS__, \ + .dim = {sizeof((S##_value[])__VA_ARGS__)/sizeof(S##_value)}}) #define cspan_make(data, ...) \ {data, {__VA_ARGS__}} @@ -101,35 +101,35 @@ int demo2() { #define cspan_rank(self) c_ARRAYLEN((self)->dim) #define cspan_index(self, ...) \ c_PASTE(_cspan_i, c_NUMARGS(__VA_ARGS__))((self)->dim, __VA_ARGS__) + \ - cspan_check_rank(self, c_NUMARGS(__VA_ARGS__)) + cspan_rank_ok(self, c_NUMARGS(__VA_ARGS__)) -#define cspan_reshape(self, ...) \ +#define cspan_resize(self, ...) \ (void)memcpy((self)->dim, (uint32_t[]){__VA_ARGS__}, \ - sizeof((self)->dim) + cspan_check_rank(self, c_NUMARGS(__VA_ARGS__))) + sizeof((self)->dim) + cspan_rank_ok(self, c_NUMARGS(__VA_ARGS__))) #define cspan_at(self, ...) ((self)->data + cspan_index(self, __VA_ARGS__)) -#define cspan_slice4(self, x0, width) \ - {cspan_at(self, x0, 0, 0, 0), {width, (self)->dim[1], (self)->dim[2], (self)->dim[3]}} -#define cspan_slice3(self, x0, width) \ - {cspan_at(self, x0, 0, 0), {width, (self)->dim[1], (self)->dim[2]}} -#define cspan_slice2(self, x0, width) \ - {cspan_at(self, x0, 0), {width, (self)->dim[1]}} #define cspan_slice1(self, x0, width) \ {cspan_at(self, x0), {width}} +#define cspan_slice2(self, x0, width) \ + {cspan_at(self, x0, 0), {width, (self)->dim[1]}} +#define cspan_slice3(self, x0, width) \ + {cspan_at(self, x0, 0, 0), {width, (self)->dim[1], (self)->dim[2]}} +#define cspan_slice4(self, x0, width) \ + {cspan_at(self, x0, 0, 0, 0), {width, (self)->dim[1], (self)->dim[2], (self)->dim[3]}} -#define cspan_4to3(self, x) \ - {cspan_at(self, x, 0, 0, 0), {(self)->dim[1], (self)->dim[2], (self)->dim[3]}} -#define cspan_4to2(self, x, y) \ - {cspan_at(self, x, y, 0, 0), {(self)->dim[2], (self)->dim[3]}} -#define cspan_4to1(self, x, y, z) \ - {cspan_at(self, x, y, z, 0), {(self)->dim[3]}} -#define cspan_3to2(self, x) \ - {cspan_at(self, x, 0, 0), {(self)->dim[1], (self)->dim[2]}} -#define cspan_3to1(self, x, y) \ - {cspan_at(self, x, y, 0), {(self)->dim[2]}} #define cspan_2to1(self, x) \ {cspan_at(self, x, 0), {(self)->dim[1]}} +#define cspan_3to1(self, x, y) \ + {cspan_at(self, x, y, 0), {(self)->dim[2]}} +#define cspan_3to2(self, x) \ + {cspan_at(self, x, 0, 0), {(self)->dim[1], (self)->dim[2]}} +#define cspan_4to1(self, x, y, z) \ + {cspan_at(self, x, y, z, 0), {(self)->dim[3]}} +#define cspan_4to2(self, x, y) \ + {cspan_at(self, x, y, 0, 0), {(self)->dim[2], (self)->dim[3]}} +#define cspan_4to3(self, x) \ + {cspan_at(self, x, 0, 0, 0), {(self)->dim[1], (self)->dim[2], (self)->dim[3]}} STC_INLINE size_t _cspan_i1(const uint32_t dim[1], uint32_t x) { c_ASSERT(x < dim[0]); return x; } |
