summaryrefslogtreecommitdiff
path: root/packages/base/src/Internal/C
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2016-12-20 19:18:49 +0100
committerGitHub <noreply@github.com>2016-12-20 19:18:49 +0100
commitd2d0066d2ff3d8e66ce902ee1b9d1317f1710a2c (patch)
tree8392b64b0d5b2da92b523cc8657921ce8ec1fee3 /packages/base/src/Internal/C
parent66f0174cec6b9b3a329321a435d0c7841f396077 (diff)
parente7843cb083316bc5b5a760f7c987671505c2e9d8 (diff)
Merge pull request #216 from kjslag/reorderVector
reorderVector for tensor libraries
Diffstat (limited to 'packages/base/src/Internal/C')
-rw-r--r--packages/base/src/Internal/C/vector-aux.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/packages/base/src/Internal/C/vector-aux.c b/packages/base/src/Internal/C/vector-aux.c
index 1cef27d..dcd6c0b 100644
--- a/packages/base/src/Internal/C/vector-aux.c
+++ b/packages/base/src/Internal/C/vector-aux.c
@@ -1533,3 +1533,54 @@ int chooseQ(KIVEC(cond),KQVEC(lt),KQVEC(eq),KQVEC(gt),QVEC(r)) {
1533 CHOOSE_IMP 1533 CHOOSE_IMP
1534} 1534}
1535 1535
1536//////////////////// reorder /////////////////////////
1537
1538#define REORDER_IMP \
1539 REQUIRES(kn == stridesn && stridesn == dimsn ,BAD_SIZE); \
1540 int i,j,l; \
1541 for (i=1,j=0,l=0;l<kn;++l) { \
1542 kp[l] = 0; \
1543 i *= dimsp[l]; \
1544 j += (dimsp[l]-1) * stridesp[l]; \
1545 } \
1546 REQUIRES(i <= vn && j < rn ,BAD_SIZE); \
1547 for (i=0,j=0;;i++) { \
1548 rp[i] = vp[j]; \
1549 for(l=kn-1;;l--) { \
1550 ++kp[l]; \
1551 if (kp[l] < dimsp[l]) { \
1552 j += stridesp[l]; \
1553 break; \
1554 } else { \
1555 if (l == 0) { \
1556 return 0; \
1557 } \
1558 kp[l] = 0; \
1559 j -= (dimsp[l]-1) * stridesp[l]; \
1560 } \
1561 } \
1562 }
1563
1564int reorderF(IVEC(k), KIVEC(strides),KIVEC(dims),KFVEC(v),FVEC(r)) {
1565 REORDER_IMP
1566}
1567
1568int reorderD(IVEC(k), KIVEC(strides),KIVEC(dims),KDVEC(v),DVEC(r)) {
1569 REORDER_IMP
1570}
1571
1572int reorderI(IVEC(k), KIVEC(strides),KIVEC(dims),KIVEC(v),IVEC(r)) {
1573 REORDER_IMP
1574}
1575
1576int reorderL(IVEC(k), KIVEC(strides),KIVEC(dims),KLVEC(v),LVEC(r)) {
1577 REORDER_IMP
1578}
1579
1580int reorderC(IVEC(k), KIVEC(strides),KIVEC(dims),KCVEC(v),CVEC(r)) {
1581 REORDER_IMP
1582}
1583
1584int reorderQ(IVEC(k), KIVEC(strides),KIVEC(dims),KQVEC(v),QVEC(r)) {
1585 REORDER_IMP
1586}