Skip to content

Commit 54c491d

Browse files
ShadyBoukharyumar456
authored andcommitted
Fixed bugs in copy native function.
1 parent c9f305b commit 54c491d

4 files changed

Lines changed: 15 additions & 12 deletions

File tree

com/arrayfire/Array.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ protected Array(long other_ref) {
3636
ref = other_ref;
3737
}
3838

39-
public Array(int[] dims, int type) throws Exception {
39+
public Array(int[] dims, ArrayFire.Type type) throws Exception {
4040
int[] adims = Array.dim4(dims);
41-
set(createEmptyArray(adims, type));
41+
set(createEmptyArray(adims, type.getType()));
4242
}
4343

4444
public Array(int[] dims, float[] elems) throws IllegalArgumentException {

com/arrayfire/Index.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.arrayfire;
22

3+
import java.util.Arrays;
4+
35
public class Index {
46
private Array arr;
57
private Seq seq;
68
private boolean isSeq;
79
private boolean isBatch;
810

911
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,
12+
private static native void afCopy(long dst, long src, int ndims, Object idx0, Object idx1,
1113
Object idx2, Object idx3);
1214

1315
public Index() {
@@ -45,7 +47,7 @@ public long getArrayRef() {
4547
return arr.ref;
4648
}
4749

48-
public Seq getSeq() {
50+
public Object getSeq() {
4951
return seq;
5052
}
5153

@@ -67,6 +69,7 @@ static Array lookup(final Array in, final Array idx, int dim) throws Exception {
6769

6870
static void copy(Array dst, final Array src, Index idx0, Index idx1,
6971
Index idx2, Index idx3) throws Exception{
70-
afCopy(dst.ref, src.ref, idx0, idx1, idx2, idx3);
72+
int ndims = Arrays.stream(dst.dims()).filter(x -> x > 1).toArray().length;
73+
afCopy(dst.ref, src.ref, ndims, idx0, idx1, idx2, idx3);
7174
}
7275
}

src/index.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ JNIEXPORT jlong JNICALL INDEX_FUNC(afLookup)(JNIEnv *env, jclass clazz, jlong in
1414

1515
JNIEXPORT void JNICALL INDEX_FUNC(afCopy)(JNIEnv *env, jclass clazz,
1616
jlong dst ,jlong src,
17+
jint ndims,
1718
jobject idx0,
1819
jobject idx1, jobject idx2,
1920
jobject idx3, int dim) {
@@ -23,7 +24,7 @@ JNIEXPORT void JNICALL INDEX_FUNC(afCopy)(JNIEnv *env, jclass clazz,
2324
java::jIndexToCIndex(env, idx3)};
2425

2526
af_array lhs = ARRAY(dst);
26-
AF_CHECK_VOID(af_assign_gen(&lhs, lhs, 4, indices, ARRAY(src)));
27+
AF_CHECK_VOID(af_assign_gen(&lhs, lhs, ndims, indices, ARRAY(src)));
2728
}
2829

2930
END_EXTERN_C

src/java/java.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ enum class JavaType {
1212
Short,
1313
Void,
1414
Boolean,
15-
Seq
15+
Object
1616
};
1717

1818
static const char *mapJavaTypeToString(JavaType type) {
@@ -26,8 +26,8 @@ static const char *mapJavaTypeToString(JavaType type) {
2626
case JavaType::String: return "Ljava/lang/String;";
2727
case JavaType::Short: return "S";
2828
case JavaType::Void: return "V";
29-
case JavaType::Boolean: return "B";
30-
case JavaType::Seq: return "Lcom/arrayfire/Seq";
29+
case JavaType::Boolean: return "Z";
30+
case JavaType::Object: return "Ljava/lang/Object;";
3131
}
3232
}
3333

@@ -57,7 +57,7 @@ void throwArrayFireException(JNIEnv *env, const char *functionName,
5757

5858
jthrowable exception = static_cast<jthrowable>(
5959
env->NewObject(exceptionClass, constructor, code,
60-
env->NewStringUTF("Some custom message here.")));
60+
env->NewStringUTF("")));
6161

6262
// Find setLocation method and call it with
6363
// the function name, file and line parameters
@@ -100,7 +100,6 @@ jobject createJavaObject(JNIEnv *env, JavaObjects objectType, Args... args) {
100100
af_index_t jIndexToCIndex(JNIEnv *env, jobject obj) {
101101
af_index_t index;
102102
jclass cls = env->GetObjectClass(obj);
103-
assert(cls == env->FindClass("com/arrayfire/Index"));
104103

105104
std::string getIsSeqSig = generateFunctionSignature(JavaType::Boolean, {});
106105
jmethodID getIsSeqId = env->GetMethodID(cls, "isSeq", getIsSeqSig.c_str());
@@ -114,7 +113,7 @@ af_index_t jIndexToCIndex(JNIEnv *env, jobject obj) {
114113

115114
if (index.isSeq) {
116115
// get seq object
117-
std::string getSeqSig = generateFunctionSignature(JavaType::Seq, {});
116+
std::string getSeqSig = generateFunctionSignature(JavaType::Object, {});
118117
jmethodID getSeqId = env->GetMethodID(cls, "getSeq", getSeqSig.c_str());
119118
assert(getSeqId != NULL);
120119
jobject seq = env->CallObjectMethod(obj, getSeqId);

0 commit comments

Comments
 (0)