-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathIndex.java
More file actions
75 lines (60 loc) · 1.87 KB
/
Index.java
File metadata and controls
75 lines (60 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.arrayfire;
import java.util.Arrays;
public class Index {
private Array arr;
private Seq seq;
private boolean isSeq;
private boolean isBatch;
private static native long afLookup(long in, long index, int dim);
private static native void afCopy(long dst, long src, int ndims, Object idx0, Object idx1,
Object idx2, Object idx3);
public Index() {
seq = ArrayFire.SPAN;
isSeq = true;
isBatch = false;
}
public Index(int idx) throws Exception {
seq = new Seq(idx, idx, 1);
isSeq = true;
isBatch = false;
}
public Index(final Seq seq) throws Exception {
this.seq = new Seq(seq);
isSeq = true;
isBatch = this.seq.gfor;
}
public Index(final Array idx) throws Exception {
arr = idx.isBool() ? Algorithm.where(idx) : new Array(idx.ref);
isSeq = false;
isBatch = false;
}
public Index(final Index other) {
arr = new Array(other.arr.ref);
seq = new Seq(other.seq);
isSeq = other.isSeq;
isBatch = other.isBatch;
}
public long getArrayRef() {
return arr.ref;
}
public Object getSeq() {
return seq;
}
public boolean isSeq() {
return isSeq;
}
public boolean isBatch() {
return isBatch;
}
public boolean isSpan() {
return isSeq && seq == ArrayFire.SPAN;
}
static Array lookup(final Array in, final Array idx, int dim) throws Exception {
return new Array(afLookup(in.ref, idx.ref, dim));
}
static void copy(Array dst, final Array src, Index idx0, Index idx1,
Index idx2, Index idx3) throws Exception{
int ndims = Arrays.stream(dst.dims()).filter(x -> x > 1).toArray().length;
afCopy(dst.ref, src.ref, ndims, idx0, idx1, idx2, idx3);
}
}