-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathData.java
More file actions
86 lines (62 loc) · 2.79 KB
/
Data.java
File metadata and controls
86 lines (62 loc) · 2.79 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
76
77
78
79
80
81
82
83
84
85
86
package com.arrayfire;
class Data {
private native static long createRanduArray(int[] dims, int type);
private native static long createRandnArray(int[] dims, int type);
private native static long createConstantsArray(double val, int[] dims, int type);
private native static float[] getFloatFromArray(long ref);
private native static double[] getDoubleFromArray(long ref);
private native static int[] getIntFromArray(long ref);
private native static boolean[] getBooleanFromArray(long ref);
private native static FloatComplex[] getFloatComplexFromArray(long ref);
private native static DoubleComplex[] getDoubleComplexFromArray(long ref);
private native static long createIdentityArray(int[] dims, int type);
private native static long afRange(int[] dims, int seqDim, int type);
public static float[] getFloatArray(Array A) throws Exception {
A.assertType(ArrayFire.Type.Float);
return getFloatFromArray(A.ref);
}
public static double[] getDoubleArray(Array A) throws Exception {
A.assertType(ArrayFire.Type.Double);
return getDoubleFromArray(A.ref);
}
public static FloatComplex[] getFloatComplexArray(Array A) throws Exception {
A.assertType(ArrayFire.Type.FloatComplex);
return getFloatComplexFromArray(A.ref);
}
public static DoubleComplex[] getDoubleComplexArray(Array A) throws Exception {
A.assertType(ArrayFire.Type.DoubleComplex);
return getDoubleComplexFromArray(A.ref);
}
public static int[] getIntArray(Array A) throws Exception {
A.assertType(ArrayFire.Type.Int);
return getIntFromArray(A.ref);
}
public static boolean[] getBooleanArray(Array A) throws Exception {
A.assertType(ArrayFire.Type.Boolean);
return getBooleanFromArray(A.ref);
}
// Binary operations
public static void randu(Array res, int[] dims, ArrayFire.Type type) throws Exception {
int[] adims = Array.dim4(dims);
res.set(createRanduArray(adims, type.getType()));
}
public static void randn(Array res, int[] dims, ArrayFire.Type type) throws Exception {
int[] adims = Array.dim4(dims);
res.set(createRandnArray(adims, type.getType()));
}
public static void constant(Array res, double val, int[] dims, ArrayFire.Type type) throws Exception {
int[] adims = Array.dim4(dims);
res.set(createConstantsArray(val, adims, type.getType()));
}
public static void identity(Array res, int[] dims, ArrayFire.Type type) throws Exception {
int[] adims = Array.dim4(dims);
res.set(createIdentityArray(adims, type.getType()));
}
public static void identity(Array res, int[] dims) throws Exception {
identity(res, dims, ArrayFire.Type.Float);
}
public static Array range(int[] dims, int seqDim, ArrayFire.Type type) {
int[] adims = Array.dim4(dims);
return new Array(afRange(adims, seqDim, seqDim));
}
}