Skip to content

Commit e5374fa

Browse files
ShadyBoukharyumar456
authored andcommitted
Wrapped af_index_t
1 parent cb7e55a commit e5374fa

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

com/arrayfire/Index.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
}

src/index.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "jni_helper.h"
2+
3+
BEGIN_EXTERN_C
4+
5+
#define INDEX_FUNC(FUNC) AF_MANGLE(Index, FUNC)
6+
7+
8+
JNIEXPORT jlong JNICALL INDEX_FUNC(afLookup)(JNIEnv *env, jclass clazz, jlong in,
9+
jlong index, int dim) {
10+
af_array ret = 0;
11+
AF_CHECK(af_lookup(&ret, ARRAY(in), ARRAY(index), dim));
12+
return JLONG(ret);
13+
}
14+
15+
JNIEXPORT void JNICALL INDEX_FUNC(afCopy)(JNIEnv *env, jclass clazz,
16+
jlong dst ,jlong src,
17+
jobject idx0,
18+
jobject idx1, jobject idx2,
19+
jobject idx3, int dim) {
20+
af_index_t indices[] {java::jIndexToCIndex(env, idx0),
21+
java::jIndexToCIndex(env, idx1),
22+
java::jIndexToCIndex(env, idx2),
23+
java::jIndexToCIndex(env, idx3)};
24+
25+
af_array lhs = ARRAY(dst);
26+
AF_CHECK_VOID(af_assign_gen(&lhs, lhs, 4, indices, ARRAY(src)));
27+
}
28+
29+
END_EXTERN_C

0 commit comments

Comments
 (0)