8000 Future proofing the JNI code · wcork/arrayfire-java@0879ed6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0879ed6

Browse files
committed
Future proofing the JNI code
Always send dimension array of length 4
1 parent b80eca3 commit 0879ed6

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

com/arrayfire/Array.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ public Array(int[] dims) throws Exception {
8383
} else if ( dims.length > 3 ) {
8484
throw new Exception("Upto 3 dimensions only supported for now.");
8585
}
86-
this.ref = createArray(dims);
86+
int[] adims;
87+
adims = new int[] {1, 1, 1, 1};
88+
for (int i = 0; i < dims.length; i++) adims[i] = dims[i];
89+
90+
this.ref = createArray(adims);
8791
}
8892

8993
public Array(int[] dims, float[] elems) throws Exception {
@@ -98,7 +102,12 @@ public Array(int[] dims, float[] elems) throws Exception {
98102
if( elems.length > total_size || elems.length < total_size ) {
99103
throw new Exception("Mismatching dims and array size");
100104
}
101-
this.ref = createArrayElems(dims,elems);
105+
106+
int[] adims;
107+
adims = new int[] {1, 1, 1, 1};
108+
for (int i = 0; i < dims.length; i++) adims[i] = dims[i];
109+
110+
this.ref = createArrayElems(adims, elems);
102111
}
103112

104113
public int[] dims() {

src/java_wrapper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createArray(JNIEnv *env, jclass
1919
jlong ret;
2020
try{
2121
jint* dimptr = env->GetIntArrayElements(dims,0);
22-
af::array *A = new af::array(dimptr[0],dimptr[1],dimptr[2]);
22+
af::array *A = new af::array(dimptr[0],dimptr[1],dimptr[2],dimptr[3]);
2323
*A = af::constant(0.0f,dimptr[0],dimptr[1],dimptr[2]);
2424
ret = (jlong)(A);
2525
env->ReleaseIntArrayElements(dims,dimptr,0);
@@ -37,7 +37,8 @@ JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_createArrayElems(JNIEnv *env, j
3737
try{
3838
jint* dimptr = env->GetIntArrayElements(dims,0);
3939
jfloat* inptr= env->GetFloatArrayElements(elems,0);
40-
af::array *A = new af::array(dimptr[0],dimptr[1],dimptr[2],inptr);
40+
af::array *A = new af::array(dimptr[0],dimptr[1],dimptr[2],dimptr[3],inptr);
41+
4142
ret = (jlong)(A);
4243
env->ReleaseIntArrayElements(dims,dimptr,0);
4344
env->ReleaseFloatArrayElements(elems,inptr,0);

0 commit comments

Comments
 (0)
0