diff options
| author | tylov <[email protected]> | 2023-07-11 22:16:09 +0200 |
|---|---|---|
| committer | tylov <[email protected]> | 2023-07-11 22:16:09 +0200 |
| commit | 0bcb0fcd981cb15329dfd4fb675097564164da18 (patch) | |
| tree | 2bb26e1c0940bdbab326b780bce0a89b47e79d16 /include/stc | |
| parent | afc968975a057f5b2653e3cfa51ef2eff83a8d5b (diff) | |
| download | STC-modified-0bcb0fcd981cb15329dfd4fb675097564164da18.tar.gz STC-modified-0bcb0fcd981cb15329dfd4fb675097564164da18.zip | |
Fixed an issue in template.h
Reverted to cspan_md() and cspan_md_left() for column-major.
Changed cspan_submdX(): add OutputSpanType as first parameter - aligns with cspan_slice() and adds type safety.
Diffstat (limited to 'include/stc')
| -rw-r--r-- | include/stc/cspan.h | 42 | ||||
| -rw-r--r-- | include/stc/priv/template.h | 6 |
2 files changed, 30 insertions, 18 deletions
diff --git a/include/stc/cspan.h b/include/stc/cspan.h index 027b5275..89986d6f 100644 --- a/include/stc/cspan.h +++ b/include/stc/cspan.h @@ -30,7 +30,7 @@ using_cspan(Intspan, int, 1); int demo1() { float raw[4*5]; - Span2f ms = cspan_md('C', raw, 4, 5); + Span2f ms = cspan_md(raw, 4, 5); for (int i=0; i<ms.shape[0]; i++) for (int j=0; j<ms.shape[1]; j++) @@ -147,26 +147,34 @@ using_cspan_tuple(7); using_cspan_tuple(8); // cspan_submd(): Reduce rank (N <= 4) Optimized, same as e.g. cspan_slice(Span2, &ms4, {x}, {y}, {c_ALL}, {c_ALL}); -#define cspan_submd2(self, x) \ - {.data=cspan_at(self, x, 0), .shape={(self)->shape[1]}, .stride={.d={(self)->stride.d[1]}}} -#define cspan_submd3(...) c_MACRO_OVERLOAD(cspan_submd3, __VA_ARGS__) -#define cspan_submd3_2(self, x) \ - {.data=cspan_at(self, x, 0, 0), .shape={(self)->shape[1], (self)->shape[2]}, \ +#define cspan_submd2(OutSpan, self, ...) _cspan_submdN(OutSpan, 2, self, __VA_ARGS__) +#define cspan_submd3(OutSpan, self, ...) _cspan_submdN(OutSpan, 3, self, __VA_ARGS__) +#define cspan_submd4(OutSpan, self, ...) _cspan_submdN(OutSpan, 4, self, __VA_ARGS__) + +#define _cspan_submdN(OutSpan, N, self, ...) \ + _cspan_submd##N(c_static_assert(cspan_rank((OutSpan*)0) == N - c_NUMARGS(__VA_ARGS__)), self, __VA_ARGS__) + +#define _cspan_submd2(ok, self, x) \ + {.data=cspan_at(self, x, 0) + ok, .shape={(self)->shape[1]}, .stride={.d={(self)->stride.d[1]}}} +#define _cspan_submd3(...) c_MACRO_OVERLOAD(_cspan_submd3, __VA_ARGS__) +#define _cspan_submd3_3(ok, self, x) \ + {.data=cspan_at(self, x, 0, 0) + ok, .shape={(self)->shape[1], (self)->shape[2]}, \ .stride={.d={(self)->stride.d[1], (self)->stride.d[2]}}} -#define cspan_submd3_3(self, x, y) \ - {.data=cspan_at(self, x, y, 0), .shape={(self)->shape[2]}, .stride={.d={(self)->stride.d[2]}}} -#define cspan_submd4(...) c_MACRO_OVERLOAD(cspan_submd4, __VA_ARGS__) -#define cspan_submd4_2(self, x) \ - {.data=cspan_at(self, x, 0, 0, 0), .shape={(self)->shape[1], (self)->shape[2], (self)->shape[3]}, \ +#define _cspan_submd3_4(ok, self, x, y) \ + {.data=cspan_at(self, x, y, 0) + ok, .shape={(self)->shape[2]}, .stride={.d={(self)->stride.d[2]}}} +#define _cspan_submd4(...) c_MACRO_OVERLOAD(_cspan_submd4, __VA_ARGS__) +#define _cspan_submd4_3(ok, self, x) \ + {.data=cspan_at(self, x, 0, 0, 0) + ok, .shape={(self)->shape[1], (self)->shape[2], (self)->shape[3]}, \ .stride={.d={(self)->stride.d[1], (self)->stride.d[2], (self)->stride.d[3]}}} -#define cspan_submd4_3(self, x, y) \ - {.data=cspan_at(self, x, y, 0, 0), .shape={(self)->shape[2], (self)->shape[3]}, \ +#define _cspan_submd4_4(ok, self, x, y) \ + {.data=cspan_at(self, x, y, 0, 0) + ok, .shape={(self)->shape[2], (self)->shape[3]}, \ .stride={.d={(self)->stride.d[2], (self)->stride.d[3]}}} -#define cspan_submd4_4(self, x, y, z) \ - {.data=cspan_at(self, x, y, z, 0), .shape={(self)->shape[3]}, .stride={.d={(self)->stride.d[3]}}} +#define _cspan_submd4_5(ok, self, x, y, z) \ + {.data=cspan_at(self, x, y, z, 0) + ok, .shape={(self)->shape[3]}, .stride={.d={(self)->stride.d[3]}}} - -#define cspan_md(order, array, ...) \ +#define cspan_md(array, ...) cspan_md_order('C', array, __VA_ARGS__) +#define cspan_md_left(array, ...) cspan_md_order('F', array, __VA_ARGS__) +#define cspan_md_order(order, array, ...) \ {.data=array, .shape={__VA_ARGS__}, \ .stride=*(c_PASTE(cspan_tuple, c_NUMARGS(__VA_ARGS__))*)_cspan_shape2stride(order, ((int32_t[]){__VA_ARGS__}), c_NUMARGS(__VA_ARGS__))} diff --git a/include/stc/priv/template.h b/include/stc/priv/template.h index 7138a87c..5551eeae 100644 --- a/include/stc/priv/template.h +++ b/include/stc/priv/template.h @@ -164,6 +164,8 @@ #error "No i_key or i_val defined" #elif defined i_keyraw ^ defined i_keyto #error "Both i_keyraw/valraw and i_keyto/valto must be defined, if any" +#elif defined i_keyfrom && !defined i_keyraw && !defined i_keyclone + #define i_keyclone i_keyfrom #elif defined i_keyfrom && !defined i_keyraw #error "i_keyfrom/valfrom defined without i_keyraw/valraw" #elif defined i_from || defined i_drop @@ -261,7 +263,9 @@ #error "i_val* must be defined for maps" #endif -#if !(defined i_valclone || defined i_no_clone) && (defined i_valdrop || defined i_valraw) +#if !defined i_valclone && defined i_valfrom && !defined i_valraw + #define i_valclone i_valfrom +#elif !(defined i_valclone || defined i_no_clone) && (defined i_valdrop || defined i_valraw) #error i_valclone should be defined when i_valdrop or i_valraw is defined #endif #ifndef i_valraw |
