summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/stc/cspan.h46
1 files changed, 23 insertions, 23 deletions
diff --git a/include/stc/cspan.h b/include/stc/cspan.h
index 86aefdc0..e058c0e8 100644
--- a/include/stc/cspan.h
+++ b/include/stc/cspan.h
@@ -81,7 +81,7 @@ int demo2() {
\
typedef struct { Self##_value *ref; int32_t pos[RANK]; const Self *_s; } Self##_iter; \
\
- STC_INLINE Self Self##_slice_(Self##_value* d, const int32_t shape[], const int32_t stri[], \
+ STC_INLINE Self Self##_slice_(Self##_value* d, const int32_t shape[], const intptr_t stri[], \
const int rank, const int32_t a[][2]) { \
Self s; int outrank; \
s.data = d + _cspan_slice(s.shape, s.stride.d, &outrank, shape, stri, rank, a); \
@@ -106,7 +106,7 @@ int demo2() {
#define using_cspan2(Self, T) using_cspan_2(Self, T); using_cspan_3(Self##2, T, 2)
#define using_cspan3(Self, T) using_cspan2(Self, T); using_cspan_3(Self##3, T, 3)
#define using_cspan4(Self, T) using_cspan3(Self, T); using_cspan_3(Self##4, T, 4)
-#define using_cspan_tuple(N) typedef struct { int32_t d[N]; } cspan_tuple##N
+#define using_cspan_tuple(N) typedef struct { intptr_t d[N]; } cspan_tuple##N
using_cspan_tuple(1); using_cspan_tuple(2);
using_cspan_tuple(3); using_cspan_tuple(4);
using_cspan_tuple(5); using_cspan_tuple(6);
@@ -139,7 +139,7 @@ typedef enum {c_ROWMAJOR, c_COLMAJOR} cspan_layout;
#define cspan_front(self) ((self)->data)
#define cspan_back(self) ((self)->data + cspan_size(self) - 1)
#define cspan_index(self, ...) \
- (_cspan_index(c_NUMARGS(__VA_ARGS__), (self)->shape, (self)->stride.d, (int32_t[]){__VA_ARGS__}) + \
+ (_cspan_index(c_NUMARGS(__VA_ARGS__), (self)->shape, (self)->stride.d, (const int32_t[]){__VA_ARGS__}) + \
c_static_assert(cspan_rank(self) == c_NUMARGS(__VA_ARGS__))) // general
// cspan_subspanX: (X <= 3) optimized. Similar to cspan_slice(Span3, &ms3, {off,off+count}, {c_ALL}, {c_ALL});
@@ -172,7 +172,7 @@ typedef enum {c_ROWMAJOR, c_COLMAJOR} cspan_layout;
#define cspan_md(array, ...) cspan_md_layout(c_ROWMAJOR, array, __VA_ARGS__)
#define cspan_md_layout(layout, array, ...) \
{.data=array, .shape={__VA_ARGS__}, \
- .stride=*(c_PASTE(cspan_tuple, c_NUMARGS(__VA_ARGS__))*)_cspan_shape2stride(layout, ((int32_t[]){__VA_ARGS__}), c_NUMARGS(__VA_ARGS__))}
+ .stride=*(c_PASTE(cspan_tuple,c_NUMARGS(__VA_ARGS__))*)_cspan_shape2stride(layout, ((intptr_t[]){__VA_ARGS__}), c_NUMARGS(__VA_ARGS__))}
#define cspan_transpose(self) \
_cspan_transpose((self)->shape, (self)->stride.d, cspan_rank(self))
@@ -191,25 +191,25 @@ STC_INLINE intptr_t _cspan_size(const int32_t shape[], int rank) {
return sz;
}
-STC_INLINE void _cspan_transpose(int32_t shape[], int32_t stride[], int rank) {
+STC_INLINE void _cspan_transpose(int32_t shape[], intptr_t stride[], int rank) {
for (int i = 0; i < --rank; ++i) {
c_swap(int32_t, shape + i, shape + rank);
- c_swap(int32_t, stride + i, stride + rank);
+ c_swap(intptr_t, stride + i, stride + rank);
}
}
-STC_INLINE intptr_t _cspan_index(int rank, const int32_t shape[], const int32_t stride[], const int32_t a[]) {
+STC_INLINE intptr_t _cspan_index(int rank, const int32_t shape[], const intptr_t stride[], const int32_t a[]) {
intptr_t off = 0;
while (rank--) {
c_assert(c_LTu(a[rank], shape[rank]));
- off += (intptr_t)stride[rank]*a[rank];
+ off += stride[rank]*a[rank];
}
return off;
}
#define _cspan_next1(pos, shape, stride, rank, done) (*done = ++pos[0]==shape[0], stride[0])
STC_API intptr_t
- _cspan_next2(int32_t pos[], const int32_t shape[], const int32_t stride[], int rank, int* done);
+ _cspan_next2(int32_t pos[], const int32_t shape[], const intptr_t stride[], int rank, int* done);
#define _cspan_next3 _cspan_next2
#define _cspan_next4 _cspan_next2
#define _cspan_next5 _cspan_next2
@@ -217,53 +217,53 @@ STC_API intptr_t
#define _cspan_next7 _cspan_next2
#define _cspan_next8 _cspan_next2
-STC_API intptr_t _cspan_slice(int32_t oshape[], int32_t ostride[], int* orank,
- const int32_t shape[], const int32_t stride[],
+STC_API intptr_t _cspan_slice(int32_t oshape[], intptr_t ostride[], int* orank,
+ const int32_t shape[], const intptr_t stride[],
int rank, const int32_t a[][2]);
-STC_API int32_t* _cspan_shape2stride(cspan_layout layout, int32_t shape[], int rank);
+STC_API intptr_t* _cspan_shape2stride(cspan_layout layout, intptr_t shape[], int rank);
#endif // STC_CSPAN_H_INCLUDED
/* --------------------- IMPLEMENTATION --------------------- */
#if defined(i_implement) || defined(i_static)
-STC_DEF intptr_t _cspan_next2(int32_t pos[], const int32_t shape[], const int32_t stride[], int r, int* done) {
+STC_DEF intptr_t _cspan_next2(int32_t pos[], const int32_t shape[], const intptr_t stride[], int r, int* done) {
intptr_t off = stride[--r];
++pos[r];
for (; r && pos[r] == shape[r]; --r) {
pos[r] = 0; ++pos[r - 1];
- off += stride[r - 1] - (intptr_t)stride[r]*shape[r];
+ off += stride[r - 1] - stride[r]*shape[r];
}
*done = pos[r] == shape[r];
return off;
}
-STC_DEF int32_t* _cspan_shape2stride(cspan_layout layout, int32_t shape[], int rank) {
+STC_DEF intptr_t* _cspan_shape2stride(cspan_layout layout, intptr_t stride[], int rank) {
int i, inc;
if (layout == c_COLMAJOR) i = 0, inc = 1;
else i = rank - 1, inc = -1;
- int32_t k = 1, s1 = shape[i], s2;
+ intptr_t k = 1, s1 = stride[i], s2;
- shape[i] = 1;
+ stride[i] = 1;
while (--rank) {
i += inc;
- s2 = shape[i];
- shape[i] = (k *= s1);
+ s2 = stride[i];
+ stride[i] = (k *= s1);
s1 = s2;
}
- return shape;
+ return stride;
}
-STC_DEF intptr_t _cspan_slice(int32_t oshape[], int32_t ostride[], int* orank,
- const int32_t shape[], const int32_t stride[],
+STC_DEF intptr_t _cspan_slice(int32_t oshape[], intptr_t ostride[], int* orank,
+ const int32_t shape[], const intptr_t stride[],
int rank, const int32_t a[][2]) {
intptr_t off = 0;
int i = 0, oi = 0;
int32_t end;
for (; i < rank; ++i) {
- off += (intptr_t)stride[i]*a[i][0];
+ off += stride[i]*a[i][0];
switch (a[i][1]) {
case 0: c_assert(c_LTu(a[i][0], shape[i])); continue;
case -1: end = shape[i]; break;