|
| 1 | +package com.arrayfire; |
| 2 | + |
| 3 | +public class Index { |
| 4 | + private Array arr; |
| 5 | + private Seq seq; |
| 6 | + private boolean isSeq; |
| 7 | + private boolean isBatch; |
| 8 | + |
| 9 | + private static native long afLookup(long in, long index, int dim); |
| 10 | + private static native void afCopy(long dst, long src, Object idx0, Object idx1, |
| 11 | + Object idx2, Object idx3); |
| 12 | + |
| 13 | + public Index() { |
| 14 | + seq = ArrayFire.SPAN; |
| 15 | + isSeq = true; |
| 16 | + isBatch = false; |
| 17 | + } |
| 18 | + |
| 19 | + public Index(int idx) throws Exception { |
| 20 | + seq = new Seq(idx, idx, 1); |
| 21 | + isSeq = true; |
| 22 | + isBatch = false; |
| 23 | + } |
| 24 | + |
| 25 | + public Index(final Seq seq) throws Exception { |
| 26 | + this.seq = new Seq(seq); |
| 27 | + isSeq = true; |
| 28 | + isBatch = this.seq.gfor; |
| 29 | + } |
| 30 | + |
| 31 | + public Index(final Array idx) throws Exception { |
| 32 | + arr = idx.isBool() ? Algorithm.where(idx) : new Array(idx.ref); |
| 33 | + isSeq = false; |
| 34 | + isBatch = false; |
| 35 | + } |
| 36 | + |
| 37 | + public Index(final Index other) { |
| 38 | + arr = new Array(other.arr.ref); |
| 39 | + seq = new Seq(other.seq); |
| 40 | + isSeq = other.isSeq; |
| 41 | + isBatch = other.isBatch; |
| 42 | + } |
| 43 | + |
| 44 | + public long getArrayRef() { |
| 45 | + return arr.ref; |
| 46 | + } |
| 47 | + |
| 48 | + public Seq getSeq() { |
| 49 | + return seq; |
| 50 | + } |
| 51 | + |
| 52 | + public boolean isSeq() { |
| 53 | + return isSeq; |
| 54 | + } |
| 55 | + |
| 56 | + public boolean isBatch() { |
| 57 | + return isBatch; |
| 58 | + } |
| 59 | + |
| 60 | + public boolean isSpan() { |
| 61 | + return isSeq && seq == ArrayFire.SPAN; |
| 62 | + } |
| 63 | + |
| 64 | + static Array lookup(final Array in, final Array idx, int dim) throws Exception { |
| 65 | + return new Array(afLookup(in.ref, idx.ref, dim)); |
| 66 | + } |
| 67 | + |
| 68 | + static void copy(Array dst, final Array src, Index idx0, Index idx1, |
| 69 | + Index idx2, Index idx3) throws Exception{ |
| 70 | + afCopy(dst.ref, src.ref, idx0, idx1, idx2, idx3); |
| 71 | + } |
| 72 | +} |
0 commit comments