Skip to content

Commit 32be74f

Browse files
committed
Adding fft support for Array.java
1 parent 08caff9 commit 32be74f

4 files changed

Lines changed: 95 additions & 18 deletions

File tree

com/arrayfire/Array.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ public class Array implements AutoCloseable {
3939
private native static FloatComplex [] getFloatComplexFromArray(long ref);
4040
private native static DoubleComplex [] getDoubleComplexFromArray(long ref);
4141

42+
private native static long fft (long a);
43+
private native static long fft2 (long a);
44+
private native static long fft3 (long a);
45+
46+
private native static long ifft (long a);
47+
private native static long ifft2(long a);
48+
private native static long ifft3(long a);
4249

4350
// Binary operations
4451
private native static long add(long a, long b);
@@ -476,6 +483,42 @@ public static Array sqrt(Array a) throws Exception {
476483
public static double maxAll(Array a) throws Exception { return maxAll(a.ref); }
477484
public static double minAll(Array a) throws Exception { return minAll(a.ref); }
478485

486+
public static Array fft(Array a) throws Exception {
487+
Array ret_val = new Array();
488+
ret_val.ref = fft(a.ref);
489+
return ret_val;
490+
}
491+
492+
public static Array fft2(Array a) throws Exception {
493+
Array ret_val = new Array();
494+
ret_val.ref = fft2(a.ref);
495+
return ret_val;
496+
}
497+
498+
public static Array fft3(Array a) throws Exception {
499+
Array ret_val = new Array();
500+
ret_val.ref = fft3(a.ref);
501+
return ret_val;
502+
}
503+
504+
public static Array ifft(Array a) throws Exception {
505+
Array ret_val = new Array();
506+
ret_val.ref = ifft(a.ref);
507+
return ret_val;
508+
}
509+
510+
public static Array ifft2(Array a) throws Exception {
511+
Array ret_val = new Array();
512+
ret_val.ref = ifft2(a.ref);
513+
return ret_val;
514+
}
515+
516+
public static Array ifft3(Array a) throws Exception {
517+
Array ret_val = new Array();
518+
ret_val.ref = ifft3(a.ref);
519+
return ret_val;
520+
}
521+
479522
public static Array sum(Array a, int dim) throws Exception {
480523
Array ret_val = new Array();
481524
ret_val.ref = sum(a.ref, dim);

com/arrayfire/Image.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ public class Image extends Array {
1414
private native static long resize1 (long a, float scale, char method);
1515
private native static long resize2 (long a, float scalex, float scaley, char method);
1616
private native static long resize3 (long a, int height, int width, char method);
17-
//private native static long fft (long a, long b);
18-
//private native static long fft2 (long a, long b);
19-
//private native static long fft3 (long a, long b);
2017

2118
public Image() throws Exception { super(); }
2219

src/java_wrapper.cpp

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -483,21 +483,48 @@ ARRAY_RET_OP_DEF(sum)
483483
ARRAY_RET_OP_DEF(max)
484484
ARRAY_RET_OP_DEF(min)
485485

486-
#define SCALAR_OP1_DEF(func,operation) \
487-
JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_##func(JNIEnv *env, jclass clazz, jlong a, jfloat b) \
488-
{ \
489-
jlong ret; \
490-
try { \
491-
af::array *A = (af::array*)(a); \
492-
af::array *res = new af::array(); \
493-
(*res) = (*A) operation (b); \
494-
ret = (jlong)(res); \
495-
} catch(af::exception& e) { \
496-
ret = 0; \
497-
} catch(std::exception& e) { \
498-
ret = 0; \
499-
} \
500-
return ret; \
486+
487+
#define FFT_DEF(func) \
488+
JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_##func \
489+
(JNIEnv *env, jclass clazz, jlong a) \
490+
{ \
491+
jlong ret = 0; \
492+
try { \
493+
af::array *A = (af::array*)(a); \
494+
af::array *res = new af::array(); \
495+
*res = af::func((*A)); \
496+
ret = (jlong)res; \
497+
} catch(af::exception& e) { \
498+
return 0; \
499+
} catch(std::exception& e) { \
500+
return 0; \
501+
} \
502+
return ret; \
503+
}
504+
505+
FFT_DEF(fft)
506+
FFT_DEF(fft2)
507+
FFT_DEF(fft3)
508+
FFT_DEF(ifft)
509+
FFT_DEF(ifft2)
510+
FFT_DEF(ifft3)
511+
512+
#define SCALAR_OP1_DEF(func,operation) \
513+
JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_##func( \
514+
JNIEnv *env, jclass clazz, jlong a, jfloat b) \
515+
{ \
516+
jlong ret; \
517+
try { \
518+
af::array *A = (af::array*)(a); \
519+
af::array *res = new af::array(); \
520+
(*res) = (*A) operation (b); \
521+
ret = (jlong)(res); \
522+
} catch(af::exception& e) { \
523+
ret = 0; \
524+
} catch(std::exception& e) { \
525+
ret = 0; \
526+
} \
527+
return ret; \
501528
}
502529

503530
SCALAR_OP1_DEF(addf,+)

src/java_wrapper.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ ARRAY_RET_OP(sum)
8888
ARRAY_RET_OP(max)
8989
ARRAY_RET_OP(min)
9090

91+
#define FFT(func) \
92+
JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_##func(JNIEnv *env, jclass clazz, jlong a);
93+
94+
FFT(fft)
95+
FFT(fft2)
96+
FFT(fft3)
97+
FFT(ifft)
98+
FFT(ifft2)
99+
FFT(ifft3)
100+
91101
#define SCALAR_OP1(func) \
92102
JNIEXPORT jlong JNICALL Java_com_arrayfire_Array_##func(JNIEnv *env, jclass clazz, jlong a, jfloat b);
93103

0 commit comments

Comments
 (0)