├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── com ├── .gitignore └── arrayfire │ ├── AFLibLoader.java │ ├── Algorithm.java │ ├── Arith.java │ ├── Array.java │ ├── ArrayFire.java │ ├── ArrayFireException.java │ ├── Data.java │ ├── DoubleComplex.java │ ├── FloatComplex.java │ ├── Graphics.java │ ├── Image.java │ ├── Index.java │ ├── JNIException.java │ ├── Seq.java │ ├── Signal.java │ ├── Statistics.java │ ├── Util.java │ └── Window.java ├── examples ├── .gitignore ├── CMakeLists.txt ├── HelloWorld.java ├── Makefile ├── MonteCarloPi.java └── WindowEx.java ├── java-google-style.xml ├── src ├── .gitignore ├── CMakeLists.txt ├── algorithm.cpp ├── arith.cpp ├── array.cpp ├── data.cpp ├── graphics.cpp ├── image.cpp ├── index.cpp ├── java │ ├── java.cpp │ └── java.h ├── jni_helper.h ├── signal.cpp ├── statistics.cpp └── util.cpp └── todo.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *.jar 2 | *.sdf 3 | *.suo 4 | x64/* 5 | tmp 6 | build 7 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 2 | PROJECT(ArrayFire-Java) 3 | 4 | SET(AF_JAR ArrayFire) 5 | SET(AF_LIB af_java) 6 | 7 | OPTION(BUILD_EXAMPLES "Option for building examples" ON) 8 | # Set a default build type if none was specified 9 | IF(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 10 | SET(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) 11 | # Set the possible values of build type for cmake-gui 12 | SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" 13 | "MinSizeRel" "RelWithDebInfo") 14 | ENDIF() 15 | 16 | FIND_PACKAGE(Java REQUIRED) 17 | INCLUDE(UseJava) 18 | 19 | ADD_SUBDIRECTORY(src) 20 | 21 | ADD_JAR(${AF_JAR} 22 | com/arrayfire/Algorithm.java 23 | com/arrayfire/Arith.java 24 | com/arrayfire/ArrayFire.java 25 | com/arrayfire/Array.java 26 | com/arrayfire/Data.java 27 | com/arrayfire/DoubleComplex.java 28 | com/arrayfire/FloatComplex.java 29 | com/arrayfire/Image.java 30 | com/arrayfire/Signal.java 31 | com/arrayfire/Util.java 32 | com/arrayfire/Statistics.java 33 | com/arrayfire/JNIException.java 34 | com/arrayfire/ArrayFireException.java 35 | com/arrayfire/Graphics.java 36 | com/arrayfire/Window.java 37 | com/arrayfire/Seq.java 38 | com/arrayfire/Index.java 39 | com/arrayfire/AFLibLoader.java 40 | ) 41 | 42 | ADD_DEPENDENCIES(${AF_JAR} ${AF_LIB}) 43 | 44 | INSTALL_JAR(${AF_JAR} ".") 45 | 46 | IF(BUILD_EXAMPLES) 47 | ADD_SUBDIRECTORY(examples) 48 | ENDIF() 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, AccelerEyes LLC 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | * Neither the name of the AccelerEyes LLC nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | arrayfire-java 2 | ============== 3 | 4 | [Slack Channel](https://join.slack.com/t/arrayfire-org/shared_invite/enQtMjI4MjIzMDMzMTczLWM4ODIyZjA3YmY3NWEwMjk2N2Q0YTQyNGMwZmU4ZjkxNGU0MjYzYmUzYTg3ZTM0MDQxOTE2OTJjNGVkOGEwN2M) 5 | 6 | This repository contains the files required to use ArrayFire from Java. 7 | 8 | Prerequisites 9 | --------------- 10 | 11 | - The latest version of ArrayFire. You can get ArrayFire using one of the following: 12 | - [Download binary installers](http://www.arrayfire.com/download) 13 | - [Build from source](https://github.com/arrayfire/arrayfire) 14 | 15 | - The latest version of `JAVA SDK`. It has been tested with OpenJDK 1.7 and OpenJDK 1.8. Make sure there is an environmental variable `JAVA_HOME` pointing to the root directory of java sdk installation. 16 | 17 | - CUDA 18 | - Tested for CUDA 7.5 19 | 20 | - CMake, minimum version of 2.8. 21 | - On Linux/OSX, it defaults to standard makefiles. 22 | - On Windows, we have tested with `NMake Makefiles`. 23 | 24 | Contents 25 | --------------- 26 | 27 | - `src/`: Contains the source files for the ArrayFire Java wrapper 28 | - `*.cpp` The JNI wrapper files 29 | - `jni_helper.h` The JNI API helper functions 30 | 31 | - `com/`: Contains the Java source files implementing algorithms 32 | 33 | - `examples`: contains a few examples demonstrating the usage 34 | 35 | Usage 36 | ---------------- 37 | 38 | After you the necessary pre-requisites, do the following: 39 | 40 | - `mkdir build` 41 | - `cd build` 42 | - Configure and generate the platform specific make files. 43 | - `cmake ..` on Linux/OSX 44 | - `cmake -G "NMake Makefiles" ..` on Windows from visual studio x64 command prompt. 45 | - Build the project and run helloworld example. 46 | - `make && make exHelloWorld` on Linux/OSX. 47 | - `nmake && nmake exHelloWorld` on Windows. 48 | 49 | Documentation 50 | --------------- 51 | - TODO 52 | 53 | License 54 | --------------- 55 | 56 | - Please check the LICENSE file in the root directory 57 | -------------------------------------------------------------------------------- /com/.gitignore: -------------------------------------------------------------------------------- 1 | arrayfire/*.class 2 | -------------------------------------------------------------------------------- /com/arrayfire/AFLibLoader.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | class AFLibLoader { 4 | static { 5 | System.loadLibrary("af_java"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /com/arrayfire/Algorithm.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | class Algorithm { 4 | 5 | // Scalar return operations 6 | private native static double sumAll(long a); 7 | 8 | private native static double maxAll(long a); 9 | 10 | private native static double minAll(long a); 11 | 12 | private native static long sum(long a, int dim); 13 | 14 | private native static long max(long a, int dim); 15 | 16 | private native static long min(long a, int dim); 17 | 18 | private native static long afWhere(long ref); 19 | 20 | // Scalar return operations 21 | public static double sumAll(Array a) throws Exception { 22 | return sumAll(a.ref); 23 | } 24 | 25 | public static double maxAll(Array a) throws Exception { 26 | return maxAll(a.ref); 27 | } 28 | 29 | public static double minAll(Array a) throws Exception { 30 | return minAll(a.ref); 31 | } 32 | 33 | public static void sum(Array res, Array a, int dim) throws Exception { 34 | long ref = sum(a.ref, dim); 35 | res.set(ref); 36 | } 37 | 38 | public static void max(Array res, Array a, int dim) throws Exception { 39 | long ref = max(a.ref, dim); 40 | res.set(ref); 41 | } 42 | 43 | public static void min(Array res, Array a, int dim) throws Exception { 44 | long ref = min(a.ref, dim); 45 | res.set(ref); 46 | } 47 | 48 | public static void sum(Array res, Array a) throws Exception { 49 | sum(res, a, 0); 50 | } 51 | 52 | public static void max(Array res, Array a) throws Exception { 53 | max(res, a, 0); 54 | } 55 | 56 | public static void min(Array res, Array a) throws Exception { 57 | min(res, a, 0); 58 | } 59 | 60 | public static Array where(final Array in) throws Exception { 61 | return new Array(afWhere(in.ref)); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /com/arrayfire/Arith.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | class Arith { 4 | 5 | // Binary operations 6 | private native static long add(long a, long b); 7 | private native static long sub(long a, long b); 8 | private native static long mul(long a, long b); 9 | private native static long div(long a, long b); 10 | private native static long le(long a, long b); 11 | private native static long lt(long a, long b); 12 | private native static long ge(long a, long b); 13 | private native static long gt(long a, long b); 14 | private native static long eq(long a, long b); 15 | private native static long neq(long a, long b); 16 | // private native static long pow(long a, float b); 17 | 18 | // Scalar Binary operations 19 | private native static long addf(long a, float b); 20 | private native static long subf(long a, float b); 21 | private native static long mulf(long a, float b); 22 | private native static long divf(long a, float b); 23 | private native static long lef(long a, float b); 24 | private native static long ltf(long a, float b); 25 | private native static long gef(long a, float b); 26 | private native static long gtf(long a, float b); 27 | private native static long eqf(long a, float b); 28 | private native static long neqf(long a, float b); 29 | private native static long powf(long a, float b); 30 | private native static long fsub(float a, long b); 31 | private native static long fdiv(float a, long b); 32 | private native static long fle(float a, long b); 33 | private native static long flt(float a, long b); 34 | private native static long fge(float a, long b); 35 | private native static long fgt(float a, long b); 36 | // private native static long fpow(long a, float b); 37 | 38 | // Unary operations 39 | private native static long sin(long a); 40 | private native static long cos(long a); 41 | private native static long tan(long a); 42 | private native static long asin(long a); 43 | private native static long acos(long a); 44 | private native static long atan(long a); 45 | private native static long sinh(long a); 46 | private native static long cosh(long a); 47 | private native static long tanh(long a); 48 | private native static long asinh(long a); 49 | private native static long acosh(long a); 50 | private native static long atanh(long a); 51 | private native static long exp(long a); 52 | private native static long log(long a); 53 | private native static long abs(long a); 54 | private native static long sqrt(long a); 55 | 56 | public static void add(Array c, Array a, Array b) throws Exception { 57 | long ref = add(a.ref, b.ref); 58 | c.set(ref); 59 | } 60 | 61 | public static void sub(Array c, Array a, Array b) throws Exception { 62 | long ref = sub(a.ref, b.ref); 63 | c.set(ref); 64 | } 65 | 66 | public static void mul(Array c, Array a, Array b) throws Exception { 67 | long ref = mul(a.ref, b.ref); 68 | c.set(ref); 69 | } 70 | 71 | public static void div(Array c, Array a, Array b) throws Exception { 72 | long ref = div(a.ref, b.ref); 73 | c.set(ref); 74 | } 75 | 76 | public static void le(Array c, Array a, Array b) throws Exception { 77 | long ref = le(a.ref, b.ref); 78 | c.set(ref); 79 | } 80 | 81 | public static void lt(Array c, Array a, Array b) throws Exception { 82 | long ref = lt(a.ref, b.ref); 83 | c.set(ref); 84 | } 85 | 86 | public static void ge(Array c, Array a, Array b) throws Exception { 87 | long ref = ge(a.ref, b.ref); 88 | c.set(ref); 89 | } 90 | 91 | public static void gt(Array c, Array a, Array b) throws Exception { 92 | long ref = gt(a.ref, b.ref); 93 | c.set(ref); 94 | } 95 | 96 | public static void eq(Array c, Array a, Array b) throws Exception { 97 | long ref = eq(a.ref, b.ref); 98 | c.set(ref); 99 | } 100 | 101 | public static void neq(Array c, Array a, Array b) throws Exception { 102 | long ref = neq(a.ref, b.ref); 103 | c.set(ref); 104 | } 105 | 106 | // Unary operations 107 | public static void sin(Array res, Array a) throws Exception { 108 | long ref = sin(a.ref); 109 | res.set(ref); 110 | } 111 | 112 | public static void cos(Array res, Array a) throws Exception { 113 | long ref = cos(a.ref); 114 | res.set(ref); 115 | } 116 | 117 | public static void tan(Array res, Array a) throws Exception { 118 | long ref = tan(a.ref); 119 | res.set(ref); 120 | } 121 | 122 | public static void asin(Array res, Array a) throws Exception { 123 | long ref = asin(a.ref); 124 | res.set(ref); 125 | } 126 | 127 | public static void acos(Array res, Array a) throws Exception { 128 | long ref = acos(a.ref); 129 | res.set(ref); 130 | } 131 | 132 | public static void atan(Array res, Array a) throws Exception { 133 | long ref = atan(a.ref); 134 | res.set(ref); 135 | } 136 | 137 | public static void sinh(Array res, Array a) throws Exception { 138 | long ref = sinh(a.ref); 139 | res.set(ref); 140 | } 141 | 142 | public static void cosh(Array res, Array a) throws Exception { 143 | long ref = cosh(a.ref); 144 | res.set(ref); 145 | } 146 | 147 | public static void tanh(Array res, Array a) throws Exception { 148 | long ref = tanh(a.ref); 149 | res.set(ref); 150 | } 151 | 152 | public static void asinh(Array res, Array a) throws Exception { 153 | long ref = asinh(a.ref); 154 | res.set(ref); 155 | } 156 | 157 | public static void acosh(Array res, Array a) throws Exception { 158 | long ref = acosh(a.ref); 159 | res.set(ref); 160 | } 161 | 162 | public static void atanh(Array res, Array a) throws Exception { 163 | long ref = atanh(a.ref); 164 | res.set(ref); 165 | } 166 | 167 | public static void exp(Array res, Array a) throws Exception { 168 | long ref = exp(a.ref); 169 | res.set(ref); 170 | } 171 | 172 | public static void log(Array res, Array a) throws Exception { 173 | long ref = log(a.ref); 174 | res.set(ref); 175 | } 176 | 177 | public static void abs(Array res, Array a) throws Exception { 178 | long ref = abs(a.ref); 179 | res.set(ref); 180 | } 181 | 182 | public static void sqrt(Array res, Array a) throws Exception { 183 | long ref = sqrt(a.ref); 184 | res.set(ref); 185 | } 186 | 187 | // Scalar operations 188 | public static void add(Array c, Array a, float b) throws Exception { 189 | long ref = addf(a.ref, b); 190 | c.set(ref); 191 | } 192 | 193 | public static void sub(Array c, Array a, float b) throws Exception { 194 | long ref = subf(a.ref, b); 195 | c.set(ref); 196 | } 197 | 198 | public static void mul(Array c, Array a, float b) throws Exception { 199 | long ref = mulf(a.ref, b); 200 | c.set(ref); 201 | } 202 | 203 | public static void div(Array c, Array a, float b) throws Exception { 204 | long ref = divf(a.ref, b); 205 | c.set(ref); 206 | } 207 | 208 | public static void le(Array c, Array a, float b) throws Exception { 209 | long ref = lef(a.ref, b); 210 | c.set(ref); 211 | } 212 | 213 | public static void lt(Array c, Array a, float b) throws Exception { 214 | long ref = ltf(a.ref, b); 215 | c.set(ref); 216 | } 217 | 218 | public static void ge(Array c, Array a, float b) throws Exception { 219 | long ref = gef(a.ref, b); 220 | c.set(ref); 221 | } 222 | 223 | public static void gt(Array c, Array a, float b) throws Exception { 224 | long ref = gtf(a.ref, b); 225 | c.set(ref); 226 | } 227 | 228 | public static void eq(Array c, Array a, float b) throws Exception { 229 | long ref = eqf(a.ref, b); 230 | c.set(ref); 231 | } 232 | 233 | public static void neq(Array c, Array a, float b) throws Exception { 234 | long ref = neqf(a.ref, b); 235 | c.set(ref); 236 | } 237 | 238 | public static void pow(Array c, Array a, float b) throws Exception { 239 | long ref = powf(a.ref, b); 240 | c.set(ref); 241 | } 242 | 243 | public static void add(Array c, float a, Array b) throws Exception { 244 | long ref = addf(b.ref, a); 245 | c.set(ref); 246 | } 247 | 248 | public static void sub(Array c, float a, Array b) throws Exception { 249 | long ref = fsub(a, b.ref); 250 | c.set(ref); 251 | } 252 | 253 | public static void mul(Array c, float a, Array b) throws Exception { 254 | long ref = mulf(b.ref, a); 255 | c.set(ref); 256 | } 257 | 258 | public static void div(Array c, float a, Array b) throws Exception { 259 | long ref = fdiv(a, b.ref); 260 | c.set(ref); 261 | } 262 | 263 | public static void le(Array c, float a, Array b) throws Exception { 264 | long ref = fle(a, b.ref); 265 | c.set(ref); 266 | } 267 | 268 | public static void lt(Array c, float a, Array b) throws Exception { 269 | long ref = flt(a, b.ref); 270 | c.set(ref); 271 | } 272 | 273 | public static void ge(Array c, float a, Array b) throws Exception { 274 | long ref = fge(a, b.ref); 275 | c.set(ref); 276 | } 277 | 278 | public static void gt(Array c, float a, Array b) throws Exception { 279 | long ref = fgt(a, b.ref); 280 | c.set(ref); 281 | } 282 | } 283 | -------------------------------------------------------------------------------- /com/arrayfire/Array.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | public class Array extends AFLibLoader implements AutoCloseable { 4 | 5 | private native static void destroyArray(long ref); 6 | 7 | private native static int[] getDims(long ref); 8 | 9 | private native static int getType(long ref); 10 | 11 | private native static long createEmptyArray(int[] dims, int type); 12 | 13 | private native static long createArrayFromFloat(int[] dims, float[] elems); 14 | 15 | private native static long createArrayFromDouble(int[] dims, double[] elems); 16 | 17 | private native static long createArrayFromFloatComplex(int[] dims, FloatComplex[] elems); 18 | 19 | private native static long createArrayFromDoubleComplex(int[] dims, DoubleComplex[] elems); 20 | 21 | private native static long createArrayFromInt(int[] dims, int[] elems); 22 | 23 | private native static long createArrayFromBoolean(int[] dims, boolean[] elems); 24 | 25 | private native static String afToString(long ref, String name); 26 | 27 | // Global reference to JVM object 28 | // to persist between JNI calls 29 | protected long ref; 30 | 31 | public Array() { 32 | ref = 0; 33 | } 34 | 35 | protected Array(long other_ref) { 36 | ref = other_ref; 37 | } 38 | 39 | public Array(int[] dims, ArrayFire.Type type) throws Exception { 40 | int[] adims = Array.dim4(dims); 41 | set(createEmptyArray(adims, type.getType())); 42 | } 43 | 44 | public Array(int[] dims, float[] elems) throws IllegalArgumentException { 45 | int[] adims = Array.dim4(dims); 46 | 47 | int total_size = 1; 48 | for (int dim : adims) { 49 | total_size *= dim; 50 | } 51 | 52 | if (elems == null) { 53 | throw new IllegalArgumentException("Null elems object provided"); 54 | } 55 | 56 | if (elems.length > total_size || elems.length < total_size) { 57 | throw new IllegalArgumentException("Mismatching dims and array size"); 58 | } 59 | 60 | set(createArrayFromFloat(adims, elems)); 61 | } 62 | 63 | public Array(int[] dims, double[] elems) throws IllegalArgumentException { 64 | int[] adims = Array.dim4(dims); 65 | 66 | int total_size = 1; 67 | for (int dim : adims) { 68 | total_size *= dim; 69 | } 70 | 71 | if (elems == null) { 72 | throw new IllegalArgumentException("Null elems object provided"); 73 | } 74 | 75 | if (elems.length > total_size || elems.length < total_size) { 76 | throw new IllegalArgumentException("Mismatching dims and array size"); 77 | } 78 | 79 | set(createArrayFromDouble(adims, elems)); 80 | } 81 | 82 | public Array(int[] dims, int[] elems) throws IllegalArgumentException { 83 | int[] adims = Array.dim4(dims); 84 | 85 | int total_size = 1; 86 | for (int dim : adims) { 87 | total_size *= dim; 88 | } 89 | if (elems == null) { 90 | throw new IllegalArgumentException("Null elems object provided"); 91 | } 92 | 93 | if (elems.length > total_size || elems.length < total_size) { 94 | throw new IllegalArgumentException("Mismatching dims and array size"); 95 | } 96 | 97 | set(createArrayFromInt(adims, elems)); 98 | } 99 | 100 | public Array(int[] dims, FloatComplex[] elems) throws Exception { 101 | int[] adims = Array.dim4(dims); 102 | 103 | int total_size = 1; 104 | for (int dim : adims) { 105 | total_size *= dim; 106 | } 107 | 108 | if (elems == null) { 109 | throw new Exception("Null elems object provided"); 110 | } 111 | 112 | if (elems.length > total_size || elems.length < total_size) { 113 | throw new Exception("Mismatching dims and array size"); 114 | } 115 | 116 | set(createArrayFromFloatComplex(adims, elems)); 117 | } 118 | 119 | public Array(int[] dims, DoubleComplex[] elems) throws IllegalArgumentException { 120 | int[] adims = Array.dim4(dims); 121 | 122 | int total_size = 1; 123 | for (int dim : adims) { 124 | total_size *= dim; 125 | } 126 | 127 | if (elems == null) { 128 | throw new IllegalArgumentException("Null elems object provided"); 129 | } 130 | 131 | if (elems.length > total_size || elems.length < total_size) { 132 | throw new IllegalArgumentException("Mismatching dims and array size"); 133 | } 134 | 135 | set(createArrayFromDoubleComplex(adims, elems)); 136 | } 137 | 138 | protected void set(long other_ref) { 139 | if (ref != 0) 140 | destroyArray(ref); 141 | ref = other_ref; 142 | } 143 | 144 | public int[] dims() { 145 | return getDims(ref); 146 | } 147 | 148 | public ArrayFire.Type type() { 149 | return ArrayFire.Type.fromInt(getType(ref)); 150 | } 151 | 152 | protected static int[] dim4(int[] dims) throws IllegalArgumentException { 153 | 154 | if (dims == null) { 155 | throw new IllegalArgumentException("Null dimensions object provided"); 156 | } else if (dims.length > 4) { 157 | throw new IllegalArgumentException("ArrayFire supports up to 4 dimensions only"); 158 | } 159 | 160 | int[] adims = new int[] { 1, 1, 1, 1 }; 161 | System.arraycopy(dims, 0, adims, 0, dims.length); 162 | return adims; 163 | } 164 | 165 | protected void assertType(ArrayFire.Type ty) throws Exception { 166 | 167 | ArrayFire.Type myType = type(); 168 | 169 | if (myType != ty) { 170 | String str = "Type mismatch: "; 171 | str = str + "Requested " + ty; 172 | str = str + ". Found " + myType; 173 | throw new IllegalArgumentException(str); 174 | } 175 | return; 176 | } 177 | 178 | public float[] getFloatArray() throws Exception { 179 | return Data.getFloatArray(this); 180 | } 181 | 182 | public double[] getDoubleArray() throws Exception { 183 | return Data.getDoubleArray(this); 184 | } 185 | 186 | public FloatComplex[] getFloatComplexArray() throws Exception { 187 | return Data.getFloatComplexArray(this); 188 | } 189 | 190 | public DoubleComplex[] getDoubleComplexArray() throws Exception { 191 | return Data.getDoubleComplexArray(this); 192 | } 193 | 194 | public int[] getIntArray() throws Exception { 195 | return Data.getIntArray(this); 196 | } 197 | 198 | public boolean[] getBooleanArray() throws Exception { 199 | return Data.getBooleanArray(this); 200 | } 201 | 202 | public boolean isBool() { 203 | return type() == ArrayFire.Type.Boolean; 204 | } 205 | 206 | @Override 207 | public String toString() { 208 | return afToString(ref, "No name"); 209 | } 210 | 211 | public String toString(String name) { 212 | return afToString(ref, name); 213 | } 214 | 215 | @Override 216 | public void close() throws Exception { 217 | if (ref != 0) 218 | destroyArray(ref); 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /com/arrayfire/ArrayFire.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | import com.arrayfire.Index; 4 | 5 | public class ArrayFire extends AFLibLoader { 6 | 7 | public static final Seq SPAN = Seq.span(); 8 | 9 | /* ************* Algorithm ************* */ 10 | 11 | /** 12 | * Sum all the elements in an Array, wraps 13 | * {@link http://arrayfire.org/docs/group__reduce__func__sum.htm } 14 | * 15 | * @param a the array to be summed 16 | * @return the sum 17 | * @throws Exception 18 | * @see Array 19 | */ 20 | public static double sumAll(Array a) throws Exception { 21 | return Algorithm.sumAll(a); 22 | } 23 | 24 | /** 25 | * Finds the maximum value in an array, wraps 26 | * {@link http://arrayfire.org/docs/group__reduce__func__max.htm} 27 | * 28 | * @param a the input array 29 | * @return the maximum value 30 | * @throws Exception 31 | * @see Array 32 | */ 33 | public static double maxAll(Array a) throws Exception { 34 | return Algorithm.maxAll(a); 35 | } 36 | 37 | /** 38 | * Finds the minimum value in an array, wraps 39 | * {@link http://arrayfire.org/docs/group__reduce__func__min.htm}. 40 | * 41 | * @param a the input array 42 | * @return the minimum value 43 | * @throws Exception 44 | * @see Array 45 | */ 46 | public static double minAll(Array a) throws Exception { 47 | return Algorithm.minAll(a); 48 | } 49 | 50 | /** 51 | * Finds the sum of an array across 1 dimension and stores the result in a 2nd array. 52 | * 53 | * @param res the array in which to store the result 54 | * @param a the input array 55 | * @param dim the dimension across which to find the sum 56 | * @throws Exception 57 | * @see Array 58 | */ 59 | public static void sum(Array res, Array a, int dim) throws Exception { 60 | Algorithm.sum(res, a, dim); 61 | } 62 | 63 | /** 64 | * Finds the maximum values of an array across 1 dimension and stores the result in a 2nd array. 65 | * 66 | * @param res the array in which to store the result. 67 | * @param a the input array 68 | * @param dim the dimenstion across which to find the maximum values 69 | * @throws Exception 70 | * @see Array 71 | */ 72 | public static void max(Array res, Array a, int dim) throws Exception { 73 | Algorithm.max(res, a, dim); 74 | } 75 | 76 | /** 77 | * Finds the minimum values in an array across 1 dimenstion and stores the result in a 2nd array. 78 | * 79 | * @param res the array in which to store the result 80 | * @param a the input array 81 | * @param dim the dimension across which to find the maximum values 82 | * @throws Exception 83 | * @see Array 84 | */ 85 | public static void min(Array res, Array a, int dim) throws Exception { 86 | Algorithm.min(res, a, dim); 87 | } 88 | 89 | 90 | /** 91 | * Finds the sum of values in an array across all dimenstion and stores the result in a 2nd array. 92 | * 93 | * @param res the array in which to store the result 94 | * @param a the input array 95 | * @throws Exception 96 | * @see Array 97 | */ 98 | public static void sum(Array res, Array a) throws Exception { 99 | Algorithm.sum(res, a); 100 | } 101 | 102 | /** 103 | * Finds the max values in an array across all dimenstion and stores the result in a 2nd array. 104 | * 105 | * @param res the array in which to store the result 106 | * @param a the input array 107 | * @throws Exception 108 | * @see Array 109 | */ 110 | public static void max(Array res, Array a) throws Exception { 111 | Algorithm.max(res, a); 112 | } 113 | 114 | /** 115 | * Finds the minimum values in an array across all dimenstion and stores the result in a 2nd 116 | * array. 117 | * 118 | * @param res the array in which to store the result 119 | * @param a the input array 120 | * @throws Exception 121 | * @see Array 122 | */ 123 | public static void min(Array res, Array a) throws Exception { 124 | Algorithm.min(res, a, 0); 125 | } 126 | 127 | /** 128 | * Finds the indices of all non-zero values in an input array, wraps 129 | * {@link http://arrayfire.org/docs/group__scan__func__where.htm} 130 | * 131 | * @param in the input array 132 | * @return an array containing the indices of all non-zero values in the input array 133 | * @throws Exception 134 | */ 135 | public static Array where(final Array in) throws Exception { 136 | return Algorithm.where(in); 137 | } 138 | 139 | /* ************* Arith ************* */ 140 | 141 | /** 142 | * Performs element-wise addition between 2 arrays and stores the result in another array, wraps 143 | * {@link http://arrayfire.org/docs/group__arith__func__add.htm} 144 | * 145 | * @param c the resulting array 146 | * @param a the lhs array 147 | * @param b the rhs array 148 | * @throws Exception 149 | */ 150 | public static void add(Array c, Array a, Array b) throws Exception { 151 | Arith.add(c, a, b); 152 | } 153 | 154 | /** 155 | * Subtracts 2 arrays, storing the result in another array, wraps 156 | * {@link http://arrayfire.org/docs/group__arith__func__sub.htm} 157 | * 158 | * @param c the resulting array 159 | * @param a the lhs array 160 | * @param b the rhs array 161 | * @throws Exception 162 | */ 163 | public static void sub(Array c, Array a, Array b) throws Exception { 164 | Arith.sub(c, a, b); 165 | } 166 | 167 | /** 168 | * Performs element-wise multiplication between 2 arrays, wraps 169 | * {@link http://arrayfire.org/docs/group__arith__func__mul.htm} 170 | * 171 | * @param c the resulting array 172 | * @param a the lhs array 173 | * @param b the rhs array 174 | * @throws Exception 175 | */ 176 | public static void mul(Array c, Array a, Array b) throws Exception { 177 | Arith.mul(c, a, b); 178 | } 179 | 180 | /** 181 | * Divides one array by another array, wraps 182 | * {@link http://arrayfire.org/docs/group__arith__func__div.htm} 183 | * 184 | * @param c the resulting array 185 | * @param a the lhs array 186 | * @param b the rhs array 187 | * @throws Exception 188 | */ 189 | public static void div(Array c, Array a, Array b) throws Exception { 190 | Arith.div(c, a, b); 191 | } 192 | 193 | /** 194 | * Checks if an array is less than or equal to another, wraps 195 | * {@link http://arrayfire.org/docs/group__arith__func__le.htm}. 196 | * 197 | * @param c the resulting array 198 | * @param a the lhs array 199 | * @param b the rhs array 200 | * @throws Exception 201 | */ 202 | public static void le(Array c, Array a, Array b) throws Exception { 203 | Arith.le(c, a, b); 204 | } 205 | 206 | /** 207 | * Checks if an array is less than another, wraps 208 | * {@link http://arrayfire.org/docs/group__arith__func__lt.htm} 209 | * 210 | * @param c the resulting array 211 | * @param a the lhs array 212 | * @param b the rhs array 213 | * @throws Exception 214 | */ 215 | public static void lt(Array c, Array a, Array b) throws Exception { 216 | Arith.lt(c, a, b); 217 | } 218 | 219 | /** 220 | * Checks if an array is greater than or equal to another, wraps 221 | * {@link http://arrayfire.org/docs/group__arith__func__ge.htm} 222 | * 223 | * @param c the resulting array 224 | * @param a the lhs array 225 | * @param b the rhs array 226 | * @throws Exception 227 | */ 228 | public static void ge(Array c, Array a, Array b) throws Exception { 229 | Arith.ge(c, a, b); 230 | } 231 | 232 | /** 233 | * Checks if an array is greater than another, wraps 234 | * {@link http://arrayfire.org/docs/group__arith__func__gt.htm} 235 | * 236 | * @param c the resulting array 237 | * @param a the lhs array 238 | * @param b the rhs array 239 | * @throws Exception 240 | */ 241 | public static void gt(Array c, Array a, Array b) throws Exception { 242 | Arith.gt(c, a, b); 243 | } 244 | 245 | /** 246 | * Checks if 2 input arrays are equal, wraps 247 | * {@link http://arrayfire.org/docs/group__arith__func__eq.htm} 248 | * 249 | * @param c the resulting array 250 | * @param a the lhs array 251 | * @param b the rhs array 252 | * @throws Exception 253 | */ 254 | public static void eq(Array c, Array a, Array b) throws Exception { 255 | Arith.eq(c, a, b); 256 | } 257 | 258 | /** 259 | * Checks if 2 input arrays are not equal, wraps 260 | * {@link http://arrayfire.org/docs/group__arith__func__neq.htm} 261 | * 262 | * @param c the resulting array 263 | * @param a the lhs array 264 | * @param b the rhs array 265 | * @throws Exception 266 | */ 267 | public static void neq(Array c, Array a, Array b) throws Exception { 268 | Arith.neq(c, a, b); 269 | } 270 | 271 | // Unary operations 272 | 273 | /** 274 | * Finds the sin of the elements in an array, wraps 275 | * {@link http://arrayfire.org/docs/group__arith__func__sin.htm} 276 | * 277 | * @param res the resulting array 278 | * @param a the input array 279 | * @throws Exception 280 | */ 281 | public static void sin(Array res, Array a) throws Exception { 282 | Arith.sin(res, a); 283 | } 284 | 285 | /** 286 | * Finds the cosine of the elements in an array, wraps 287 | * {@link http://arrayfire.org/docs/group__arith__func__cos.htm} 288 | * 289 | * @param res the resulting array 290 | * @param a the input array 291 | * @throws Exception 292 | */ 293 | public static void cos(Array res, Array a) throws Exception { 294 | Arith.cos(res, a); 295 | } 296 | 297 | /** 298 | * Finds the tan of the elements in an array, wraps 299 | * {@link http://arrayfire.org/docs/group__arith__func__tan.htm} 300 | * 301 | * @param res the resulting array 302 | * @param a the input array 303 | * @throws Exception 304 | */ 305 | public static void tan(Array res, Array a) throws Exception { 306 | Arith.tan(res, a); 307 | } 308 | 309 | /** 310 | * Finds the asin of the elements in an array, wraps 311 | * {@link http://arrayfire.org/docs/group__arith__func__asin.htm} 312 | * 313 | * @param res the resulting array 314 | * @param a the input array 315 | * @throws Exception 316 | */ 317 | public static void asin(Array res, Array a) throws Exception { 318 | Arith.asin(res, a); 319 | } 320 | 321 | /** 322 | * Finds the acos of the elements in an array, wraps 323 | * {@link http://arrayfire.org/docs/group__arith__func__acos.htm} 324 | * 325 | * @param res the resulting array 326 | * @param a the input array 327 | * @throws Exception 328 | */ 329 | public static void acos(Array res, Array a) throws Exception { 330 | Arith.acos(res, a); 331 | } 332 | 333 | /** 334 | * Finds the atan of the elements in an array, wraps 335 | * {@link http://arrayfire.org/docs/group__arith__func__atan.htm} 336 | * 337 | * @param res the resulting array 338 | * @param a the input array 339 | * @throws Exception 340 | */ 341 | public static void atan(Array res, Array a) throws Exception { 342 | Arith.atan(res, a); 343 | } 344 | 345 | /** 346 | * Finds the sinh of the elements in an array, wraps 347 | * {@link http://arrayfire.org/docs/group__arith__func__sinh.htm} 348 | * 349 | * @param res the resulting array 350 | * @param a the input array 351 | * @throws Exception 352 | */ 353 | public static void sinh(Array res, Array a) throws Exception { 354 | Arith.sinh(res, a); 355 | } 356 | 357 | /** 358 | * Finds the cosh of the elements in an array, wraps 359 | * {@link http://arrayfire.org/docs/group__arith__func__cosh.htm} 360 | * 361 | * @param res the resulting array 362 | * @param a the input array 363 | * @throws Exception 364 | */ 365 | public static void cosh(Array res, Array a) throws Exception { 366 | Arith.cosh(res, a); 367 | } 368 | 369 | /** 370 | * Finds the tanh of the elements in an array, wraps 371 | * {@link http://arrayfire.org/docs/group__arith__func__tanh.htm} 372 | * 373 | * @param res the resulting array 374 | * @param a the input array 375 | * @throws Exception 376 | */ 377 | public static void tanh(Array res, Array a) throws Exception { 378 | Arith.tanh(res, a); 379 | } 380 | 381 | /** 382 | * Finds the asinh of the elements in an array, wraps 383 | * {@link http://arrayfire.org/docs/group__arith__func__asinh.htm} 384 | * 385 | * @param res the resulting array 386 | * @param a the input array 387 | * @throws Exception 388 | */ 389 | public static void asinh(Array res, Array a) throws Exception { 390 | Arith.asinh(res, a); 391 | } 392 | 393 | /** 394 | * Finds the acosh of the elements in an array, wraps 395 | * {@link http://arrayfire.org/docs/group__arith__func__acosh.htm} 396 | * 397 | * @param res the resulting array 398 | * @param a the input array 399 | * @throws Exception 400 | */ 401 | public static void acosh(Array res, Array a) throws Exception { 402 | Arith.acosh(res, a); 403 | } 404 | 405 | /** 406 | * Finds the atanh of the elements in an array, wraps 407 | * {@link http://arrayfire.org/docs/group__arith__func__atanh.htm} 408 | * 409 | * @param res the resulting array 410 | * @param a the input array 411 | * @throws Exception 412 | */ 413 | public static void atanh(Array res, Array a) throws Exception { 414 | Arith.atanh(res, a); 415 | } 416 | 417 | /** 418 | * Finds the exponential of the elements in an array, wraps 419 | * {@link http://arrayfire.org/docs/group__arith__func__exp.htm} 420 | * 421 | * @param res the resulting array 422 | * @param a the input array 423 | * @throws Exception 424 | */ 425 | public static void exp(Array res, Array a) throws Exception { 426 | Arith.exp(res, a); 427 | } 428 | 429 | /** 430 | * Finds the log of the elements in an array, wraps 431 | * {@link http://arrayfire.org/docs/group__arith__func__log.htm} 432 | * 433 | * @param res the resulting array 434 | * @param a the input array 435 | * @throws Exception 436 | */ 437 | public static void log(Array res, Array a) throws Exception { 438 | Arith.log(res, a); 439 | } 440 | 441 | /** 442 | * Finds the absolute value of the elements in an array, wraps 443 | * {@link http://arrayfire.org/docs/group__arith__func__abs.htm} 444 | * 445 | * @param res the resulting array 446 | * @param a the input array 447 | * @throws Exception 448 | */ 449 | public static void abs(Array res, Array a) throws Exception { 450 | Arith.abs(res, a); 451 | } 452 | 453 | /** 454 | * Finds the square root of the elements in an array, wraps 455 | * {@link http://arrayfire.org/docs/group__arith__func__sqrt.htm} 456 | * 457 | * @param res the resulting array 458 | * @param a the input array 459 | * @throws Exception 460 | */ 461 | public static void sqrt(Array res, Array a) throws Exception { 462 | Arith.sqrt(res, a); 463 | } 464 | 465 | // Scalar operations 466 | /** 467 | * Adds a broadcasted value to an array. 468 | * 469 | * @param c the resulting array 470 | * @param a the input array 471 | * @param b the value to broadcast 472 | * @throws Exception 473 | */ 474 | public static void add(Array c, Array a, float b) throws Exception { 475 | Arith.add(c, a, b); 476 | } 477 | 478 | /** 479 | * Subtracts a broadcasted value from an array. 480 | * 481 | * @param c the resulting array 482 | * @param a the input array 483 | * @param b the value to broadcast 484 | * @throws Exception 485 | */ 486 | public static void sub(Array c, Array a, float b) throws Exception { 487 | Arith.sub(c, a, b); 488 | } 489 | 490 | /** 491 | * Performs element-wise multiplication between an array and a broadcasted value. 492 | * 493 | * @param c the resulting array 494 | * @param a the input array 495 | * @param b the value to broadcast 496 | * @throws Exception 497 | */ 498 | public static void mul(Array c, Array a, float b) throws Exception { 499 | Arith.mul(c, a, b); 500 | } 501 | 502 | /** 503 | * Divides an array by a broadcasted value. 504 | * 505 | * @param c the resulting array 506 | * @param a the input array 507 | * @param b the value to broadcast 508 | * @throws Exception 509 | */ 510 | public static void div(Array c, Array a, float b) throws Exception { 511 | Arith.div(c, a, b); 512 | } 513 | 514 | /** 515 | * Finds if an array is less than or equal to a broadcasted value. 516 | * 517 | * @param c the resulting array 518 | * @param a the input array 519 | * @param b the value 520 | * @throws Exception 521 | */ 522 | public static void le(Array c, Array a, float b) throws Exception { 523 | Arith.le(c, a, b); 524 | } 525 | 526 | /** 527 | * Finds if an array is less a broadcasted value. 528 | * 529 | * @param c the resulting array 530 | * @param a the input array 531 | * @param b the value 532 | * @throws Exception 533 | */ 534 | public static void lt(Array c, Array a, float b) throws Exception { 535 | Arith.lt(c, a, b); 536 | } 537 | 538 | /** 539 | * Finds if an array is greater than or equal to a broadcasted value. 540 | * 541 | * @param c the resulting array 542 | * @param a the input array 543 | * @param b the value 544 | * @throws Exception 545 | */ 546 | public static void ge(Array c, Array a, float b) throws Exception { 547 | Arith.ge(c, a, b); 548 | } 549 | 550 | /** 551 | * Finds if an array is greater a broadcasted value. 552 | * 553 | * @param c the resulting array 554 | * @param a the input array 555 | * @param b the value 556 | * @throws Exception 557 | */ 558 | public static void gt(Array c, Array a, float b) throws Exception { 559 | Arith.gt(c, a, b); 560 | } 561 | 562 | /** 563 | * Finds if an array is equal to a broadcasted value. 564 | * 565 | * @param c the resulting array 566 | * @param a the input array 567 | * @param b the value 568 | * @throws Exception 569 | */ 570 | public static void eq(Array c, Array a, float b) throws Exception { 571 | Arith.eq(c, a, b); 572 | } 573 | 574 | /** 575 | * Finds if an array is not equal to a broadcasted value. 576 | * 577 | * @param c the resulting array 578 | * @param a the input array 579 | * @param b the value 580 | * @throws Exception 581 | */ 582 | public static void neq(Array c, Array a, float b) throws Exception { 583 | Arith.neq(c, a, b); 584 | } 585 | 586 | /** 587 | * Raises an array to a power. 588 | * 589 | * @param c the resulting array 590 | * @param a the input array 591 | * @param b the power to raise the array to 592 | * @throws Exception 593 | */ 594 | public static void pow(Array c, Array a, float b) throws Exception { 595 | Arith.pow(c, a, b); 596 | } 597 | 598 | /** 599 | * Adds an array to a broadcasted value. 600 | * 601 | * @param c the resulting array 602 | * @param a the value to which the array is added 603 | * @param b the input array 604 | * @throws Exception 605 | */ 606 | public static void add(Array c, float a, Array b) throws Exception { 607 | Arith.add(c, a, b); 608 | } 609 | 610 | /** 611 | * Subtracts an array from a broadcasted value. 612 | * 613 | * @param c the resulting array 614 | * @param a the value from which the array is subtracted 615 | * @param b the input array 616 | * @throws Exception 617 | */ 618 | public static void sub(Array c, float a, Array b) throws Exception { 619 | Arith.sub(c, a, b); 620 | } 621 | 622 | /** 623 | * Performs element-wise multiplication between a broadcasted value and an array 624 | * 625 | * @param c the resulting array 626 | * @param a the input value 627 | * @param b the input array 628 | * @throws Exception 629 | */ 630 | public static void mul(Array c, float a, Array b) throws Exception { 631 | Arith.mul(c, a, b); 632 | } 633 | 634 | /** 635 | * Divides an array of a broadcasted value by an another array 636 | * 637 | * @param c the resulting array 638 | * @param a the input value 639 | * @param b the input array 640 | * @throws Exception 641 | */ 642 | public static void div(Array c, float a, Array b) throws Exception { 643 | Arith.div(c, a, b); 644 | } 645 | 646 | /** 647 | * Finds if a value is less than or equal to the values in an array 648 | * 649 | * @param c the resulting array 650 | * @param a the input value 651 | * @param b the input array 652 | * @throws Exception 653 | */ 654 | public static void le(Array c, float a, Array b) throws Exception { 655 | Arith.le(c, a, b); 656 | } 657 | 658 | /** 659 | * Finds if a value is less than to the values in an array 660 | * 661 | * @param c the resulting array 662 | * @param a the input value 663 | * @param b the input array 664 | * @throws Exception 665 | */ 666 | public static void lt(Array c, float a, Array b) throws Exception { 667 | Arith.lt(c, a, b); 668 | } 669 | 670 | /** 671 | * Finds if a value is greater than or equal to the values in an array 672 | * 673 | * @param c the resulting array 674 | * @param a the input value 675 | * @param b the input array 676 | * @throws Exception 677 | */ 678 | public static void ge(Array c, float a, Array b) throws Exception { 679 | Arith.ge(c, a, b); 680 | } 681 | 682 | /** 683 | * Finds if a value is greater than the values in an array 684 | * 685 | * @param c the resulting array 686 | * @param a the input value 687 | * @param b the input array 688 | * @throws Exception 689 | */ 690 | public static void gt(Array c, float a, Array b) throws Exception { 691 | Arith.gt(c, a, b); 692 | } 693 | 694 | /* ************* Data ************* */ 695 | 696 | /** 697 | * Gets a floating-point array from the underlining Array data. 698 | * 699 | * @param A the input array 700 | * @return a java array containng the input's data 701 | * @throws Exception 702 | */ 703 | public static float[] getFloatArray(Array A) throws Exception { 704 | return Data.getFloatArray(A); 705 | } 706 | 707 | /** 708 | * Gets a full precision floating-point array from the underlining Array data. 709 | * 710 | * @param A the input array 711 | * @return a java array containng the input's data 712 | * @throws Exception 713 | */ 714 | public static double[] getDoubleArray(Array A) throws Exception { 715 | return Data.getDoubleArray(A); 716 | } 717 | 718 | /** 719 | * Gets a FloatComplex array from the underlining Array data. 720 | * 721 | * @param A the input array 722 | * @return a java array containng the input's data 723 | * @throws Exception 724 | */ 725 | public static FloatComplex[] getFloatComplexArray(Array A) throws Exception { 726 | return Data.getFloatComplexArray(A); 727 | } 728 | 729 | /** 730 | * Gets a DoubleComplex array from the underlining Array data. 731 | * 732 | * @param A the input array 733 | * @return a java array containng the input's data 734 | * @throws Exception 735 | */ 736 | public static DoubleComplex[] getDoubleComplexArray(Array A) throws Exception { 737 | return Data.getDoubleComplexArray(A); 738 | } 739 | 740 | /** 741 | * Gets an int array from the underlining Array data. 742 | * 743 | * @param A the input array 744 | * @return a java array containng the input's data 745 | * @throws Exception 746 | */ 747 | public static int[] getIntArray(Array A) throws Exception { 748 | return Data.getIntArray(A); 749 | } 750 | 751 | /** 752 | * Gets a boolean array from the underlining Array data. 753 | * 754 | * @param A the input array 755 | * @return a java array containng the input's data 756 | * @throws Exception 757 | */ 758 | public static boolean[] getBooleanArray(Array A) throws Exception { 759 | return Data.getBooleanArray(A); 760 | } 761 | 762 | // Binary operations 763 | 764 | /** 765 | * Create a random array sampled from uniform distribution, wraps 766 | * {@link http://arrayfire.org/docs/group__random__func__randu.htm} 767 | * 768 | * @param res the resulting array to populate 769 | * @param dims the array dimenstions 770 | * @param type the type of the array 771 | * @throws Exception 772 | */ 773 | public static void randu(Array res, int[] dims, Type type) throws Exception { 774 | Data.randu(res, dims, type); 775 | } 776 | 777 | /** 778 | * Create a random array sampled from normal distribution, wraps 779 | * {@link http://arrayfire.org/docs/group__random__func__randn.htm} 780 | * 781 | * @param res the resulting array to populate 782 | * @param dims the array dimenstions 783 | * @param type the type of the array 784 | * @throws Exception 785 | */ 786 | public static void randn(Array res, int[] dims, Type type) throws Exception { 787 | Data.randn(res, dims, type); 788 | } 789 | 790 | /** 791 | * Create an array using a scalar input value, wraps 792 | * {@link http://arrayfire.org/docs/group__data__func__constant.htm} 793 | * 794 | * @param res the resulting array to populate 795 | * @param val the scalar value used to populate the array 796 | * @param dims the array dimenstions 797 | * @param type the type of the array 798 | * @throws Exception 799 | */ 800 | public static void constant(Array res, double val, int[] dims, Type type) throws Exception { 801 | Data.constant(res, val, dims, type); 802 | } 803 | 804 | /** 805 | * Create an identity array, wraps 806 | * {@link http://arrayfire.org/docs/group__data__func__identity.htm} 807 | * 808 | * @param res the resulting array to populate 809 | * @param dims the array dimenstions 810 | * @param type the type of the array 811 | * @throws Exception 812 | */ 813 | public static void identity(Array res, int[] dims, Type type) throws Exception { 814 | Data.identity(res, dims, type); 815 | } 816 | 817 | /** 818 | * Create a floating-point identity array, wraps 819 | * {@link http://arrayfire.org/docs/group__data__func__identity.htm} 820 | * 821 | * @param res the resulting array to populate 822 | * @param dims the array dimenstions 823 | * @throws Exception 824 | */ 825 | public static void identity(Array res, int[] dims) throws Exception { 826 | Data.identity(res, dims); 827 | } 828 | 829 | /** 830 | * Creates an array with [0, n] values along the seqDim which is tiled across other dimensions. 831 | * {@link http://arrayfire.org/docs/group__data__func__range.htm} 832 | * 833 | * @param dims the array dimensions 834 | * @param seqDim the dimension along which [0, dim[seq_dim] - 1] is generated 835 | * @param type the type of the array 836 | * @return the created array 837 | */ 838 | public static Array range(int[] dims, int seqDim, Type type) { 839 | return Data.range(dims, seqDim, type); 840 | } 841 | 842 | /** 843 | * Creates an array with [0, n] floating-point values along the seqDim which is tiled across other 844 | * dimensions. {@link http://arrayfire.org/docs/group__data__func__range.htm} 845 | * 846 | * @param dims the array dimensions 847 | * @param seqDim the dimension along which [0, dim[seq_dim] - 1] is generated 848 | * @return the created array 849 | */ 850 | public static Array range(int[] dims, int seqDim) { 851 | return Data.range(dims, seqDim, Type.Float); 852 | } 853 | 854 | /** 855 | * Creates an array with [0, n] floating-point values along the seqDim which is tiled across other 856 | * dimensions. {@link http://arrayfire.org/docs/group__data__func__range.htm} 857 | * 858 | * @param dims the array dimensions 859 | * @param seqDim the dimension along which [0, dim[seq_dim] - 1] is generated 860 | * @return the created array 861 | */ 862 | public static Array range(int[] dims) { 863 | return Data.range(dims, -1, Type.Float); 864 | } 865 | 866 | /** 867 | * Creates an array with [0, n] floating-point values along the seqDim which is tiled across other 868 | * dimensions. {@link http://arrayfire.org/docs/group__data__func__range.htm} 869 | * 870 | * @param dim the size of the first dimension 871 | * @param seqDim the dimension along which [0, dim[seq_dim] - 1] is generated 872 | * @return the created array 873 | */ 874 | public static Array range(int dim) { 875 | return Data.range(new int[] {dim}, -1, Type.Float); 876 | } 877 | 878 | /* ************* Image ************* */ 879 | 880 | /** 881 | * Perform erosion (a morphological operation) on an image, 882 | * {@link http://arrayfire.org/docs/group__image__func__erode.htm} 883 | * 884 | * @param res the eroded image 885 | * @param a the input image 886 | * @param b the neighborhood window 887 | * @throws Exception 888 | */ 889 | public static void erode(Array res, Array a, Array b) throws Exception { 890 | Image.erode(res, a, b); 891 | } 892 | 893 | /** 894 | * Perform dilation (a morphological operation) on an image, 895 | * {@link http://arrayfire.org/docs/group__image__func__dilate.htm} 896 | * 897 | * @param res the dilated image 898 | * @param a the input image 899 | * @param b the neighborhood window 900 | * @throws Exception 901 | */ 902 | public static void dilate(Array res, Array a, Array b) throws Exception { 903 | Image.dilate(res, a, b); 904 | } 905 | 906 | /** 907 | * Finds the median filter of an image, wraps 908 | * {@link http://arrayfire.org/docs/group__image__func__medfilt.htm} 909 | * 910 | * @param res the processed image 911 | * @param a the input image 912 | * @param width the kernel width 913 | * @param height the kernel height 914 | * @throws Exception 915 | */ 916 | public static void medianfilter(Array res, Array a, int width, int height) throws Exception { 917 | Image.medianfilter(res, a, width, height); 918 | } 919 | 920 | /** 921 | * Applies a bilateral filter to an image, wraps 922 | * {@link http://arrayfire.org/docs/group__image__func__bilateral.htm} 923 | * 924 | * @param res the processed image 925 | * @param a the input image 926 | * @param space the spacial variance parameter 927 | * @param color the chromatic variance parameter 928 | * @throws Exception 929 | */ 930 | public static void bilateral(Array res, Array a, float space, float color) throws Exception { 931 | Image.bilateral(res, a, space, color); 932 | } 933 | 934 | /** 935 | * Applies a meanshift filter to an image, wraps 936 | * {@link http://arrayfire.org/docs/group__image__func__mean__shift.htm} 937 | * 938 | * @param res the processed image 939 | * @param a the input image 940 | * @param space the spacial variance parameter 941 | * @param color the chromatic variance parameter 942 | * @param interations the number of iterations 943 | * @throws Exception 944 | */ 945 | public static void meanshift(Array res, Array a, float space, float color, int iterations) 946 | throws Exception { 947 | Image.meanshift(res, a, space, color, iterations); 948 | } 949 | 950 | /** 951 | * Create a histogram of some give data, wraps 952 | * {@link http://arrayfire.org/docs/group__image__func__histogram.htm} 953 | * 954 | * @param res the created array representing the histogram 955 | * @param a the input data 956 | * @param nbins the number of bins to populate 957 | * @throws Exception 958 | */ 959 | public static void histogram(Array res, Array a, int nbins) throws Exception { 960 | Image.histogram(res, a, nbins); 961 | } 962 | 963 | /** 964 | * Create a histogram of some give data, wraps 965 | * {@link http://arrayfire.org/docs/group__image__func__histogram.htm} 966 | * 967 | * @param res the created array representing the histogram 968 | * @param a the input data 969 | * @param nbins the number of bins to populate between min and max 970 | * @param min the minimum bin value 971 | * @param max the maximum bin value 972 | * @throws Exception 973 | */ 974 | public static void histogram(Array res, Array a, int nbins, float min, float max) 975 | throws Exception { 976 | Image.histogram(res, a, nbins, min, max); 977 | } 978 | 979 | /** 980 | * Rotate an input image, wraps 981 | * {@link http://arrayfire.org/docs/group__transform__func__rotate.htm} 982 | * 983 | * @param res the rotated image 984 | * @param a the input image 985 | * @param theta the angle by which to rotate 986 | * @param crop whether to crop against the original dimensions, otherwise scale according to 987 | * theta 988 | * @throws Exception 989 | */ 990 | public static void rotate(Array res, Array a, float theta, boolean crop) throws Exception { 991 | Image.rotate(res, a, theta, crop); 992 | } 993 | 994 | /** 995 | * Rotate an input image, wraps 996 | * {@link http://arrayfire.org/docs/group__transform__func__rotate.htm} 997 | * 998 | * @param res the rotated image 999 | * @param a the input image 1000 | * @param theta the angle by which to rotate 1001 | * @param crop whether to crop against the original dimensions, otherwise scale according to 1002 | * theta 1003 | * @param method the interpolation type 1004 | * @throws Exception 1005 | */ 1006 | public static void rotate(Array res, Array a, float theta, boolean crop, int method) 1007 | throws Exception { 1008 | Image.rotate(res, a, theta, crop, method); 1009 | } 1010 | 1011 | /** 1012 | * Resize an input image, wraps 1013 | * {@link http://arrayfire.org/docs/group__transform__func__resize.htm} 1014 | * 1015 | * @param res the resized image 1016 | * @param a the input image 1017 | * @param scale the scale to resize by 1018 | * @throws Exception 1019 | */ 1020 | public static void resize(Array res, Array a, float scale) throws Exception { 1021 | Image.resize(res, a, scale); 1022 | } 1023 | 1024 | /** 1025 | * Resize an input image, wraps 1026 | * {@link http://arrayfire.org/docs/group__transform__func__resize.htm} 1027 | * 1028 | * @param res the resized image 1029 | * @param a the input image 1030 | * @param scale the scale to resize by 1031 | * @param method the interpolation type 1032 | * @throws Exception 1033 | */ 1034 | public static void resize(Array res, Array a, float scale, int method) throws Exception { 1035 | Image.resize(res, a, scale, method); 1036 | } 1037 | 1038 | /** 1039 | * Resize an input image, wraps 1040 | * {@link http://arrayfire.org/docs/group__transform__func__resize.htm} 1041 | * 1042 | * @param res the resized image 1043 | * @param a the input image 1044 | * @param scalex the scale to resize by for the 1st dimension 1045 | * @param scaley the scale to resize by for the 2nd dimension 1046 | * @throws Exception 1047 | */ 1048 | public static void resize(Array res, Array a, float scalex, float scaley) throws Exception { 1049 | Image.resize(res, a, scalex, scaley); 1050 | } 1051 | 1052 | /** 1053 | * Resize an input image, wraps 1054 | * {@link http://arrayfire.org/docs/group__transform__func__resize.htm} 1055 | * 1056 | * @param res the resized image 1057 | * @param a the input image 1058 | * @param scalex the scale to resize by for the 1st dimension 1059 | * @param scaley the scale to resize by for the 2nd dimension 1060 | * @param method the interpolation type 1061 | * @throws Exception 1062 | */ 1063 | public static void resize(Array res, Array a, float scalex, float scaley, int method) 1064 | throws Exception { 1065 | Image.resize(res, a, scalex, scaley, method); 1066 | } 1067 | 1068 | /** 1069 | * Resize an input image, wraps 1070 | * {@link http://arrayfire.org/docs/group__transform__func__resize.htm} 1071 | * 1072 | * @param res the resized image 1073 | * @param a the input image 1074 | * @param height the height of the image 1075 | * @param width the width of the image 1076 | * @throws Exception 1077 | */ 1078 | public static void resize(Array res, Array a, int height, int width) throws Exception { 1079 | Image.resize(res, a, height, width); 1080 | } 1081 | 1082 | /** 1083 | * Resize an input image, wraps 1084 | * {@link http://arrayfire.org/docs/group__transform__func__resize.htm} 1085 | * 1086 | * @param res the resized image 1087 | * @param a the input image 1088 | * @param height the height of the image 1089 | * @param width the width of the image 1090 | * @param method the interpolation type 1091 | * @throws Exception 1092 | */ 1093 | public static void resize(Array res, Array a, int height, int width, int method) 1094 | throws Exception { 1095 | Image.resize(res, a, height, width, method); 1096 | } 1097 | 1098 | /* ************* Signal ************* */ 1099 | 1100 | /** 1101 | * Compute the fast fourier transform of an array across 1 dimension, wraps 1102 | * {@link http://arrayfire.org/docs/group__signal__func__fft.htm} 1103 | * @param res the fft 1104 | * @param a the input array 1105 | * @throws Exception 1106 | */ 1107 | public static void fft(Array res, Array a) throws Exception { 1108 | Signal.fft(res, a); 1109 | } 1110 | 1111 | /** 1112 | * Compute the fast fourier transform of an array, wraps 1113 | * {@link http://arrayfire.org/docs/group__signal__func__fft.htm} 1114 | * @param res the fft 1115 | * @param a the input array 1116 | * @param dim0 the size of the first dimension 1117 | * @throws Exception 1118 | */ 1119 | public static void fft(Array res, Array a, int dim0) throws Exception { 1120 | Signal.fft(res, a, dim0); 1121 | } 1122 | 1123 | /** 1124 | * Compute the fast fourier transform of an array across 2 dimensions, wraps 1125 | * {@link http://arrayfire.org/docs/group__signal__func__fft.htm} 1126 | * @param res the fft 1127 | * @param a the input array 1128 | * @throws Exception 1129 | */ 1130 | public static void fft2(Array res, Array a) throws Exception { 1131 | Signal.fft2(res, a); 1132 | } 1133 | 1134 | /** 1135 | * Compute the fast fourier transform of an array, wraps 1136 | * {@link http://arrayfire.org/docs/group__signal__func__fft.htm} 1137 | * @param res the fft 1138 | * @param a the input array 1139 | * @param dim0 the size of the first dimension 1140 | * @param dim1 the size of the second dimension 1141 | * @throws Exception 1142 | */ 1143 | public static void fft2(Array res, Array a, int dim0, int dim1) throws Exception { 1144 | Signal.fft2(res, a, dim0, dim1); 1145 | } 1146 | 1147 | /** 1148 | * Compute the fast fourier transform of an array across 3 dimensions, wraps 1149 | * {@link http://arrayfire.org/docs/group__signal__func__fft.htm} 1150 | * @param res the fft 1151 | * @param a the input array 1152 | * @throws Exception 1153 | */ 1154 | public static void fft3(Array res, Array a) throws Exception { 1155 | Signal.fft3(res, a); 1156 | } 1157 | 1158 | /** 1159 | * Compute the fast fourier transform of an array, wraps 1160 | * {@link http://arrayfire.org/docs/group__signal__func__fft.htm} 1161 | * @param res the fft 1162 | * @param a the input array 1163 | * @param dim0 the size of the first dimension 1164 | * @param dim1 the size of the second dimension 1165 | * @param dim2 the size of the third dimension 1166 | * @throws Exception 1167 | */ 1168 | public static void fft3(Array res, Array a, int dim0, int dim1, int dim2) throws Exception { 1169 | Signal.fft3(res, a, dim0, dim1, dim2); 1170 | } 1171 | 1172 | /** 1173 | * Compute the the inverse fast fourier transform of an array across 1 dimension, wraps 1174 | * {@link http://arrayfire.org/docs/group__signal__func__fft.htm} 1175 | * @param res the fft 1176 | * @param a the input array 1177 | * @throws Exception 1178 | */ 1179 | public static void ifft(Array res, Array a) throws Exception { 1180 | Signal.ifft(res, a); 1181 | } 1182 | 1183 | /** 1184 | * Compute the inverse fast fourier transform of an array, wraps 1185 | * {@link http://arrayfire.org/docs/group__signal__func__fft.htm} 1186 | * @param res the fft 1187 | * @param a the input array 1188 | * @param dim0 the size of the first dimension 1189 | * @throws Exception 1190 | */ 1191 | public static void ifft(Array res, Array a, int dim0) throws Exception { 1192 | Signal.ifft(res, a, dim0); 1193 | } 1194 | 1195 | /** 1196 | * Compute the the inverse fast fourier transform of an array across 2 dimensions, wraps 1197 | * {@link http://arrayfire.org/docs/group__signal__func__fft.htm} 1198 | * @param res the fft 1199 | * @param a the input array 1200 | * @throws Exception 1201 | */ 1202 | public static void ifft2(Array res, Array a) throws Exception { 1203 | Signal.ifft2(res, a); 1204 | } 1205 | 1206 | /** 1207 | * Compute the inverse fast fourier transform of an array, wraps 1208 | * {@link http://arrayfire.org/docs/group__signal__func__fft.htm} 1209 | * @param res the fft 1210 | * @param a the input array 1211 | * @param dim0 the size of the first dimension 1212 | * @param dim1 the size of the second dimension 1213 | * @throws Exception 1214 | */ 1215 | public static void ifft2(Array res, Array a, int dim0, int dim1) throws Exception { 1216 | Signal.ifft2(res, a, dim0, dim1); 1217 | } 1218 | 1219 | /** 1220 | * Compute the the inverse fast fourier transform of an array across 3 dimensions, wraps 1221 | * {@link http://arrayfire.org/docs/group__signal__func__fft.htm} 1222 | * @param res the fft 1223 | * @param a the input array 1224 | * @throws Exception 1225 | */ 1226 | public static void ifft3(Array res, Array a) throws Exception { 1227 | Signal.ifft3(res, a); 1228 | } 1229 | 1230 | /** 1231 | * Compute the inverse fast fourier transform of an array, wraps 1232 | * {@link http://arrayfire.org/docs/group__signal__func__fft.htm} 1233 | * @param res the fft 1234 | * @param a the input array 1235 | * @param dim0 the size of the first dimension 1236 | * @param dim1 the size of the second dimension 1237 | * @param dim2 the size of the third dimension 1238 | * @throws Exception 1239 | */ 1240 | public static void ifft3(Array res, Array a, int dim0, int dim1, int dim2) throws Exception { 1241 | Signal.ifft3(res, a, dim0, dim1, dim2); 1242 | } 1243 | 1244 | /** 1245 | * Find the convolutional intergral for 1 dimensional data, wraps 1246 | * {@link http://arrayfire.org/docs/group__signal__func__convolve.htm} 1247 | * @param res the convolved array 1248 | * @param a the signal 1249 | * @param b the filter 1250 | * @throws Exception 1251 | */ 1252 | public static void convolve1(Array res, Array a, Array b) throws Exception { 1253 | Signal.convolve1(res, a, b); 1254 | } 1255 | 1256 | /** 1257 | * Find the convolutional intergral for 2 dimensional data, wraps 1258 | * {@link http://arrayfire.org/docs/group__signal__func__convolve.htm} 1259 | * @param res the convolved array 1260 | * @param a the signal 1261 | * @param b the filter 1262 | * @throws Exception 1263 | */ 1264 | public static void convolve2(Array res, Array a, Array b) throws Exception { 1265 | Signal.convolve2(res, a, b); 1266 | } 1267 | 1268 | /** 1269 | * Find the convolutional intergral for 3 dimensional data, wraps 1270 | * {@link http://arrayfire.org/docs/group__signal__func__convolve.htm} 1271 | * @param res the convolved array 1272 | * @param a the signal 1273 | * @param b the filter 1274 | * @throws Exception 1275 | */ 1276 | public static void convolve3(Array res, Array a, Array b) throws Exception { 1277 | Signal.convolve3(res, a, b); 1278 | } 1279 | 1280 | /* ************* Statistics ************* */ 1281 | 1282 | /** 1283 | * Find the mean of the values in th input across 1 dimension, wraps 1284 | * {@link http://arrayfire.org/docs/group__stat__func__mean.htm} 1285 | * @param in the input array 1286 | * @param dim the dimension 1287 | * @return the array containing the mean 1288 | */ 1289 | public static Array mean(final Array in, int dim) { 1290 | return Statistics.mean(in, dim); 1291 | } 1292 | 1293 | /** 1294 | * Find the weighted mean of the values in th input across 1 dimension, wraps 1295 | * {@link http://arrayfire.org/docs/group__stat__func__mean.htm} 1296 | * @param in the input array 1297 | * @param dim the dimension 1298 | * @param weights the weights of the input 1299 | * @return the array containing the mean 1300 | */ 1301 | public static Array mean(final Array in, final Array weights, int dim) { 1302 | return Statistics.mean(in, weights, dim); 1303 | } 1304 | 1305 | /** 1306 | * Find the mean of all the values in the input, wraps 1307 | * {@link http://arrayfire.org/docs/group__stat__func__mean.htm} 1308 | * @param in the input array 1309 | * @param type the type of the input 1310 | * @return the array containing the mean 1311 | */ 1312 | public static T mean(final Array in, Class type) throws Exception { 1313 | return Statistics.mean(in, type); 1314 | } 1315 | 1316 | /** 1317 | * Find the weighted mean of all the values in the input, wraps 1318 | * {@link http://arrayfire.org/docs/group__stat__func__mean.htm} 1319 | * @param in the input array 1320 | * @param weights the weights of the input 1321 | * @param type the type of the input 1322 | * @return the array containing the mean 1323 | */ 1324 | public static T mean(final Array in, final Array weights, Class type) throws Exception { 1325 | return Statistics.mean(in, weights, type); 1326 | } 1327 | 1328 | /** 1329 | * Find the variance of the values in an input across 1 dimension, wraps 1330 | * {@link http://arrayfire.org/docs/group__stat__func__var.htm} 1331 | * @param in the input array 1332 | * @param isBiased whether to use sample variance 1333 | * @param dim the dimension across which to find the variance 1334 | * @return the resulting array 1335 | */ 1336 | public static Array var(final Array in, boolean isBiased, int dim) { 1337 | return Statistics.var(in, isBiased, dim); 1338 | } 1339 | 1340 | /** 1341 | * Find the weighted variance of the values in an input across 1 dimension, wraps 1342 | * {@link http://arrayfire.org/docs/group__stat__func__var.htm} 1343 | * @param in the input array 1344 | * @param weights weights of the input 1345 | * @param dim the dimension across which to find the variance 1346 | * @return the resulting array 1347 | */ 1348 | public static Array var(final Array in, final Array weights, int dim) { 1349 | return Statistics.var(in, weights, dim); 1350 | } 1351 | 1352 | /** 1353 | * Find the variance of the values in an input across all dimensions, wraps 1354 | * {@link http://arrayfire.org/docs/group__stat__func__var.htm} 1355 | * @param in the input array 1356 | * @param isBiased whether to use sample variance 1357 | * @param type the type of the input array 1358 | * @return the variance across all dimensions 1359 | */ 1360 | public static T var(final Array in, boolean isBiased, Class type) throws Exception { 1361 | return Statistics.var(in, isBiased, type); 1362 | } 1363 | 1364 | /** 1365 | * Find the weighted variance of the values in an input across all dimensions, wraps 1366 | * {@link http://arrayfire.org/docs/group__stat__func__var.htm} 1367 | * @param in the input array 1368 | * @param weights the weights of th input 1369 | * @param type the type of the input array 1370 | * @return the variance across all dimensions 1371 | */ 1372 | public static T var(final Array in, final Array weights, Class type) throws Exception { 1373 | return Statistics.var(in, weights, type); 1374 | } 1375 | 1376 | /** 1377 | * Find the standard deviation of an input across 1 dimension, wraps 1378 | * {@link http://arrayfire.org/docs/group__stat__func__stdev.htm} 1379 | * @param in the input array 1380 | * @param dim the dimension across which to find the standard deviation 1381 | * @return the resulting array containing the standard deviations 1382 | */ 1383 | public static Array stdev(final Array in, int dim) { 1384 | return Statistics.stdev(in, dim); 1385 | } 1386 | 1387 | /** 1388 | * Find the standard deviation of an input across all dimensions, wraps 1389 | * {@link http://arrayfire.org/docs/group__stat__func__stdev.htm} 1390 | * @param in the input array 1391 | * @param type the type of the input array 1392 | * @return the total standard deviation 1393 | */ 1394 | public static T stdev(final Array in, Class type) throws Exception { 1395 | return Statistics.stdev(in, type); 1396 | } 1397 | 1398 | /** 1399 | * Find the median of values in an input across 1 dimension, wraps 1400 | * {@link http://arrayfire.org/docs/group__stat__func__median.htm} 1401 | * @param in the input array 1402 | * @param dim the dimension across which to find the median 1403 | * @return the resulting array containing the medians 1404 | */ 1405 | public static Array median(final Array in, int dim) { 1406 | return Statistics.median(in, dim); 1407 | } 1408 | 1409 | /** 1410 | * Find the median of values in an input across all dimensions, wraps 1411 | * {@link http://arrayfire.org/docs/group__stat__func__median.htm} 1412 | * @param in the input array 1413 | * @param type the type of the input array data 1414 | * @return the median across all dimensions 1415 | */ 1416 | public static T median(final Array in, Class type) throws Exception { 1417 | return Statistics.median(in, type); 1418 | } 1419 | 1420 | /** 1421 | * Find the covariance of values in an input, wraps 1422 | * {@link http://arrayfire.org/docs/group__stat__func__cov.htm} 1423 | * @param x the first input array 1424 | * @param y the second input array 1425 | * @param isBiased whether a biased estimate should be made 1426 | * @return array containing the covariances of the input 1427 | */ 1428 | public static Array cov(Array x, Array y, boolean isBiased) { 1429 | return Statistics.cov(x, y, isBiased); 1430 | } 1431 | 1432 | /** 1433 | * Find the correlation coefficient of values in an input, wraps 1434 | * {@link http://arrayfire.org/docs/group__stat__func__corrcoef.htm} 1435 | * @param the type, should be a number 1436 | * @param x the first input array 1437 | * @param y the seconds input array 1438 | * @param type the type of data in the arrays 1439 | * @return the correlation coefficent of the two arrays 1440 | * @throws Exception 1441 | */ 1442 | public static T corrcoef(final Array x, final Array y, Class type) 1443 | throws Exception { 1444 | return Statistics.corrcoef(x, y, type); 1445 | } 1446 | 1447 | /** 1448 | * Find the top k values along a given dimension on an input array, wraps 1449 | * {@link http://arrayfire.org/docs/group__stat__func__topk.htm} 1450 | * @param in the input array 1451 | * @param k the number of elements to be retrieved along the given dimension 1452 | * @param dim the dimension along which top k values are extracted 1453 | * @param order the order by which to retrieve the values 1454 | * @return an array of array scontaining the top k values 1455 | * @see TopkOrder 1456 | */ 1457 | public static Array[] topk(final Array in, int k, int dim, TopkOrder order) throws Exception { 1458 | return Statistics.topk(in, k, dim, order); 1459 | } 1460 | 1461 | static T castResult(DoubleComplex res, Class type) throws Exception { 1462 | return Statistics.castResult(res, type); 1463 | } 1464 | 1465 | /* ************* Index ************* */ 1466 | 1467 | /** 1468 | * Look up values in an array by indexing another array, wraps 1469 | * {@link http://arrayfire.org/docs/group__index__func__lookup.htm} 1470 | * @param in the input array 1471 | * @param idx the indexing array 1472 | * @param dim the dimension used for indexing 1473 | * @return the array containing the indexed input array 1474 | * @throws Exception 1475 | */ 1476 | public static Array lookup(final Array in, final Array idx, int dim) throws Exception { 1477 | return Index.lookup(in, idx, dim); 1478 | } 1479 | 1480 | /** 1481 | * Look up values in an array by indexing another array, wraps 1482 | * {@link http://arrayfire.org/docs/group__index__func__lookup.htm} 1483 | * @param in the input array 1484 | * @param idx the indexing array 1485 | * @param dim the dimension used for indexing 1486 | * @return the array containing the indexed input array 1487 | * @throws Exception 1488 | */ 1489 | public static Array lookup(final Array in, final Array idx) throws Exception { 1490 | return Index.lookup(in, idx, 0); 1491 | } 1492 | 1493 | /** 1494 | * Copy the values of an input array based on an index, wraps 1495 | * {@link http://arrayfire.org/docs/group__index__func__index.htm} 1496 | * @param dst the array to copy into 1497 | * @param src the array to copy from 1498 | * @param idx0 the first index 1499 | * @param idx1 the second index 1500 | * @param idx2 the third index 1501 | * @param idx3 the fourth index 1502 | * @throws Exception 1503 | */ 1504 | public static void copy(Array dst, final Array src, Index idx0, Index idx1, Index idx2, 1505 | Index idx3) throws Exception { 1506 | Index.copy(dst, src, idx0, idx1, idx2, idx3); 1507 | } 1508 | 1509 | /** 1510 | * Copy the values of an input array based on an index, wraps 1511 | * {@link http://arrayfire.org/docs/group__index__func__index.htm} 1512 | * @param dst the array to copy into 1513 | * @param src the array to copy from 1514 | * @param idx0 the first index 1515 | * @param idx1 the second index 1516 | * @param idx2 the third index 1517 | * @throws Exception 1518 | */ 1519 | public static void copy(Array dst, final Array src, Index idx0, Index idx1, Index idx2) 1520 | throws Exception { 1521 | Index.copy(dst, src, idx0, idx1, idx2, new Index()); 1522 | } 1523 | 1524 | /** 1525 | * Copy the values of an input array based on an index, wraps 1526 | * {@link http://arrayfire.org/docs/group__index__func__index.htm} 1527 | * @param dst the array to copy into 1528 | * @param src the array to copy from 1529 | * @param idx0 the first index 1530 | * @param idx1 the second index 1531 | * @throws Exception 1532 | */ 1533 | public static void copy(Array dst, final Array src, Index idx0, Index idx1) throws Exception { 1534 | Index.copy(dst, src, idx0, idx1, new Index(), new Index()); 1535 | } 1536 | 1537 | /** 1538 | * Copy the values of an input array based on an index, wraps 1539 | * {@link http://arrayfire.org/docs/group__index__func__index.htm} 1540 | * @param dst the array to copy into 1541 | * @param src the array to copy from 1542 | * @param idx0 the first index 1543 | * @throws Exception 1544 | */ 1545 | public static void copy(Array dst, final Array src, Index idx0) throws Exception { 1546 | Index.copy(dst, src, idx0, new Index(), new Index(), new Index()); 1547 | } 1548 | 1549 | // Utils 1550 | 1551 | public static String toString(Array a, String delim) { 1552 | return Util.toString(a, delim); 1553 | } 1554 | 1555 | public static float[] toFloatArray(String text, String delim) { 1556 | return Util.toFloatArray(text, delim); 1557 | } 1558 | 1559 | public static void info() { 1560 | Util.info(); 1561 | } 1562 | 1563 | // Enums 1564 | 1565 | public static enum Type { 1566 | Float(0), FloatComplex(1), Double(2), DoubleComplex(3), Boolean(4), Int(5); 1567 | 1568 | private final int type; 1569 | 1570 | private Type(int type) { 1571 | this.type = type; 1572 | } 1573 | 1574 | public static Type fromInt(int type) throws IllegalArgumentException { 1575 | switch (type) { 1576 | case 0: 1577 | return Type.Float; 1578 | case 1: 1579 | return Type.FloatComplex; 1580 | case 2: 1581 | return Type.Double; 1582 | case 3: 1583 | return Type.DoubleComplex; 1584 | case 4: 1585 | return Type.Boolean; 1586 | case 5: 1587 | return Type.Int; 1588 | default: 1589 | throw new IllegalArgumentException("Unknown type."); 1590 | } 1591 | } 1592 | 1593 | public int getType() { 1594 | return type; 1595 | } 1596 | 1597 | public Type f32() { 1598 | return Type.Float; 1599 | } 1600 | 1601 | public Type f64() { 1602 | return Type.Double; 1603 | } 1604 | 1605 | public Type int32() { 1606 | return Type.Int; 1607 | } 1608 | 1609 | @Override 1610 | public String toString() { 1611 | return this.name(); 1612 | } 1613 | } 1614 | 1615 | public static enum ColorMap { 1616 | DEFAULT(0), SPECTRUM(1), COLORS(2), RED(3), MOOD(4), HEAT(5), BLUE(6), INFERNO(7), MAGMA( 1617 | 8), PLASMA(9), VIRIDIS(10); 1618 | 1619 | private final int map; 1620 | 1621 | private ColorMap(int map) { 1622 | this.map = map; 1623 | } 1624 | 1625 | public int getMap() { 1626 | return map; 1627 | } 1628 | } 1629 | 1630 | public static enum MarkerType { 1631 | NONE(0), POINT(1), CIRCLE(2), SQUARE(3), TRIANGLE(4), CROSS(5), PLUS(6), STAR(7); 1632 | 1633 | private final int type; 1634 | 1635 | private MarkerType(int type) { 1636 | this.type = type; 1637 | } 1638 | 1639 | public int getType() { 1640 | return type; 1641 | } 1642 | } 1643 | 1644 | public static enum TopkOrder { 1645 | DEFAULT(0), MIN(1), MAX(2); 1646 | 1647 | private final int order; 1648 | 1649 | TopkOrder(int order) { 1650 | this.order = order; 1651 | } 1652 | 1653 | public int getOrder() { 1654 | return order; 1655 | } 1656 | } 1657 | } 1658 | -------------------------------------------------------------------------------- /com/arrayfire/ArrayFireException.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | import java.util.Collections; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | 8 | class ArrayFireException extends JNIException { 9 | private static final Map errorCodes; 10 | 11 | static { 12 | @SuppressWarnings("serial") 13 | final Map map = new HashMap<>() { 14 | { 15 | put(0, "Success"); 16 | put(101, "AF_ERR_NO_MEM: The system or device ran out of memory."); 17 | put(102, "AF_ERR_DRIVER: There was an error in the device driver."); 18 | put(103, "AF_ERR_RUNTIME: There was an error in the runtime environment."); 19 | put(201, "AF_ERR_INVALID_ARRAY: The input variable is not a valid Array object."); 20 | put(202, "AF_ERR_ARG: One of the function arguments is incorrect."); 21 | put(203, "AF_ERR_SIZE: The size is incorrect."); 22 | put(204, "AF_ERR_TYPE: The type is not supported by this function."); 23 | put(205, "AF_ERR_DIFF_TYPE: The types of the input arrays are incompatible."); 24 | put(207, "AF_ERR_BATCH: Function does not support GFOR / batch mode."); 25 | put(208, "AF_ERR_DEVICE: Input does not belong to the current device."); 26 | put(301, "AF_ERR_NOT_SUPPORTED: The option is not supported."); 27 | put(302, "AF_ERR_NOT_CONFIGURED: The build of ArrayFire does not support this feature."); 28 | put(303, "AF_ERR_NONFREE: The build of ArrayFire is not compiled with \"nonfree\" algorithms"); 29 | put(401, "AF__ERR_NO_DBL: This device does not support double"); 30 | put(402, 31 | "AF_ERR_NO_GFX: This build of ArrayFire was not built with graphics or this device does not support graphics."); 32 | put(501, "AF_ERR_LOAD_LIB: There was an error loading the libraries."); 33 | put(502, "AF_ERR_LOAD_SYM: There was an error when loading the symbols."); 34 | put(503, "AF_ERR_ARR_BKND_MISMATCH: There was a mismatch between the input array and the active backend."); 35 | put(998, "AF_ERR_INTERNAL: There was an internal error either in ArrayFire or in a project upstream."); 36 | put(999, "AF_ERR_UNKNOWN: An unknown error has occured."); 37 | } 38 | }; 39 | errorCodes = Collections.unmodifiableMap(map); 40 | } 41 | 42 | public ArrayFireException(int code, String message) { 43 | super(String.format("%s %s (code: %d)", errorCodes.get(code), message, code)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /com/arrayfire/Data.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | class Data { 4 | 5 | private native static long createRanduArray(int[] dims, int type); 6 | 7 | private native static long createRandnArray(int[] dims, int type); 8 | 9 | private native static long createConstantsArray(double val, int[] dims, int type); 10 | 11 | private native static float[] getFloatFromArray(long ref); 12 | 13 | private native static double[] getDoubleFromArray(long ref); 14 | 15 | private native static int[] getIntFromArray(long ref); 16 | 17 | private native static boolean[] getBooleanFromArray(long ref); 18 | 19 | private native static FloatComplex[] getFloatComplexFromArray(long ref); 20 | 21 | private native static DoubleComplex[] getDoubleComplexFromArray(long ref); 22 | 23 | private native static long createIdentityArray(int[] dims, int type); 24 | 25 | private native static long afRange(int[] dims, int seqDim, int type); 26 | 27 | public static float[] getFloatArray(Array A) throws Exception { 28 | A.assertType(ArrayFire.Type.Float); 29 | return getFloatFromArray(A.ref); 30 | } 31 | 32 | public static double[] getDoubleArray(Array A) throws Exception { 33 | A.assertType(ArrayFire.Type.Double); 34 | return getDoubleFromArray(A.ref); 35 | } 36 | 37 | public static FloatComplex[] getFloatComplexArray(Array A) throws Exception { 38 | A.assertType(ArrayFire.Type.FloatComplex); 39 | return getFloatComplexFromArray(A.ref); 40 | } 41 | 42 | public static DoubleComplex[] getDoubleComplexArray(Array A) throws Exception { 43 | A.assertType(ArrayFire.Type.DoubleComplex); 44 | return getDoubleComplexFromArray(A.ref); 45 | } 46 | 47 | public static int[] getIntArray(Array A) throws Exception { 48 | A.assertType(ArrayFire.Type.Int); 49 | return getIntFromArray(A.ref); 50 | } 51 | 52 | public static boolean[] getBooleanArray(Array A) throws Exception { 53 | A.assertType(ArrayFire.Type.Boolean); 54 | return getBooleanFromArray(A.ref); 55 | } 56 | 57 | // Binary operations 58 | public static void randu(Array res, int[] dims, ArrayFire.Type type) throws Exception { 59 | int[] adims = Array.dim4(dims); 60 | res.set(createRanduArray(adims, type.getType())); 61 | } 62 | 63 | public static void randn(Array res, int[] dims, ArrayFire.Type type) throws Exception { 64 | int[] adims = Array.dim4(dims); 65 | res.set(createRandnArray(adims, type.getType())); 66 | } 67 | 68 | public static void constant(Array res, double val, int[] dims, ArrayFire.Type type) throws Exception { 69 | int[] adims = Array.dim4(dims); 70 | res.set(createConstantsArray(val, adims, type.getType())); 71 | } 72 | 73 | public static void identity(Array res, int[] dims, ArrayFire.Type type) throws Exception { 74 | int[] adims = Array.dim4(dims); 75 | res.set(createIdentityArray(adims, type.getType())); 76 | } 77 | 78 | public static void identity(Array res, int[] dims) throws Exception { 79 | identity(res, dims, ArrayFire.Type.Float); 80 | } 81 | 82 | public static Array range(int[] dims, int seqDim, ArrayFire.Type type) { 83 | int[] adims = Array.dim4(dims); 84 | return new Array(afRange(adims, seqDim, seqDim)); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /com/arrayfire/DoubleComplex.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | public class DoubleComplex { 4 | private double real; 5 | private double imag; 6 | 7 | public double real() { 8 | return real; 9 | } 10 | 11 | public double imag() { 12 | return imag; 13 | } 14 | 15 | public void set(double re, double im) { 16 | real = re; 17 | imag = im; 18 | } 19 | 20 | public void setReal(double re) { 21 | real = re; 22 | } 23 | 24 | public void setImag(double im) { 25 | imag = im; 26 | } 27 | 28 | public DoubleComplex(double re, double im) { 29 | set(re, im); 30 | } 31 | 32 | public DoubleComplex() { 33 | set(0, 0); 34 | } 35 | 36 | public String toString() { 37 | String str = String.valueOf(real); 38 | 39 | if (imag < 0) 40 | str = str + " - "; 41 | else 42 | str = str + " + "; 43 | 44 | return str + String.valueOf(Math.abs(imag)) + "i"; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /com/arrayfire/FloatComplex.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | public class FloatComplex { 4 | private float real; 5 | private float imag; 6 | 7 | public float real() { 8 | return real; 9 | } 10 | 11 | public float imag() { 12 | return imag; 13 | } 14 | 15 | public void set(float re, float im) { 16 | real = re; 17 | imag = im; 18 | } 19 | 20 | public void setReal(float re) { 21 | real = re; 22 | } 23 | 24 | public void setImag(float im) { 25 | imag = im; 26 | } 27 | 28 | public FloatComplex(float re, float im) { 29 | set(re, im); 30 | } 31 | 32 | public FloatComplex() { 33 | set(0, 0); 34 | } 35 | 36 | public String toString() { 37 | String str = String.valueOf(real); 38 | 39 | if (imag < 0) 40 | str = str + " - "; 41 | else 42 | str = str + " + "; 43 | 44 | return str + String.valueOf(Math.abs(imag)) + "i"; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /com/arrayfire/Graphics.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | class Graphics { 4 | 5 | public static native long afInitWindow(int width, int height, String name); 6 | 7 | public static native void afDestroyWindow(long wnd); 8 | 9 | public static native void afSetPos(long wnd, int x, int y); 10 | 11 | public static native void afSetTitle(long wnd, String title); 12 | 13 | public static native void afSetSize(long wnd, int w, int h); 14 | 15 | public static native void afDrawImage(long wnd, long arr, int r, int c, String title, int cmap); 16 | 17 | public static native void afDrawPlotnd(long wnd, long arr, int r, int c, String title); 18 | 19 | public static native void afDrawPlot2d(long wnd, long arrX, long arrY, int r, int c, String title); 20 | 21 | public static native void afDrawPlot3d(long wnd, long arrX, long arrY, long arrZ, int r, int c, String title); 22 | 23 | public static native void afDrawScatternd(long wnd, long arr, int r, int c, int markerType, String title); 24 | 25 | public static native void afDrawScatter2d(long wnd, long arrX, long arrY, int r, int c, int markerType, String title); 26 | 27 | public static native void afDrawScatter3d(long wnd, long arrX, long arrY, long arrZ, int r, int c, int markerType, 28 | String title); 29 | 30 | public static native void afDrawHist(long wnd, long arr, int r, int c, double min, double max, String title); 31 | 32 | public static native void afDrawSurface(long wnd, long arr, long xVals, long yVals, int r, int c, String title); 33 | 34 | public static native void afDrawVectorFieldnd(long wnd, long points, long directions, int r, int c, String title); 35 | 36 | public static native void afDrawVectorField2d(long wnd, long xPoints, long yPoints, long xDirections, 37 | long yDirections, int r, int c, String title); 38 | 39 | public static native void afDrawVectorField3d(long wnd, long xPoints, long yPoints, long zPoints, long xDirections, 40 | long yDirections, long zDirections, int r, int c, String title); 41 | 42 | public static native void afGrid(long wnd, int rows, int columns); 43 | 44 | public static native void afSetAxesLimitsCompute(long wnd, long arrX, long arrY, long arrZ, boolean isExact, int r, 45 | int c); 46 | 47 | public static native void afSetAxesLimits2d(long wnd, float xMin, float xMax, float yMin, float yMax, boolean isExact, 48 | int r, int c); 49 | 50 | public static native void afSetAxesLimits3d(long wnd, float xMin, float xMax, float yMin, float yMax, float zMin, 51 | float zMax, boolean isExact, int r, int c); 52 | 53 | public static native void afSetAxesTitles(String xTitle, String yTitle, String zTitle); 54 | 55 | public static native void afShow(long wnd); 56 | 57 | public static native boolean afClose(long wnd); 58 | 59 | public static native void afSetVisibility(long wnd, boolean isVisible); 60 | } 61 | -------------------------------------------------------------------------------- /com/arrayfire/Image.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | class Image { 4 | 5 | private native static long erode(long a, long b); 6 | 7 | private native static long dilate(long a, long b); 8 | 9 | private native static long medfilt(long a, int w, int h); 10 | 11 | private native static long bilateral(long a, float space, float color); 12 | 13 | private native static long meanshift(long a, float space, float color, int iter); 14 | 15 | private native static long histogram(long a, int nbins); 16 | 17 | private native static long hist_mnmx(long a, int nbins, float min, float max); 18 | 19 | private native static long rotate(long a, float theta, boolean crop, int method); 20 | 21 | private native static long resize1(long a, float scale, int method); 22 | 23 | private native static long resize2(long a, float scalex, float scaley, int method); 24 | 25 | private native static long resize3(long a, int height, int width, int method); 26 | 27 | public static void erode(Array res, Array a, Array b) throws Exception { 28 | long ref = erode(a.ref, b.ref); 29 | res.set(ref); 30 | } 31 | 32 | public static void dilate(Array res, Array a, Array b) throws Exception { 33 | long ref = dilate(a.ref, b.ref); 34 | res.set(ref); 35 | } 36 | 37 | public static void medianfilter(Array res, Array a, int width, int height) throws Exception { 38 | long ref = medfilt(a.ref, width, height); 39 | res.set(ref); 40 | } 41 | 42 | public static void bilateral(Array res, Array a, float space, float color) throws Exception { 43 | long ref = bilateral(a.ref, space, color); 44 | res.set(ref); 45 | } 46 | 47 | public static void meanshift(Array res, Array a, float space, float color, int iterations) throws Exception { 48 | long ref = meanshift(a.ref, space, color, iterations); 49 | res.set(ref); 50 | } 51 | 52 | public static void histogram(Array res, Array a, int nbins) throws Exception { 53 | long ref = histogram(a.ref, nbins); 54 | res.set(ref); 55 | } 56 | 57 | public static void histogram(Array res, Array a, int nbins, float min, float max) throws Exception { 58 | long ref = hist_mnmx(a.ref, nbins, min, max); 59 | res.set(ref); 60 | } 61 | 62 | public static void rotate(Array res, Array a, float theta, boolean crop) throws Exception { 63 | long ref = rotate(a.ref, theta, crop, 0); 64 | res.set(ref); 65 | } 66 | 67 | public static void rotate(Array res, Array a, float theta, boolean crop, int method) throws Exception { 68 | long ref = rotate(a.ref, theta, crop, method); 69 | res.set(ref); 70 | } 71 | 72 | public static void resize(Array res, Array a, float scale) throws Exception { 73 | long ref = resize1(a.ref, scale, 0); 74 | res.set(ref); 75 | } 76 | 77 | public static void resize(Array res, Array a, float scale, int method) throws Exception { 78 | long ref = resize1(a.ref, scale, method); 79 | res.set(ref); 80 | } 81 | 82 | public static void resize(Array res, Array a, float scalex, float scaley) throws Exception { 83 | long ref = resize2(a.ref, scalex, scaley, 0); 84 | res.set(ref); 85 | } 86 | 87 | public static void resize(Array res, Array a, float scalex, float scaley, int method) throws Exception { 88 | long ref = resize2(a.ref, scalex, scaley, method); 89 | res.set(ref); 90 | } 91 | 92 | public static void resize(Array res, Array a, int height, int width) throws Exception { 93 | long ref = resize3(a.ref, height, width, 0); 94 | res.set(ref); 95 | } 96 | 97 | public static void resize(Array res, Array a, int height, int width, int method) throws Exception { 98 | long ref = resize3(a.ref, height, width, method); 99 | res.set(ref); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /com/arrayfire/Index.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | import java.util.Arrays; 4 | 5 | public class Index { 6 | private Array arr; 7 | private Seq seq; 8 | private boolean isSeq; 9 | private boolean isBatch; 10 | 11 | private static native long afLookup(long in, long index, int dim); 12 | private static native void afCopy(long dst, long src, int ndims, Object idx0, Object idx1, 13 | Object idx2, Object idx3); 14 | 15 | public Index() { 16 | seq = ArrayFire.SPAN; 17 | isSeq = true; 18 | isBatch = false; 19 | } 20 | 21 | public Index(int idx) throws Exception { 22 | seq = new Seq(idx, idx, 1); 23 | isSeq = true; 24 | isBatch = false; 25 | } 26 | 27 | public Index(final Seq seq) throws Exception { 28 | this.seq = new Seq(seq); 29 | isSeq = true; 30 | isBatch = this.seq.gfor; 31 | } 32 | 33 | public Index(final Array idx) throws Exception { 34 | arr = idx.isBool() ? Algorithm.where(idx) : new Array(idx.ref); 35 | isSeq = false; 36 | isBatch = false; 37 | } 38 | 39 | public Index(final Index other) { 40 | arr = new Array(other.arr.ref); 41 | seq = new Seq(other.seq); 42 | isSeq = other.isSeq; 43 | isBatch = other.isBatch; 44 | } 45 | 46 | public long getArrayRef() { 47 | return arr.ref; 48 | } 49 | 50 | public Object getSeq() { 51 | return seq; 52 | } 53 | 54 | public boolean isSeq() { 55 | return isSeq; 56 | } 57 | 58 | public boolean isBatch() { 59 | return isBatch; 60 | } 61 | 62 | public boolean isSpan() { 63 | return isSeq && seq == ArrayFire.SPAN; 64 | } 65 | 66 | static Array lookup(final Array in, final Array idx, int dim) throws Exception { 67 | return new Array(afLookup(in.ref, idx.ref, dim)); 68 | } 69 | 70 | static void copy(Array dst, final Array src, Index idx0, Index idx1, 71 | Index idx2, Index idx3) throws Exception{ 72 | int ndims = Arrays.stream(dst.dims()).filter(x -> x > 1).toArray().length; 73 | afCopy(dst.ref, src.ref, ndims, idx0, idx1, idx2, idx3); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /com/arrayfire/JNIException.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | class JNIException extends Exception { 4 | public JNIException(String message) { 5 | super(message); 6 | } 7 | 8 | /** 9 | * Called by native code during construction to set the location. 10 | */ 11 | public void setLocation(String functionName, String file, int line) { 12 | JNIException.addStackTraceElement(this, functionName, file, line); 13 | } 14 | 15 | /** 16 | * Pushes a stack trace element onto the existing stack trace of the throwable. 17 | */ 18 | public static void addStackTraceElement​(Throwable t, String functionName, String file, int line) { 19 | StackTraceElement[] currentStack = t​.getStackTrace(); 20 | StackTraceElement[] newStack = new StackTraceElement[currentStack​.length + 1]; 21 | System.arraycopy(currentStack, 0, newStack, 1, currentStack​.length); 22 | file = file.replace('\\', '/'); 23 | if (file.lastIndexOf('/') > -1) { 24 | file = file.substring(file​.lastIndexOf('/') + 1); 25 | } 26 | newStack[0] = new StackTraceElement("", functionName, file, line); 27 | t​.setStackTrace(newStack); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /com/arrayfire/Seq.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | import static com.arrayfire.Util.*; 4 | import static com.arrayfire.ArrayFire.range; 5 | import static com.arrayfire.ArrayFire.add; 6 | import static com.arrayfire.ArrayFire.mul; 7 | 8 | public class Seq extends AFLibLoader { 9 | // Start position of the sequence 10 | private double begin; 11 | // End position of the sequence (inclusive) 12 | private double end; 13 | // Step size between sequence values 14 | private double step; 15 | 16 | private long size; 17 | protected boolean gfor; // always false until implemented 18 | 19 | public Seq() { 20 | this(0); 21 | } 22 | 23 | public Seq(double length) { 24 | if (length < 0) { 25 | init(0, length, 1); 26 | } else { 27 | init(0, length - 1, 1); 28 | } 29 | } 30 | 31 | public Seq(double begin, double end) throws Exception { 32 | this(begin, end, 1); 33 | } 34 | 35 | public Seq(double begin, double end, double step) throws Exception { 36 | if (step == 0 && begin != end) { // Span 37 | throw new IllegalArgumentException("Invalid step size."); 38 | } 39 | if ((signbit(end) == signbit(begin)) && (signbit(end - begin) != signbit(step))) { 40 | throw new Exception("Sequence is invalid"); 41 | } 42 | init(begin, end, step); 43 | } 44 | 45 | public Seq(Seq other) { 46 | set(other); 47 | } 48 | 49 | protected static Seq span() { 50 | try { 51 | return new Seq(1, 1, 0); // will never throw 52 | } catch (Exception ex) { 53 | return null; 54 | } 55 | } 56 | 57 | public void set(Seq other) { 58 | init(other.begin, other.end, other.step); 59 | } 60 | 61 | public Seq negate() throws Exception { 62 | return new Seq(-begin, -end, -step); 63 | } 64 | 65 | public Seq addOffset(double offset) throws Exception { 66 | return new Seq(begin + offset, end + offset, step); 67 | } 68 | 69 | public Seq subtractOffset(double offset) throws Exception { 70 | return new Seq(begin - offset, end - offset, step); 71 | } 72 | 73 | public Seq spaceBy(double factor) throws Exception { 74 | return new Seq(begin * factor, end * factor, step * factor); 75 | } 76 | 77 | public Array toArray() throws Exception { 78 | double diff = end - begin; 79 | int len = (int)((diff + Math.abs(step) * (signbit(diff) == 0 ? 1 : -1)) / step); 80 | Array tmp = range(len); 81 | Array res = new Array(); 82 | mul(res, (float) step, tmp); 83 | add(res, (float)begin, res); 84 | return res; 85 | } 86 | 87 | private void init(double begin, double end, double step) { 88 | this.begin = begin; 89 | this.end = end; 90 | this.step = step; 91 | this.gfor = false; 92 | this.size = (long)(step != 0 ? Math.abs((end - begin) / step) + 1 : 0); 93 | } 94 | 95 | @Override 96 | public boolean equals(Object obj) { 97 | if (obj == this) { 98 | return true; 99 | } 100 | if (obj == null || obj.getClass() != this.getClass()) { 101 | return false; 102 | } 103 | Seq seq = (Seq) obj; 104 | return this.begin == seq.begin && this.end == seq.end && 105 | this.step == seq.step && size == seq.size; 106 | } 107 | 108 | @Override 109 | public int hashCode() { 110 | final int prime = 31; 111 | int result = 1; 112 | result = prime * result + (int) ((int)begin ^ ((int)begin >>> 32)); 113 | result = prime * result + (int) ((int) end ^ ((int) end >>> 32)); 114 | result = prime * result + (int) ((int) step ^ ((int) step >>> 32)); 115 | result = prime * result + (int) ((int) size ^ ((int) size >>> 32)); 116 | return result; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /com/arrayfire/Signal.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | class Signal { 4 | 5 | private native static long fft(long a, int dim0); 6 | 7 | private native static long fft2(long a, int dim0, int dim1); 8 | 9 | private native static long fft3(long a, int dim0, int dim1, int dim2); 10 | 11 | private native static long ifft(long a, int dim0); 12 | 13 | private native static long ifft2(long a, int dim0, int dim1); 14 | 15 | private native static long ifft3(long a, int dim0, int dim1, int dim2); 16 | 17 | private native static long convolve1(long a, long b, int type); 18 | 19 | private native static long convolve2(long a, long b, int type); 20 | 21 | private native static long convolve3(long a, long b, int type); 22 | 23 | public static void fft(Array res, Array a) throws Exception { 24 | long ref = fft(a.ref, 0); 25 | res.set(ref); 26 | } 27 | 28 | public static void fft(Array res, Array a, int dim0) throws Exception { 29 | long ref = fft(a.ref, dim0); 30 | res.set(ref); 31 | } 32 | 33 | public static void fft2(Array res, Array a) throws Exception { 34 | long ref = fft2(a.ref, 0, 0); 35 | res.set(ref); 36 | } 37 | 38 | public static void fft2(Array res, Array a, int dim0, int dim1) throws Exception { 39 | long ref = fft2(a.ref, dim0, dim1); 40 | res.set(ref); 41 | } 42 | 43 | public static void fft3(Array res, Array a) throws Exception { 44 | long ref = fft3(a.ref, 0, 0, 0); 45 | res.set(ref); 46 | } 47 | 48 | public static void fft3(Array res, Array a, int dim0, int dim1, int dim2) throws Exception { 49 | long ref = fft3(a.ref, dim0, dim1, dim2); 50 | res.set(ref); 51 | } 52 | 53 | public static void ifft(Array res, Array a) throws Exception { 54 | long ref = ifft(a.ref, 0); 55 | res.set(ref); 56 | } 57 | 58 | public static void ifft(Array res, Array a, int dim0) throws Exception { 59 | long ref = ifft(a.ref, dim0); 60 | res.set(ref); 61 | } 62 | 63 | public static void ifft2(Array res, Array a) throws Exception { 64 | long ref = ifft2(a.ref, 0, 0); 65 | res.set(ref); 66 | } 67 | 68 | public static void ifft2(Array res, Array a, int dim0, int dim1) throws Exception { 69 | long ref = ifft2(a.ref, dim0, dim1); 70 | res.set(ref); 71 | } 72 | 73 | public static void ifft3(Array res, Array a) throws Exception { 74 | long ref = ifft3(a.ref, 0, 0, 0); 75 | res.set(ref); 76 | } 77 | 78 | public static void ifft3(Array res, Array a, int dim0, int dim1, int dim2) throws Exception { 79 | long ref = ifft3(a.ref, dim0, dim1, dim2); 80 | res.set(ref); 81 | } 82 | 83 | public static void convolve1(Array res, Array a, Array b) throws Exception { 84 | long ref = convolve1(a.ref, b.ref, 0); 85 | res.set(ref); 86 | } 87 | 88 | public static void convolve2(Array res, Array a, Array b) throws Exception { 89 | long ref = convolve2(a.ref, b.ref, 0); 90 | res.set(ref); 91 | } 92 | 93 | public static void convolve3(Array res, Array a, Array b) throws Exception { 94 | long ref = convolve3(a.ref, b.ref, 0); 95 | res.set(ref); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /com/arrayfire/Statistics.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | import static com.arrayfire.ArrayFire.*; 4 | 5 | class Statistics { 6 | 7 | static private native long afMean(long ref, int dim); 8 | 9 | static private native long afMeanWeighted(long ref, long weightsRef, int dim); 10 | 11 | static private native DoubleComplex afMeanAll(long ref); 12 | 13 | static private native DoubleComplex afMeanAllWeighted(long ref, long weightsRef); 14 | 15 | static private native long afVar(long ref, boolean isBiased, int dim); 16 | 17 | static private native long afVarWeighted(long ref, long weightsRef, int dim); 18 | 19 | static private native DoubleComplex afVarAll(long ref, boolean isBiased); 20 | 21 | static private native DoubleComplex afVarAllWeighted(long ref, long weightsRef); 22 | 23 | static private native long afStdev(long ref, int dim); 24 | 25 | static private native DoubleComplex afStdevAll(long ref); 26 | 27 | static private native long afMedian(long ref, int dim); 28 | 29 | static private native DoubleComplex afMedianAll(long ref); 30 | 31 | static private native long afCov(long ref, long ref2, boolean isBiased); 32 | 33 | static private native DoubleComplex afCorrcoef(long ref, long ref2); 34 | 35 | static private native long[] afTopk(long ref, int k, int dim, int order); 36 | 37 | static public Array mean(final Array in, int dim) { 38 | return new Array(afMean(in.ref, dim)); 39 | } 40 | 41 | static public Array mean(final Array in, final Array weights, int dim) { 42 | return new Array(afMeanWeighted(in.ref, weights.ref, dim)); 43 | } 44 | 45 | static public T mean(final Array in, Class type) throws Exception { 46 | DoubleComplex res = afMeanAll(in.ref); 47 | return castResult(res, type); 48 | } 49 | 50 | static public T mean(final Array in, final Array weights, Class type) throws Exception { 51 | DoubleComplex res = afMeanAllWeighted(in.ref, weights.ref); 52 | return castResult(res, type); 53 | } 54 | 55 | static public Array var(final Array in, boolean isBiased, int dim) { 56 | return new Array(afVar(in.ref, isBiased, dim)); 57 | } 58 | 59 | static public Array var(final Array in, final Array weights, int dim) { 60 | return new Array(afVarWeighted(in.ref, weights.ref, dim)); 61 | } 62 | 63 | static public T var(final Array in, boolean isBiased, Class type) throws Exception { 64 | DoubleComplex res = afVarAll(in.ref, isBiased); 65 | return castResult(res, type); 66 | } 67 | 68 | static public T var(final Array in, final Array weights, Class type) throws Exception { 69 | DoubleComplex res = afVarAllWeighted(in.ref, weights.ref); 70 | return castResult(res, type); 71 | } 72 | 73 | static public Array stdev(final Array in, int dim) { 74 | return new Array(afStdev(in.ref, dim)); 75 | } 76 | 77 | static public T stdev(final Array in, Class type) throws Exception { 78 | DoubleComplex res = afStdevAll(in.ref); 79 | return castResult(res, type); 80 | } 81 | 82 | static public Array median(final Array in, int dim) { 83 | return new Array(afMedian(in.ref, dim)); 84 | } 85 | 86 | static public T median(final Array in, Class type) throws Exception { 87 | DoubleComplex res = afMedianAll(in.ref); 88 | return castResult(res, type); 89 | } 90 | 91 | static public Array cov(Array x, Array y, boolean isBiased) { 92 | return new Array(afCov(x.ref, y.ref, isBiased)); 93 | } 94 | 95 | static public T corrcoef(final Array x, final Array y, Class type) 96 | throws Exception { 97 | DoubleComplex res = afCorrcoef(x.ref, y.ref); 98 | return castResult(res, type); 99 | } 100 | 101 | static public Array[] topk(final Array in, int k, int dim, ArrayFire.TopkOrder order) throws Exception { 102 | long[] refs = afTopk(in.ref, k, dim, order.getOrder()); 103 | return new Array[] {new Array(refs[0]), new Array(refs[1])}; 104 | } 105 | 106 | static public T castResult(DoubleComplex res, Class type) throws Exception { 107 | Object ret; 108 | if (type == Float.class) { 109 | ret = Float.valueOf((float) res.real()); 110 | } else if (type == Double.class) { 111 | ret = Double.valueOf((double) res.real()); 112 | } else if (type == Integer.class) { 113 | ret = Integer.valueOf((int) res.real()); 114 | } else if (type == FloatComplex.class) { 115 | ret = new FloatComplex((float) res.real(), (float) res.imag()); 116 | } else if (type == DoubleComplex.class) { 117 | ret = res; 118 | } else { 119 | throw new Exception("Unknown type"); 120 | } 121 | 122 | return type.cast(ret); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /com/arrayfire/Util.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | class Util extends ArrayFire { 4 | 5 | public native static void info(); 6 | 7 | public static String toString(Array a, String delim) { 8 | String ret_txt = ""; 9 | try { 10 | float[] fary = Data.getFloatArray(a); 11 | for (int k = 0; k < fary.length - 1; ++k) { 12 | String temp = Float.toString(fary[k]) + delim; 13 | ret_txt += temp; 14 | } 15 | ret_txt += Float.toString(fary[fary.length - 1]); 16 | } catch (Exception e) { 17 | ret_txt = "Failed to convert to string"; 18 | } 19 | return ret_txt; 20 | } 21 | 22 | public static float[] toFloatArray(String text, String delim) { 23 | String[] list = text.split(delim); 24 | float[] ret_ary = new float[list.length]; 25 | for (int k = 0; k < list.length; ++k) { 26 | ret_ary[k] = Float.parseFloat(list[k]); 27 | } 28 | return ret_ary; 29 | } 30 | 31 | public static int signbit(double x) { 32 | return x < 0 ? -1 : 0; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /com/arrayfire/Window.java: -------------------------------------------------------------------------------- 1 | package com.arrayfire; 2 | 3 | import static com.arrayfire.ArrayFire.*; 4 | 5 | public class Window implements AutoCloseable { 6 | 7 | 8 | protected long ref; 9 | private int r; 10 | private int c; 11 | private ColorMap cmap; 12 | 13 | public Window() throws Exception { 14 | ref = 0; 15 | r = c = -1; 16 | cmap = ColorMap.DEFAULT; 17 | initWindow(1280, 720, "ArrayFire"); 18 | } 19 | 20 | public Window(String title) throws Exception { 21 | ref = 0; 22 | r = c = -1; 23 | cmap = ColorMap.DEFAULT; 24 | initWindow(1280, 720, title); 25 | } 26 | 27 | public Window(int width, int height, String title) throws Exception { 28 | ref = 0; 29 | r = c = -1; 30 | cmap = ColorMap.DEFAULT; 31 | initWindow(width, height, title); 32 | } 33 | 34 | public Window(int width, int height) throws Exception { 35 | ref = 0; 36 | r = c = -1; 37 | cmap = ColorMap.DEFAULT; 38 | initWindow(width, height, "ArrayFire"); 39 | } 40 | 41 | public Window(long ref) throws Exception { 42 | this.ref = ref; 43 | r = c = -1; 44 | cmap = ColorMap.DEFAULT; 45 | } 46 | 47 | private void initWindow(int width, int height, String title) throws Exception { 48 | ref = Graphics.afInitWindow(width, height, title); 49 | } 50 | 51 | protected void set(long ref) { 52 | if (this.ref != 0) { 53 | Graphics.afDestroyWindow(this.ref); 54 | } 55 | this.ref = ref; 56 | } 57 | 58 | public void setPos(int x, int y) { 59 | Graphics.afSetPos(ref, x, y); 60 | } 61 | 62 | public void setTitle(String title) { 63 | Graphics.afSetTitle(ref, title); 64 | } 65 | 66 | public void setSize(int w, int h) { 67 | Graphics.afSetSize(ref, w, h); 68 | } 69 | 70 | public void setColorMap(ColorMap cmap) { 71 | this.cmap = cmap; 72 | } 73 | 74 | public void image(final Array in, String title) { 75 | Graphics.afDrawImage(ref, in.ref, r, c, title, cmap.getMap()); 76 | } 77 | 78 | public void plot(final Array in, String title) { 79 | Graphics.afDrawPlotnd(ref, in.ref, r, c, title); 80 | } 81 | 82 | public void plot(final Array x, final Array y, String title) { 83 | Graphics.afDrawPlot2d(ref, x.ref, y.ref, r, c, title); 84 | } 85 | 86 | public void plot(final Array x, final Array y, final Array z, String title) { 87 | Graphics.afDrawPlot3d(ref, x.ref, y.ref, z.ref, r, c, title); 88 | } 89 | 90 | public void scatter(final Array in, MarkerType type, String title) { 91 | Graphics.afDrawScatternd(ref, in.ref, r, c, type.getType(), title); 92 | } 93 | 94 | public void scatter(final Array x, final Array y, MarkerType type, String title) { 95 | Graphics.afDrawScatter2d(ref, x.ref, y.ref, c, r, type.getType(), title); 96 | } 97 | 98 | public void scatter(final Array x, final Array y, final Array z, MarkerType type, String title) { 99 | Graphics.afDrawScatter3d(ref, x.ref, y.ref, z.ref, c, r, type.getType(), title); 100 | } 101 | 102 | public void hist(final Array in, double min, double max, String title) { 103 | Graphics.afDrawHist(ref, in.ref, r, c, min, max, title); 104 | } 105 | 106 | public void surface(final Array xVals, final Array yVals, final Array s, String title) { 107 | Graphics.afDrawSurface(ref, s.ref, xVals.ref, yVals.ref, r, c, title); 108 | } 109 | 110 | public void vectorField(final Array points, final Array directions, String title) { 111 | Graphics.afDrawVectorFieldnd(ref, points.ref, directions.ref, r, c, title); 112 | } 113 | 114 | public void vectorField(final Array xPoints, final Array yPoints, final Array xDirections, 115 | final Array yDirections, String title) { 116 | Graphics.afDrawVectorField2d(ref, xPoints.ref, yPoints.ref, xDirections.ref, yDirections.ref, r, 117 | c, title); 118 | } 119 | 120 | public void vectorField(final Array xPoints, final Array yPoints, final Array zPoints, 121 | final Array xDirections, final Array yDirections, final Array zDirections, String title) { 122 | Graphics.afDrawVectorField3d(ref, xPoints.ref, yPoints.ref, zPoints.ref, xDirections.ref, 123 | yDirections.ref, zDirections.ref, r, c, title); 124 | } 125 | 126 | public void grid(int rows, int cols) { 127 | Graphics.afGrid(ref, rows, cols); 128 | } 129 | 130 | public void setAxesLimits(final Array x, final Array y, boolean isExact) { 131 | Graphics.afSetAxesLimitsCompute(ref, x.ref, y.ref, 0, isExact, r, c); 132 | } 133 | 134 | public void setAxesLimits(final Array x, final Array y, final Array z, boolean isExact) { 135 | Graphics.afSetAxesLimitsCompute(ref, x.ref, y.ref, z.ref, isExact, r, c); 136 | } 137 | 138 | public void setAxesLimits(float xMin, float xMax, float yMin, float yMax, boolean isExact) { 139 | Graphics.afSetAxesLimits2d(ref, xMin, xMax, yMin, yMax, isExact, r, c); 140 | } 141 | 142 | public void setAxesLimits(float xMin, float xMax, float yMin, float yMax, float zMin, float zMax, 143 | boolean isExact) { 144 | Graphics.afSetAxesLimits3d(ref, xMin, xMax, yMin, yMax, zMin, zMax, isExact, r, c); 145 | } 146 | 147 | public void setAxesTitles(String xTitle, String yTitle, String zTitle) { 148 | Graphics.afSetAxesTitles(xTitle, yTitle, zTitle); 149 | } 150 | 151 | public void show() { 152 | Graphics.afShow(ref); 153 | r = c = -1; 154 | } 155 | 156 | public boolean closeWindow() { 157 | return Graphics.afClose(ref); 158 | } 159 | 160 | public void setVisibility(boolean isVisible) { 161 | Graphics.afSetVisibility(ref, isVisible); 162 | } 163 | 164 | @Override 165 | public void close() throws Exception { 166 | if (ref != 0) { 167 | Graphics.afDestroyWindow(ref); 168 | } 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | *.jar 2 | *.class 3 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | find_package(Java REQUIRED) 4 | include(UseJava) 5 | 6 | if(WIN32) 7 | SET(JAVA_INCLUDE_FLAG_SEP ";") 8 | else(WIN32) 9 | SET(JAVA_INCLUDE_FLAG_SEP ":") 10 | endif(WIN32) 11 | 12 | macro(BUILD_EXAMPLE src) 13 | # get arrayfire jar file 14 | get_target_property(_afJar ${AF_JAR} JAR_FILE) 15 | # extract file name from source file 16 | get_filename_component(EXAMPLE ${src} NAME_WE) 17 | # add jar file for given source file 18 | add_jar(${EXAMPLE} SOURCES ${src} INCLUDE_JARS ${_afJar}) 19 | # udpate the jar file with program entry point 20 | get_target_property(_jarFile ${EXAMPLE} JAR_FILE) 21 | add_custom_command(TARGET ${EXAMPLE} COMMAND ${Java_JAR_EXECUTABLE} ufe ${_jarFile} ${EXAMPLE}) 22 | # install examples jar 23 | install_jar(${EXAMPLE} examples) 24 | # add target for running examples 25 | add_custom_target(ex${EXAMPLE} ${Java_JAVA_EXECUTABLE} 26 | -Djava.library.path="${PROJECT_BINARY_DIR}/src" 27 | -cp ".${JAVA_INCLUDE_FLAG_SEP}${_afJar}${JAVA_INCLUDE_FLAG_SEP}${_jarFile}" ${EXAMPLE}) 28 | endmacro() 29 | 30 | build_example(HelloWorld.java) 31 | build_example(WindowEx.java) 32 | build_example(MonteCarloPi.java) 33 | -------------------------------------------------------------------------------- /examples/HelloWorld.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; 2 | import com.arrayfire.*; 3 | import static com.arrayfire.ArrayFire.*; 4 | 5 | public class HelloWorld { 6 | 7 | public static void main(String[] args) { 8 | 9 | Array a = new Array(), b = new Array(), c = new Array(), d = new Array(); 10 | Array f = new Array(); 11 | try { 12 | info(); 13 | 14 | System.out.println("Create a 5-by-3 matrix of random floats on the GPU"); 15 | randu(a, new int[] { 5, 3 }, Type.Float); 16 | System.out.println(a.toString("a")); 17 | 18 | System.out.println("Element-wise arithmetic"); 19 | sin(b, a); 20 | System.out.println(b.toString("b")); 21 | 22 | System.out.println("Fourier transform the result"); 23 | fft(c, b); 24 | System.out.println(c.toString("c")); 25 | 26 | System.out.println("Matmul b and c"); 27 | mul(d, b, c); 28 | System.out.println(d.toString("d")); 29 | 30 | System.out.println("Calculate weighted variance."); 31 | Array forVar = new Array(); 32 | Array weights = new Array(); 33 | randn(forVar, new int[] { 5, 5 }, Type.Double); 34 | randn(weights, new int[] { 5, 5 }, Type.Double); 35 | System.out.println(forVar.toString("forVar")); 36 | 37 | double abc = var(forVar, weights, Double.class); 38 | System.out.println(String.format("Variance is: %f", abc)); 39 | forVar.close(); 40 | weights.close(); 41 | 42 | System.out.println("Median"); 43 | Array forMedian = new Array(); 44 | randu(forMedian, new int[] { 3, 5 }, Type.Double); 45 | System.out.println(forMedian.toString("forMedian")); 46 | double median = median(forMedian, Double.class); 47 | System.out.printf("Median = %f\n", median); 48 | forMedian.close(); 49 | 50 | System.out.println("Calculate standard deviation"); 51 | Array forStdev = new Array(); 52 | randu(forStdev, new int[] { 5, 3 }, Type.Double); 53 | System.out.println(forStdev.toString("forStdev")); 54 | double stdev = stdev(forStdev, Double.class); 55 | System.out.println(String.format("Stdev is: %f", stdev)); 56 | forStdev.close(); 57 | 58 | System.out.println("Covariance"); 59 | Array x = new Array(); 60 | Array z = new Array(); 61 | randu(x, new int[] { 5, 3 }, Type.Double); 62 | randu(z, new int[] { 5, 3 }, Type.Double); 63 | System.out.println(x.toString("x")); 64 | System.out.println(z.toString("z")); 65 | Array cov = cov(x, z, false); 66 | System.out.println(cov.toString("cov")); 67 | 68 | System.out.println("Correlation coefficient of the 2 previous arrays"); 69 | double corrcoef = corrcoef(x, z, Double.class); 70 | System.out.printf("Corrcoef = %f\n", corrcoef); 71 | x.close(); 72 | z.close(); 73 | 74 | System.out.println("Topk"); 75 | Array forTopk = new Array(); 76 | randu(forTopk, new int[] { 3, 3 }, Type.Double); 77 | System.out.println(forTopk.toString("forTopk")); 78 | Array[] results = topk(forTopk, 3, 0, TopkOrder.DEFAULT); 79 | System.out.println(results[0].toString("Indicies")); 80 | System.out.println(results[1].toString("Values")); 81 | 82 | System.out.println("Create a 2-by-3 matrix from host data"); 83 | int[] dims = new int[] { 2, 3 }; 84 | int total = 1; 85 | for (int dim : dims) { 86 | total *= dim; 87 | } 88 | 89 | float[] data = new float[total]; 90 | Random rand = new Random(); 91 | 92 | for (int i = 0; i < total; i++) { 93 | double tmp = Math.ceil(rand.nextDouble() * 10) / 10; 94 | data[i] = (float) (tmp); 95 | } 96 | Array e = new Array(dims, data); 97 | System.out.println(e.toString("e")); 98 | 99 | System.out.println("Add e and random array"); 100 | Array randa = new Array(); 101 | randu(randa, dims, Type.Float); 102 | add(f, e, randa); 103 | System.out.println(f.toString("f")); 104 | 105 | System.out.println("Copy result back to host."); 106 | float[] result = f.getFloatArray(); 107 | for (int i = 0; i < dims[0]; i++) { 108 | for (int y = 0; y < dims[1]; y++) { 109 | System.out.print(result[y * dims[0] + i] + " "); 110 | } 111 | System.out.println(); 112 | } 113 | a.close(); 114 | b.close(); 115 | c.close(); 116 | d.close(); 117 | e.close(); 118 | f.close(); 119 | 120 | } catch (Exception ex) { 121 | ex.printStackTrace(); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | LIB:=lib 2 | 3 | AF_JAVA_PATH?=../ 4 | AF_JAVA_JAR?=$(AF_JAVA_PATH)/ArrayFire.jar 5 | AF_JAVA_LIB_PATH?=$(AF_JAVA_PATH)/$(LIB) 6 | 7 | CLASSES=$(patsubst %.java, %.class, $(shell ls *.java)) 8 | BINS=$(patsubst %.class, %, $(CLASSES)) 9 | 10 | all: $(CLASSES) 11 | 12 | run: $(BINS) 13 | 14 | %: %.class 15 | LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):$(AF_JAVA_LIB_PATH) java -cp .:$(AF_JAVA_JAR) $@ 16 | 17 | %.class: %.java 18 | javac -cp $(AF_JAVA_PATH)/ArrayFire.jar $< 19 | -------------------------------------------------------------------------------- /examples/MonteCarloPi.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; 2 | import com.arrayfire.*; 3 | import static com.arrayfire.ArrayFire.*; 4 | 5 | public class MonteCarloPi { 6 | 7 | public static double hostCalcPi(int size) { 8 | Random rand = new Random(); 9 | int count = 0; 10 | for (int i = 0; i < size; i++) { 11 | float x = rand.nextFloat(); 12 | float y = rand.nextFloat(); 13 | boolean lt1 = (x * x + y * y) < 1; 14 | if (lt1) 15 | count++; 16 | } 17 | 18 | return 4.0 * ((double) (count)) / size; 19 | } 20 | 21 | public static double deviceCalcPi(int size) throws Exception { 22 | Array x = new Array(), y = new Array(), res = new Array(); 23 | try { 24 | 25 | int[] dims = new int[] { size, 1 }; 26 | randu(x, dims, Type.Float); 27 | randu(y, dims, Type.Float); 28 | 29 | mul(x, x, x); 30 | mul(y, y, y); 31 | 32 | add(res, x, y); 33 | lt(res, res, 1); 34 | 35 | double count = sumAll(res); 36 | return 4.0 * ((double) (count)) / size; 37 | 38 | } catch (Exception e) { 39 | throw e; 40 | } finally { 41 | x.close(); 42 | y.close(); 43 | res.close(); 44 | } 45 | } 46 | 47 | public static void main(String[] args) { 48 | 49 | try { 50 | int size = 5000000; 51 | int iter = 100; 52 | 53 | double devicePi = deviceCalcPi(size); 54 | System.out.println("Results from device: " + devicePi); 55 | 56 | double hostPi = hostCalcPi(size); 57 | System.out.println("Results from host: " + hostPi); 58 | 59 | long deviceStart = System.currentTimeMillis(); 60 | for (int i = 0; i < iter; i++) { 61 | devicePi = deviceCalcPi(size); 62 | } 63 | double deviceElapsed = (double) (System.currentTimeMillis() - deviceStart) / iter; 64 | System.out.println("Time taken for device (ms): " + deviceElapsed); 65 | 66 | long hostStart = System.currentTimeMillis(); 67 | for (int i = 0; i < iter; i++) { 68 | hostPi = hostCalcPi(size); 69 | } 70 | double hostElapsed = (double) (System.currentTimeMillis() - hostStart) / iter; 71 | System.out.println("Time taken for host (ms): " + hostElapsed); 72 | 73 | System.out.println("Speedup: " + Math.round((hostElapsed) / (deviceElapsed))); 74 | 75 | } catch (Exception e) { 76 | e.printStackTrace(); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /examples/WindowEx.java: -------------------------------------------------------------------------------- 1 | import static com.arrayfire.ArrayFire.*; 2 | import com.arrayfire.*; 3 | 4 | public class WindowEx { 5 | public static void main(String[] args) { 6 | System.out.println("Creating window"); 7 | try { 8 | Array img = new Array(); 9 | randu(img, new int[] { 200, 200 }, Type.Int); 10 | Window window = new Window(); 11 | while (!window.closeWindow()) { 12 | window.image(img, "Image"); 13 | window.show(); 14 | } 15 | window.close(); 16 | } catch (Exception ex) { 17 | ex.printStackTrace(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /java-google-style.xml: -------------------------------------------------------------------------------- 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 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ENABLE_LANGUAGE(CXX) 2 | 3 | FIND_PACKAGE(JNI REQUIRED) 4 | FIND_PACKAGE(ArrayFire QUIET) 5 | 6 | IF(NOT ArrayFire_FOUND) 7 | MESSAGE(FATAL_ERROR "Please point environment variable ArrayFire_DIR to ArrayFire installation 8 | directory") 9 | ENDIF() 10 | 11 | INCLUDE_DIRECTORIES(${JNI_INCLUDE_DIRS} ${ArrayFire_INCLUDE_DIRS}) 12 | 13 | ADD_LIBRARY(${AF_LIB} SHARED 14 | java/java.h 15 | java/java.cpp 16 | jni_helper.h 17 | algorithm.cpp 18 | arith.cpp 19 | array.cpp 20 | data.cpp 21 | image.cpp 22 | signal.cpp 23 | statistics.cpp 24 | graphics.cpp 25 | index.cpp 26 | util.cpp 27 | ) 28 | 29 | TARGET_LINK_LIBRARIES(${AF_LIB} ${JNI_LIBRARIES} ArrayFire::afopencl) 30 | 31 | IF(${UNIX}) 32 | SET(CMAKE_CXX_FLAGS "-fPIC") 33 | SET_TARGET_PROPERTIES(${AF_LIB} PROPERTIES CMAKE_SHARED_LINKER_FLAGS "-fPIC") 34 | ELSEIF(${WINDOWS}) 35 | SET(CMAKE_CXX_FLAGS "/MP /EHsc") 36 | ENDIF(${UNIX}) 37 | 38 | INSTALL(TARGETS ${AF_LIB} DESTINATION lib) 39 | -------------------------------------------------------------------------------- /src/algorithm.cpp: -------------------------------------------------------------------------------- 1 | #include "jni_helper.h" 2 | 3 | BEGIN_EXTERN_C 4 | 5 | #define ALGO_FUNC(FUNC) AF_MANGLE(Algorithm, FUNC) 6 | 7 | #define SCALAR_RET_OP_DEF(func) \ 8 | JNIEXPORT jdouble JNICALL ALGO_FUNC(func##All)(JNIEnv * env, jclass clazz, \ 9 | jlong a) { \ 10 | double real, imag; \ 11 | AF_CHECK(af_##func##_all(&real, &imag, ARRAY(a))); \ 12 | return real; \ 13 | } 14 | 15 | SCALAR_RET_OP_DEF(sum) 16 | SCALAR_RET_OP_DEF(max) 17 | SCALAR_RET_OP_DEF(min) 18 | 19 | #define ARRAY_RET_OP_DEF(func) \ 20 | JNIEXPORT jlong JNICALL ALGO_FUNC(func)(JNIEnv * env, jclass clazz, jlong a, \ 21 | jint dim) { \ 22 | af_array ret = 0; \ 23 | AF_CHECK(af_##func(&ret, ARRAY(a), dim)); \ 24 | return JLONG(ret); \ 25 | } 26 | 27 | ARRAY_RET_OP_DEF(sum) 28 | ARRAY_RET_OP_DEF(max) 29 | ARRAY_RET_OP_DEF(min) 30 | 31 | JNIEXPORT jlong JNICALL ALGO_FUNC(afWhere)(JNIEnv *env, jclass clazz, jlong arr) { 32 | af_array ret = 0; 33 | AF_CHECK(af_where(&ret, ARRAY(arr))); 34 | return JLONG(ret); 35 | } 36 | 37 | END_EXTERN_C 38 | -------------------------------------------------------------------------------- /src/arith.cpp: -------------------------------------------------------------------------------- 1 | #include "jni_helper.h" 2 | 3 | BEGIN_EXTERN_C 4 | 5 | #define ARITH_FUNC(FUNC) AF_MANGLE(Arith, FUNC) 6 | 7 | #define BINARY_OP_DEF(func) \ 8 | JNIEXPORT jlong JNICALL ARITH_FUNC(func)(JNIEnv * env, jclass clazz, \ 9 | jlong a, jlong b) { \ 10 | af_array ret = 0; \ 11 | AF_CHECK(af_##func(&ret, ARRAY(a), ARRAY(b), false)); \ 12 | return JLONG(ret); \ 13 | } \ 14 | \ 15 | JNIEXPORT jlong JNICALL ARITH_FUNC(func##f)(JNIEnv * env, jclass clazz, \ 16 | jlong a, jfloat b) { \ 17 | af_array ret = 0; \ 18 | af_array tmp = 0; \ 19 | dim_t dims[4]; \ 20 | af_dtype ty = f32; \ 21 | AF_CHECK(af_get_dims(dims + 0, dims + 1, dims + 2, dims + 3, ARRAY(a))); \ 22 | AF_CHECK(af_get_type(&ty, ARRAY(a))); \ 23 | AF_CHECK(af_constant(&tmp, b, 4, dims, ty)); \ 24 | AF_CHECK(af_##func(&ret, ARRAY(a), tmp, false)); \ 25 | AF_CHECK(af_release_array(tmp)); \ 26 | return JLONG(ret); \ 27 | } \ 28 | \ 29 | JNIEXPORT jlong JNICALL ARITH_FUNC(f##func)(JNIEnv * env, jclass clazz, \ 30 | float a, jlong b) { \ 31 | af_array ret = 0; \ 32 | af_array tmp = 0; \ 33 | dim_t dims[4]; \ 34 | af_dtype ty = f32; \ 35 | AF_CHECK(af_get_dims(dims + 0, dims + 1, dims + 2, dims + 3, ARRAY(b))); \ 36 | AF_CHECK(af_get_type(&ty, ARRAY(b))); \ 37 | AF_CHECK(af_constant(&tmp, a, 4, dims, ty)); \ 38 | AF_CHECK(af_##func(&ret, tmp, ARRAY(b), false)); \ 39 | AF_CHECK(af_release_array(tmp)); \ 40 | return JLONG(ret); \ 41 | } 42 | 43 | BINARY_OP_DEF(add) 44 | BINARY_OP_DEF(sub) 45 | BINARY_OP_DEF(mul) 46 | BINARY_OP_DEF(div) 47 | BINARY_OP_DEF(le) 48 | BINARY_OP_DEF(lt) 49 | BINARY_OP_DEF(ge) 50 | BINARY_OP_DEF(gt) 51 | BINARY_OP_DEF(eq) 52 | BINARY_OP_DEF(neq) 53 | BINARY_OP_DEF(pow) 54 | 55 | #define UNARY_OP_DEF(func) \ 56 | JNIEXPORT jlong JNICALL ARITH_FUNC(func)(JNIEnv * env, jclass clazz, \ 57 | jlong a) { \ 58 | af_array ret = 0; \ 59 | AF_CHECK(af_##func(&ret, ARRAY(a))); \ 60 | return JLONG(ret); \ 61 | } 62 | 63 | UNARY_OP_DEF(sin) 64 | UNARY_OP_DEF(cos) 65 | UNARY_OP_DEF(tan) 66 | UNARY_OP_DEF(asin) 67 | UNARY_OP_DEF(acos) 68 | UNARY_OP_DEF(atan) 69 | UNARY_OP_DEF(sinh) 70 | UNARY_OP_DEF(cosh) 71 | UNARY_OP_DEF(tanh) 72 | UNARY_OP_DEF(asinh) 73 | UNARY_OP_DEF(acosh) 74 | UNARY_OP_DEF(atanh) 75 | UNARY_OP_DEF(exp) 76 | UNARY_OP_DEF(log) 77 | UNARY_OP_DEF(abs) 78 | UNARY_OP_DEF(sqrt) 79 | 80 | END_EXTERN_C 81 | -------------------------------------------------------------------------------- /src/array.cpp: -------------------------------------------------------------------------------- 1 | #include "jni_helper.h" 2 | 3 | BEGIN_EXTERN_C 4 | 5 | #define ARRAY_FUNC(FUNC) AF_MANGLE(Array, FUNC) 6 | 7 | JNIEXPORT void JNICALL ARRAY_FUNC(destroyArray)(JNIEnv *env, jclass clazz, 8 | jlong ref) { 9 | AF_CHECK_VOID(af_release_array(ARRAY(ref))); 10 | } 11 | 12 | JNIEXPORT jstring JNICALL ARRAY_FUNC(afToString)(JNIEnv *env, jclass clazz, jlong ref, 13 | jstring name) { 14 | char *res; 15 | const char *str = env->GetStringUTFChars(name, 0); 16 | af_array_to_string(&res, str, ARRAY(ref), 4, false); 17 | env->ReleaseStringUTFChars(name, str); 18 | return env->NewStringUTF(res); 19 | } 20 | 21 | JNIEXPORT jintArray JNICALL ARRAY_FUNC(getDims)(JNIEnv *env, jclass clazz, 22 | jlong ref) { 23 | jintArray result = env->NewIntArray(MaxDimSupported); 24 | if (result == NULL) { 25 | return NULL; 26 | } 27 | 28 | dim_t dims[4]; 29 | AF_CHECK(af_get_dims(dims + 0, dims + 1, dims + 2, dims + 3, ARRAY(ref))); 30 | 31 | jint *dimsf = env->GetIntArrayElements(result, 0); 32 | 33 | for (int k = 0; k < MaxDimSupported; ++k) { 34 | dimsf[k] = dims[k]; 35 | } 36 | env->ReleaseIntArrayElements(result, dimsf, 0); 37 | 38 | return result; 39 | } 40 | 41 | JNIEXPORT jint JNICALL ARRAY_FUNC(getType)(JNIEnv *env, jclass clazz, 42 | jlong ref) { 43 | af_dtype ty = f32; 44 | AF_CHECK(af_get_type(&ty, ARRAY(ref))); 45 | return ty; 46 | } 47 | 48 | JNIEXPORT jlong JNICALL ARRAY_FUNC(createEmptyArray)(JNIEnv *env, jclass clazz, 49 | jintArray dims, jint type) { 50 | af_array ret = 0; 51 | jint *dimptr = env->GetIntArrayElements(dims, 0); 52 | dim_t tdims[4] = {dimptr[0], dimptr[1], dimptr[2], dimptr[3]}; 53 | env->ReleaseIntArrayElements(dims, dimptr, 0); 54 | AF_CHECK(af_create_handle(&ret, 4, tdims, (af_dtype)(type))); 55 | return JLONG(ret); 56 | } 57 | 58 | #define CREATE_DATA_T(Ty, ty, dty) \ 59 | JNIEXPORT jlong JNICALL ARRAY_FUNC(createArrayFrom##Ty)( \ 60 | JNIEnv * env, jclass clazz, jintArray dims, j##ty##Array elems) { \ 61 | af_array ret = 0; \ 62 | jint *dimptr = env->GetIntArrayElements(dims, 0); \ 63 | dim_t tdims[4] = {dimptr[0], dimptr[1], dimptr[2], dimptr[3]}; \ 64 | void *inptr = (void *)env->Get##Ty##ArrayElements(elems, 0); \ 65 | AF_CHECK(af_create_array(&ret, inptr, 4, tdims, dty)); \ 66 | env->ReleaseIntArrayElements(dims, dimptr, 0); \ 67 | env->Release##Ty##ArrayElements(elems, (j##ty *)inptr, 0); \ 68 | return JLONG(ret); \ 69 | } 70 | 71 | CREATE_DATA_T(Float, float, f32); 72 | CREATE_DATA_T(Double, double, f64); 73 | CREATE_DATA_T(Int, int, s32); 74 | CREATE_DATA_T(Boolean, boolean, b8); 75 | 76 | #undef CREATE_DATA_T 77 | 78 | JNIEXPORT jlong JNICALL ARRAY_FUNC(createArrayFromFloatComplex)( 79 | JNIEnv *env, jclass clazz, jintArray dims, jobjectArray objs) { 80 | af_array ret = 0; 81 | jint *dimptr = env->GetIntArrayElements(dims, 0); 82 | jint len = env->GetArrayLength(objs); 83 | 84 | static jclass cls; 85 | static jfieldID re, im; 86 | static bool isfirst = true; 87 | 88 | if (isfirst) { 89 | cls = env->FindClass("com/arrayfire/FloatComplex"); 90 | re = env->GetFieldID(cls, "real", "F"); 91 | im = env->GetFieldID(cls, "imag", "F"); 92 | isfirst = false; 93 | } 94 | 95 | af_cfloat *tmp = (af_cfloat *)malloc(len * sizeof(af_cfloat)); 96 | 97 | for (int i = 0; i < len; i++) { 98 | jobject obj = env->GetObjectArrayElement(objs, i); 99 | jfloat real = env->GetFloatField(obj, re); 100 | jfloat imag = env->GetFloatField(obj, im); 101 | 102 | tmp[i].real = real; 103 | tmp[i].imag = imag; 104 | } 105 | 106 | dim_t tdims[4] = {dimptr[0], dimptr[1], dimptr[2], dimptr[3]}; 107 | 108 | AF_CHECK(af_create_array(&ret, (void *)tmp, 4, tdims, c32)); 109 | 110 | free(tmp); 111 | env->ReleaseIntArrayElements(dims, dimptr, 0); 112 | return JLONG(ret); 113 | } 114 | 115 | JNIEXPORT jlong JNICALL ARRAY_FUNC(createArrayFromDoubleComplex)( 116 | JNIEnv *env, jclass clazz, jintArray dims, jobjectArray objs) { 117 | af_array ret = 0; 118 | jint *dimptr = env->GetIntArrayElements(dims, 0); 119 | jint len = env->GetArrayLength(objs); 120 | 121 | static jclass cls; 122 | static jfieldID re, im; 123 | static bool isfirst = true; 124 | 125 | if (isfirst) { 126 | cls = env->FindClass("com/arrayfire/DoubleComplex"); 127 | re = env->GetFieldID(cls, "real", "D"); 128 | im = env->GetFieldID(cls, "imag", "D"); 129 | isfirst = false; 130 | } 131 | 132 | af_cdouble *tmp = (af_cdouble *)malloc(len * sizeof(af_cdouble)); 133 | 134 | for (int i = 0; i < len; i++) { 135 | jobject obj = env->GetObjectArrayElement(objs, i); 136 | jdouble real = env->GetDoubleField(obj, re); 137 | jdouble imag = env->GetDoubleField(obj, im); 138 | 139 | tmp[i].real = real; 140 | tmp[i].imag = imag; 141 | } 142 | 143 | dim_t tdims[4] = {dimptr[0], dimptr[1], dimptr[2], dimptr[3]}; 144 | 145 | AF_CHECK(af_create_array(&ret, (void *)tmp, 4, tdims, c64)); 146 | 147 | free(tmp); 148 | env->ReleaseIntArrayElements(dims, dimptr, 0); 149 | return JLONG(ret); 150 | } 151 | 152 | END_EXTERN_C 153 | -------------------------------------------------------------------------------- /src/data.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "jni_helper.h" 3 | 4 | BEGIN_EXTERN_C 5 | 6 | #define DATA_FUNC(FUNC) AF_MANGLE(Data, FUNC) 7 | 8 | using af::cdouble; 9 | using af::cfloat; 10 | 11 | JNIEXPORT jlong JNICALL DATA_FUNC(createRanduArray)(JNIEnv *env, jclass clazz, 12 | jintArray dims, jint type) { 13 | af_array ret = 0; 14 | jint *dimptr = env->GetIntArrayElements(dims, 0); 15 | dim_t tdims[4] = {dimptr[0], dimptr[1], dimptr[2], dimptr[3]}; 16 | env->ReleaseIntArrayElements(dims, dimptr, 0); 17 | AF_CHECK(af_randu(&ret, 4, tdims, (af_dtype)(type))); 18 | return JLONG(ret); 19 | } 20 | 21 | JNIEXPORT jlong JNICALL DATA_FUNC(createRandnArray)(JNIEnv *env, jclass clazz, 22 | jintArray dims, jint type) { 23 | af_array ret = 0; 24 | jint *dimptr = env->GetIntArrayElements(dims, 0); 25 | dim_t tdims[4] = {dimptr[0], dimptr[1], dimptr[2], dimptr[3]}; 26 | env->ReleaseIntArrayElements(dims, dimptr, 0); 27 | AF_CHECK(af_randn(&ret, 4, tdims, (af_dtype)(type))); 28 | return JLONG(ret); 29 | } 30 | 31 | JNIEXPORT jlong JNICALL DATA_FUNC(afRange)(JNIEnv *env, jclass clazz, 32 | jintArray dims, jint seqDim, 33 | jint type) { 34 | af_array ret = 0; 35 | jint *dimptr = env->GetIntArrayElements(dims, 0); 36 | dim_t tdims[4] = {dimptr[0], dimptr[1], dimptr[2], dimptr[3]}; 37 | AF_CHECK(af_range(&ret, 4, tdims, seqDim, (af_dtype)type)); 38 | env->ReleaseIntArrayElements(dims, dimptr, 0); 39 | } 40 | 41 | JNIEXPORT jlong JNICALL DATA_FUNC(createConstantsArray)( 42 | JNIEnv *env, jclass clazz, jdouble val, jintArray dims, jint type) { 43 | af_array ret = 0; 44 | jint *dimptr = env->GetIntArrayElements(dims, 0); 45 | dim_t tdims[4] = {dimptr[0], dimptr[1], dimptr[2], dimptr[3]}; 46 | env->ReleaseIntArrayElements(dims, dimptr, 0); 47 | AF_CHECK(af_constant(&ret, val, 4, tdims, (af_dtype)(type))); 48 | return JLONG(ret); 49 | } 50 | 51 | JNIEXPORT jlong JNICALL DATA_FUNC(createIdentityArray)(JNIEnv *env, 52 | jclass clazz, 53 | jintArray dims, 54 | jint type) { 55 | af_array ret = 0; 56 | jint *dimptr = env->GetIntArrayElements(dims, 0); 57 | dim_t tdims[4] = {dimptr[0], dimptr[1], dimptr[2], dimptr[3]}; 58 | env->ReleaseIntArrayElements(dims, dimptr, 0); 59 | AF_CHECK(af_identity(&ret, 4, tdims, (af_dtype)(type))); 60 | return JLONG(ret); 61 | } 62 | 63 | #define GET_T_FROM_ARRAY(Ty, ty) \ 64 | JNIEXPORT j##ty##Array JNICALL DATA_FUNC(get##Ty##FromArray)( \ 65 | JNIEnv * env, jclass clazz, jlong ref) { \ 66 | j##ty##Array result; \ 67 | dim_t elements = 0; \ 68 | AF_CHECK(af_get_elements(&elements, ARRAY(ref))); \ 69 | result = env->New##Ty##Array(elements); \ 70 | if (result == NULL) { \ 71 | LOG("Something terrible happened. " \ 72 | "Couldn't allocate heap space!!!!"); \ 73 | return NULL; \ 74 | } \ 75 | j##ty *resf = env->Get##Ty##ArrayElements(result, 0); \ 76 | AF_CHECK(af_get_data_ptr((void *)resf, ARRAY(ref))); \ 77 | env->Release##Ty##ArrayElements(result, resf, 0); \ 78 | return result; \ 79 | } 80 | 81 | GET_T_FROM_ARRAY(Float, float); 82 | GET_T_FROM_ARRAY(Double, double); 83 | GET_T_FROM_ARRAY(Int, int); 84 | GET_T_FROM_ARRAY(Boolean, boolean); 85 | 86 | JNIEXPORT jobjectArray JNICALL DATA_FUNC(getFloatComplexFromArray)(JNIEnv *env, 87 | jclass clazz, 88 | jlong ref) { 89 | jobjectArray result; 90 | dim_t elements = 0; 91 | AF_CHECK(af_get_elements(&elements, ARRAY(ref))); 92 | 93 | jclass cls = env->FindClass("com/arrayfire/FloatComplex"); 94 | result = env->NewObjectArray(elements, cls, NULL); 95 | 96 | af_cfloat *tmp = (af_cfloat *)malloc(sizeof(af_cfloat) * elements); 97 | AF_CHECK(af_get_data_ptr((void *)tmp, ARRAY(ref))); 98 | 99 | for (int i = 0; i < elements; i++) { 100 | float re = tmp[i].real; 101 | float im = tmp[i].imag; 102 | jobject obj = java::createJavaObject(env, java::JavaObjects::FloatComplex, re, im); 103 | env->SetObjectArrayElement(result, i, obj); 104 | } 105 | 106 | free(tmp); 107 | return result; 108 | } 109 | 110 | JNIEXPORT jobjectArray JNICALL 111 | DATA_FUNC(getDoubleComplexFromArray)(JNIEnv *env, jclass clazz, jlong ref) { 112 | jobjectArray result; 113 | dim_t elements = 0; 114 | AF_CHECK(af_get_elements(&elements, ARRAY(ref))); 115 | 116 | jclass cls = env->FindClass("com/arrayfire/DoubleComplex"); 117 | result = env->NewObjectArray(elements, cls, NULL); 118 | 119 | af_cdouble *tmp = (af_cdouble *)malloc(sizeof(af_cdouble) * elements); 120 | AF_CHECK(af_get_data_ptr((void *)tmp, ARRAY(ref))); 121 | 122 | for (int i = 0; i < elements; i++) { 123 | double re = tmp[i].real; 124 | double im = tmp[i].imag; 125 | jobject obj = 126 | java::createJavaObject(env, java::JavaObjects::DoubleComplex, re, im); 127 | env->SetObjectArrayElement(result, i, obj); 128 | } 129 | 130 | free(tmp); 131 | return result; 132 | } 133 | 134 | END_EXTERN_C 135 | -------------------------------------------------------------------------------- /src/graphics.cpp: -------------------------------------------------------------------------------- 1 | #include "jni_helper.h" 2 | 3 | BEGIN_EXTERN_C 4 | 5 | #define GRAPHICS_FUNC(FUNC) AF_MANGLE(Graphics, FUNC) 6 | #define WND(ref) (void *)ref 7 | 8 | JNIEXPORT jlong JNICALL GRAPHICS_FUNC(afInitWindow)(JNIEnv *env, jclass clazz, 9 | jint width, jint height, 10 | jstring name) { 11 | af_window wnd; 12 | const char *cName = env->GetStringUTFChars(name, 0); 13 | AF_CHECK(af_create_window(&wnd, width, height, cName)); 14 | env->ReleaseStringUTFChars(name, cName); 15 | return JLONG(wnd); 16 | } 17 | 18 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afDestroyWindow)(JNIEnv *env, jclass clazz, 19 | jlong wnd) { 20 | AF_CHECK_VOID(af_destroy_window(WND(wnd))); 21 | } 22 | 23 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetPos)(JNIEnv *env, jclass clazz, 24 | jlong wnd, jint x, jint y) { 25 | AF_CHECK_VOID(af_set_position(WND(wnd), x, y)); 26 | } 27 | 28 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetTitle)(JNIEnv *env, jclass clazz, 29 | jlong wnd, jstring title) { 30 | const char *cTitle = env->GetStringUTFChars(title, 0); 31 | AF_CHECK_VOID(af_set_title(WND(wnd), cTitle)); 32 | env->ReleaseStringUTFChars(title, cTitle); 33 | } 34 | 35 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetSize)(JNIEnv *env, jclass clazz, 36 | jlong wnd, jint w, jint h) { 37 | AF_CHECK_VOID(af_set_size(WND(wnd), w, h)); 38 | } 39 | 40 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawImage)(JNIEnv *env, jclass clazz, 41 | jlong wnd, jlong arr, jint r, 42 | jint c, jstring title, 43 | int cmap) { 44 | const char *cTitle = env->GetStringUTFChars(title, 0); 45 | af_cell props{r, c, cTitle, static_cast(cmap)}; 46 | AF_CHECK_VOID(af_draw_image(WND(wnd), ARRAY(arr), &props)); 47 | env->ReleaseStringUTFChars(title, cTitle); 48 | } 49 | 50 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawPlotnd)(JNIEnv *env, jclass clazz, 51 | jlong wnd, jlong arr, jint r, 52 | jint c, jstring title) { 53 | const char *cTitle = env->GetStringUTFChars(title, 0); 54 | af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT}; 55 | AF_CHECK_VOID(af_draw_plot_nd(WND(wnd), ARRAY(arr), &props)); 56 | env->ReleaseStringUTFChars(title, cTitle); 57 | } 58 | 59 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawPlot2d)(JNIEnv *env, jclass clazz, 60 | jlong wnd, jlong arrX, 61 | jlong arrY, jint r, jint c, 62 | jstring title) { 63 | const char *cTitle = env->GetStringUTFChars(title, 0); 64 | af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT}; 65 | AF_CHECK_VOID(af_draw_plot_2d(WND(wnd), ARRAY(arrX), ARRAY(arrY), &props)); 66 | env->ReleaseStringUTFChars(title, cTitle); 67 | } 68 | 69 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawPlot3d)(JNIEnv *env, jclass clazz, 70 | jlong wnd, jlong arrX, 71 | jlong arrY, jlong arrZ, 72 | jint r, jint c, 73 | jstring title) { 74 | const char *cTitle = env->GetStringUTFChars(title, 0); 75 | af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT}; 76 | AF_CHECK_VOID( 77 | af_draw_plot_3d(WND(wnd), ARRAY(arrX), ARRAY(arrY), ARRAY(arrZ), &props)); 78 | env->ReleaseStringUTFChars(title, cTitle); 79 | } 80 | 81 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawScatternd)(JNIEnv *env, jclass clazz, 82 | jlong wnd, jlong arr, 83 | jint r, jint c, 84 | jint markerType, 85 | jstring title) { 86 | const char *cTitle = env->GetStringUTFChars(title, 0); 87 | af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT}; 88 | AF_CHECK_VOID(af_draw_scatter_nd( 89 | WND(wnd), ARRAY(arr), static_cast(markerType), &props)); 90 | env->ReleaseStringUTFChars(title, cTitle); 91 | } 92 | 93 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawScatter2d)(JNIEnv *env, jclass clazz, 94 | jlong wnd, jlong arrX, 95 | jlong arrY, jint r, 96 | jint c, jint markerType, 97 | jstring title) { 98 | const char *cTitle = env->GetStringUTFChars(title, 0); 99 | af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT}; 100 | AF_CHECK_VOID(af_draw_scatter_2d(WND(wnd), ARRAY(arrX), ARRAY(arrY), 101 | static_cast(markerType), 102 | &props)); 103 | env->ReleaseStringUTFChars(title, cTitle); 104 | } 105 | 106 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawScatter3d)( 107 | JNIEnv *env, jclass clazz, jlong wnd, jlong arrX, jlong arrY, jlong arrZ, 108 | jint r, jint c, jint markerType, jstring title) { 109 | const char *cTitle = env->GetStringUTFChars(title, 0); 110 | af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT}; 111 | AF_CHECK_VOID( 112 | af_draw_scatter_3d(WND(wnd), ARRAY(arrX), ARRAY(arrY), ARRAY(arrZ), 113 | static_cast(markerType), &props)); 114 | env->ReleaseStringUTFChars(title, cTitle); 115 | } 116 | 117 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawHist)(JNIEnv *env, jclass clazz, 118 | jlong wnd, jlong arr, jint r, 119 | jint c, jdouble min, 120 | jdouble max, jstring title) { 121 | const char *cTitle = env->GetStringUTFChars(title, 0); 122 | af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT}; 123 | AF_CHECK_VOID(af_draw_hist(WND(wnd), ARRAY(arr), min, max, &props)); 124 | env->ReleaseStringUTFChars(title, cTitle); 125 | } 126 | 127 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawSurface)(JNIEnv *env, jclass clazz, 128 | jlong wnd, jlong arr, 129 | jlong xVals, jlong yVals, 130 | jint r, jint c, 131 | jstring title) { 132 | const char *cTitle = env->GetStringUTFChars(title, 0); 133 | af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT}; 134 | AF_CHECK_VOID(af_draw_surface(WND(wnd), ARRAY(xVals), ARRAY(yVals), 135 | ARRAY(arr), &props)); 136 | env->ReleaseStringUTFChars(title, cTitle); 137 | } 138 | 139 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawVectorFieldnd)( 140 | JNIEnv *env, jclass clazz, jlong wnd, jlong points, jlong directions, 141 | jint r, jint c, jstring title) { 142 | 143 | const char *cTitle = env->GetStringUTFChars(title, 0); 144 | af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT}; 145 | AF_CHECK_VOID(af_draw_vector_field_nd(WND(wnd), ARRAY(points), 146 | ARRAY(directions), &props)); 147 | env->ReleaseStringUTFChars(title, cTitle); 148 | } 149 | 150 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawVectorField2d)( 151 | JNIEnv *env, jclass clazz, jlong wnd, jlong xPoints, jlong yPoints, 152 | jlong xDirections, jlong yDirections, jint r, jint c, jstring title) { 153 | 154 | const char *cTitle = env->GetStringUTFChars(title, 0); 155 | af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT}; 156 | AF_CHECK_VOID(af_draw_vector_field_2d(WND(wnd), ARRAY(xPoints), 157 | ARRAY(yPoints), ARRAY(xDirections), 158 | ARRAY(yDirections), &props)); 159 | env->ReleaseStringUTFChars(title, cTitle); 160 | } 161 | 162 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afDrawVectorField3d)( 163 | JNIEnv *env, jclass clazz, jlong wnd, jlong xPoints, jlong yPoints, 164 | jlong zPoints, jlong xDirections, jlong yDirections, jlong zDirections, 165 | jint r, jint c, jstring title) { 166 | 167 | const char *cTitle = env->GetStringUTFChars(title, 0); 168 | af_cell props{r, c, cTitle, AF_COLORMAP_DEFAULT}; 169 | AF_CHECK_VOID(af_draw_vector_field_3d( 170 | WND(wnd), ARRAY(xPoints), ARRAY(yPoints), ARRAY(zPoints), 171 | ARRAY(xDirections), ARRAY(yDirections), ARRAY(zDirections), &props)); 172 | env->ReleaseStringUTFChars(title, cTitle); 173 | } 174 | 175 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afGrid)(JNIEnv *env, jclass clazz, 176 | jlong wnd, jint rows, 177 | jint columns) { 178 | AF_CHECK_VOID(af_grid(WND(wnd), rows, columns)); 179 | } 180 | 181 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetAxesLimitsCompute)( 182 | JNIEnv *env, jclass clazz, jlong wnd, jlong arrX, jlong arrY, jlong arrZ, 183 | jboolean isExact, jint r, jint c) { 184 | 185 | af_cell props{r, c, NULL, AF_COLORMAP_DEFAULT}; 186 | AF_CHECK_VOID(af_set_axes_limits_compute(WND(wnd), ARRAY(arrX), ARRAY(arrY), 187 | arrZ > 0 ? ARRAY(arrZ) : NULL, 188 | isExact, &props)); 189 | } 190 | 191 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetAxesLimits2d)( 192 | JNIEnv *env, jclass clazz, jlong wnd, jfloat xMin, jfloat xMax, jfloat yMin, 193 | jfloat yMax, jboolean isExact, jint r, jint c) { 194 | 195 | af_cell props{r, c, NULL, AF_COLORMAP_DEFAULT}; 196 | AF_CHECK_VOID( 197 | af_set_axes_limits_2d(WND(wnd), xMin, xMax, yMin, yMax, isExact, &props)); 198 | } 199 | 200 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetAxesLimits3d)( 201 | JNIEnv *env, jclass clazz, jlong wnd, jfloat xMin, jfloat xMax, jfloat yMin, 202 | jfloat yMax, jfloat zMin, jfloat zMax, jboolean isExact, jint r, jint c) { 203 | 204 | af_cell props{r, c, NULL, AF_COLORMAP_DEFAULT}; 205 | AF_CHECK_VOID(af_set_axes_limits_3d(WND(wnd), xMin, xMax, yMin, yMax, zMin, 206 | zMax, isExact, &props)); 207 | } 208 | 209 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetAxesTitles)(JNIEnv *env, jclass clazz, 210 | jlong wnd, jstring xTitle, 211 | jstring yTitle, 212 | jstring zTitle, jint r, 213 | jint c) { 214 | af_cell props{r, c, NULL, AF_COLORMAP_DEFAULT}; 215 | const char *cXTitle = env->GetStringUTFChars(xTitle, 0); 216 | const char *cYTitle = env->GetStringUTFChars(yTitle, 0); 217 | const char *cZTitle = env->GetStringUTFChars(zTitle, 0); 218 | AF_CHECK_VOID( 219 | af_set_axes_titles(WND(wnd), cXTitle, cYTitle, cZTitle, &props)); 220 | env->ReleaseStringUTFChars(xTitle, cXTitle); 221 | env->ReleaseStringUTFChars(yTitle, cYTitle); 222 | env->ReleaseStringUTFChars(zTitle, cZTitle); 223 | } 224 | 225 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afShow)(JNIEnv *env, jclass clazz, 226 | jlong wnd) { 227 | AF_CHECK_VOID(af_show(WND(wnd))); 228 | } 229 | 230 | JNIEXPORT jboolean JNICALL GRAPHICS_FUNC(afClose)(JNIEnv *env, jclass clazz, 231 | jlong wnd) { 232 | bool closed = true; 233 | AF_CHECK(af_is_window_closed(&closed, WND(wnd))); 234 | return (jboolean)closed; 235 | } 236 | 237 | JNIEXPORT void JNICALL GRAPHICS_FUNC(afSetVisibility)(JNIEnv *env, jclass clazz, 238 | jlong wnd, 239 | jboolean isVisible) { 240 | AF_CHECK_VOID(af_set_visibility(WND(wnd), isVisible)); 241 | } 242 | 243 | END_EXTERN_C 244 | -------------------------------------------------------------------------------- /src/image.cpp: -------------------------------------------------------------------------------- 1 | #include "jni_helper.h" 2 | 3 | BEGIN_EXTERN_C 4 | 5 | #define IMAGE_FUNC(FUNC) AF_MANGLE(Image, FUNC) 6 | 7 | #define MORPH_OP_DEF(func) \ 8 | JNIEXPORT jlong JNICALL IMAGE_FUNC(func)(JNIEnv * env, jclass clazz, \ 9 | jlong a, jlong b) { \ 10 | af_array ret = 0; \ 11 | AF_CHECK(af_##func(&ret, ARRAY(a), ARRAY(b))); \ 12 | return JLONG(ret); \ 13 | } 14 | 15 | MORPH_OP_DEF(erode) 16 | MORPH_OP_DEF(dilate) 17 | 18 | JNIEXPORT jlong JNICALL IMAGE_FUNC(medfilt)(JNIEnv *env, jclass clazz, jlong a, 19 | jint w, jint h) { 20 | af_array ret = 0; 21 | AF_CHECK(af_medfilt(&ret, ARRAY(a), w, h, AF_PAD_ZERO)); 22 | return JLONG(ret); 23 | } 24 | 25 | JNIEXPORT jlong JNICALL IMAGE_FUNC(bilateral)(JNIEnv *env, jclass clazz, 26 | jlong a, jfloat space, 27 | jfloat color) { 28 | af_array ret = 0; 29 | AF_CHECK(af_bilateral(&ret, ARRAY(a), space, color, false)); 30 | return JLONG(ret); 31 | } 32 | 33 | JNIEXPORT jlong JNICALL IMAGE_FUNC(meanshift)(JNIEnv *env, jclass clazz, 34 | jlong a, jfloat space, 35 | jfloat color, jint iter) { 36 | af_array ret = 0; 37 | AF_CHECK(af_mean_shift(&ret, ARRAY(a), space, color, iter, false)); 38 | return JLONG(ret); 39 | } 40 | 41 | JNIEXPORT jlong JNICALL IMAGE_FUNC(histogram)(JNIEnv *env, jclass clazz, 42 | jlong a, jint nbins) { 43 | double rmin, imin; 44 | double rmax, imax; 45 | AF_CHECK(af_min_all(&rmin, &imin, ARRAY(a))); 46 | AF_CHECK(af_max_all(&rmax, &imax, ARRAY(a))); 47 | 48 | af_array ret = 0; 49 | AF_CHECK(af_histogram(&ret, ARRAY(a), nbins, rmin, rmax)); 50 | return JLONG(ret); 51 | } 52 | 53 | JNIEXPORT jlong JNICALL IMAGE_FUNC(hist_mnmx)(JNIEnv *env, jclass clazz, 54 | jlong a, jint nbins, jfloat min, 55 | jfloat max) { 56 | af_array ret = 0; 57 | AF_CHECK(af_histogram(&ret, ARRAY(a), nbins, min, max)); 58 | return JLONG(ret); 59 | } 60 | 61 | JNIEXPORT jlong JNICALL IMAGE_FUNC(rotate)(JNIEnv *env, jclass clazz, jlong a, 62 | jfloat theta, jboolean crop, 63 | jint method) { 64 | af_array ret = 0; 65 | AF_CHECK(af_rotate(&ret, ARRAY(a), theta, crop, (af_interp_type)method)); 66 | return JLONG(ret); 67 | } 68 | 69 | JNIEXPORT jlong JNICALL IMAGE_FUNC(resize1)(JNIEnv *env, jclass clazz, jlong a, 70 | jfloat scale, jint method) { 71 | af_array ret = 0; 72 | dim_t dims[4]; 73 | AF_CHECK(af_get_dims(dims + 0, dims + 1, dims + 2, dims + 3, ARRAY(a))); 74 | 75 | dim_t odim0 = (dim_t)(scale * (float)dims[0]); 76 | dim_t odim1 = (dim_t)(scale * (float)dims[1]); 77 | AF_CHECK(af_resize(&ret, ARRAY(a), odim0, odim1, (af_interp_type)method)); 78 | return JLONG(ret); 79 | } 80 | 81 | JNIEXPORT jlong JNICALL IMAGE_FUNC(resize2)(JNIEnv *env, jclass clazz, jlong a, 82 | jfloat scalex, jfloat scaley, 83 | jint method) { 84 | af_array ret = 0; 85 | dim_t dims[4]; 86 | AF_CHECK(af_get_dims(dims + 0, dims + 1, dims + 2, dims + 3, ARRAY(a))); 87 | 88 | dim_t odim0 = (dim_t)(scalex * (float)dims[0]); 89 | dim_t odim1 = (dim_t)(scaley * (float)dims[1]); 90 | AF_CHECK(af_resize(&ret, ARRAY(a), odim0, odim1, (af_interp_type)method)); 91 | return JLONG(ret); 92 | } 93 | 94 | JNIEXPORT jlong JNICALL IMAGE_FUNC(resize3)(JNIEnv *env, jclass clazz, jlong a, 95 | jint height, jint width, 96 | jint method) { 97 | af_array ret = 0; 98 | AF_CHECK(af_resize(&ret, ARRAY(a), height, width, (af_interp_type)method)); 99 | return JLONG(ret); 100 | } 101 | 102 | END_EXTERN_C 103 | -------------------------------------------------------------------------------- /src/index.cpp: -------------------------------------------------------------------------------- 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 | jint ndims, 18 | jobject idx0, 19 | jobject idx1, jobject idx2, 20 | jobject idx3, int dim) { 21 | af_index_t indices[] {java::jIndexToCIndex(env, idx0), 22 | java::jIndexToCIndex(env, idx1), 23 | java::jIndexToCIndex(env, idx2), 24 | java::jIndexToCIndex(env, idx3)}; 25 | 26 | af_array lhs = ARRAY(dst); 27 | AF_CHECK_VOID(af_assign_gen(&lhs, lhs, ndims, indices, ARRAY(src))); 28 | } 29 | 30 | END_EXTERN_C 31 | -------------------------------------------------------------------------------- /src/java/java.cpp: -------------------------------------------------------------------------------- 1 | #include "java.h" 2 | 3 | namespace java { 4 | enum class JavaType { 5 | Int, 6 | Byte, 7 | Char, 8 | Double, 9 | Float, 10 | Long, 11 | String, 12 | Short, 13 | Void, 14 | Boolean, 15 | Object 16 | }; 17 | 18 | static const char *mapJavaTypeToString(JavaType type) { 19 | switch (type) { 20 | case JavaType::Int: return "I"; 21 | case JavaType::Byte: return "B"; 22 | case JavaType::Char: return "C"; 23 | case JavaType::Double: return "D"; 24 | case JavaType::Float: return "F"; 25 | case JavaType::Long: return "J"; 26 | case JavaType::String: return "Ljava/lang/String;"; 27 | case JavaType::Short: return "S"; 28 | case JavaType::Void: return "V"; 29 | case JavaType::Boolean: return "Z"; 30 | case JavaType::Object: return "Ljava/lang/Object;"; 31 | } 32 | } 33 | 34 | static std::string generateFunctionSignature( 35 | JavaType returnType, std::initializer_list params) { 36 | std::string signature = "("; 37 | for (const auto ¶m : params) { 38 | signature += mapJavaTypeToString(param); 39 | } 40 | signature += ")"; 41 | signature += mapJavaTypeToString(returnType); 42 | return signature; 43 | } 44 | 45 | void throwArrayFireException(JNIEnv *env, const char *functionName, 46 | const char *file, const int line, const int code) { 47 | // Find and instantiate an ArrayFireException 48 | jclass exceptionClass = env->FindClass("com/arrayfire/ArrayFireException"); 49 | if (env->ExceptionCheck()) { 50 | env->ExceptionDescribe(); 51 | } 52 | 53 | const std::string constructorSig = generateFunctionSignature( 54 | JavaType::Void, {JavaType::Int, JavaType::String}); 55 | jmethodID constructor = 56 | env->GetMethodID(exceptionClass, "", constructorSig.c_str()); 57 | 58 | jthrowable exception = static_cast( 59 | env->NewObject(exceptionClass, constructor, code, 60 | env->NewStringUTF(""))); 61 | 62 | // Find setLocation method and call it with 63 | // the function name, file and line parameters 64 | const std::string setLocationSig = generateFunctionSignature( 65 | JavaType::Void, {JavaType::String, JavaType::String, JavaType::Int}); 66 | 67 | jmethodID setLocationID = 68 | env->GetMethodID(exceptionClass, "setLocation", setLocationSig.c_str()); 69 | 70 | env->CallVoidMethod(exception, setLocationID, env->NewStringUTF(functionName), 71 | env->NewStringUTF(file), line); 72 | 73 | env->Throw(exception); 74 | env->DeleteLocalRef(exceptionClass); 75 | } 76 | 77 | template 78 | jobject createJavaObject(JNIEnv *env, JavaObjects objectType, Args... args) { 79 | switch (objectType) { 80 | case JavaObjects::FloatComplex: { 81 | jclass cls = env->FindClass("com/arrayfire/FloatComplex"); 82 | std::string sig = generateFunctionSignature( 83 | JavaType::Void, {JavaType::Float, JavaType::Float}); 84 | jmethodID id = env->GetMethodID(cls, "", sig.c_str()); 85 | jobject obj = env->NewObject(cls, id, args...); 86 | return obj; 87 | 88 | } break; 89 | case JavaObjects::DoubleComplex: { 90 | jclass cls = env->FindClass("com/arrayfire/DoubleComplex"); 91 | std::string sig = generateFunctionSignature( 92 | JavaType::Void, {JavaType::Double, JavaType::Double}); 93 | jmethodID id = env->GetMethodID(cls, "", sig.c_str()); 94 | jobject obj = env->NewObject(cls, id, args...); 95 | return obj; 96 | } break; 97 | } 98 | } 99 | 100 | af_index_t jIndexToCIndex(JNIEnv *env, jobject obj) { 101 | af_index_t index; 102 | jclass cls = env->GetObjectClass(obj); 103 | 104 | std::string getIsSeqSig = generateFunctionSignature(JavaType::Boolean, {}); 105 | jmethodID getIsSeqId = env->GetMethodID(cls, "isSeq", getIsSeqSig.c_str()); 106 | assert(getIsSeqId != NULL); 107 | index.isSeq = env->CallBooleanMethod(obj, getIsSeqId); 108 | 109 | std::string getIsBatchSig = generateFunctionSignature(JavaType::Boolean, {}); 110 | jmethodID getIsBatchId = env->GetMethodID(cls, "isBatch", getIsBatchSig.c_str()); 111 | assert(getIsBatchId != NULL); 112 | index.isBatch = env->CallBooleanMethod(obj, getIsBatchId); 113 | 114 | if (index.isSeq) { 115 | // get seq object 116 | std::string getSeqSig = generateFunctionSignature(JavaType::Object, {}); 117 | jmethodID getSeqId = env->GetMethodID(cls, "getSeq", getSeqSig.c_str()); 118 | assert(getSeqId != NULL); 119 | jobject seq = env->CallObjectMethod(obj, getSeqId); 120 | 121 | // get seq fields 122 | jclass seqCls = env->GetObjectClass(seq); 123 | assert(seqCls == env->FindClass("com/arrayfire/Seq")); 124 | 125 | jfieldID beginID = env->GetFieldID(seqCls, "begin", mapJavaTypeToString(JavaType::Double)); 126 | assert(beginID != NULL); 127 | double begin = env->GetDoubleField(seq, beginID); 128 | 129 | jfieldID endID = env->GetFieldID(seqCls, "end", mapJavaTypeToString(JavaType::Double)); 130 | assert(endID != NULL); 131 | double end = env->GetDoubleField(seq, endID); 132 | 133 | jfieldID stepID = env->GetFieldID(seqCls, "step", mapJavaTypeToString(JavaType::Double)); 134 | assert(stepID != NULL); 135 | double step = env->GetDoubleField(seq, stepID); 136 | 137 | index.idx.seq = af_make_seq(begin, end, step); 138 | } else { 139 | std::string getArrSig = generateFunctionSignature(JavaType::Long, {}); 140 | jmethodID getArrId = env->GetMethodID(cls, "getArrRef", getArrSig.c_str()); 141 | assert(getArrId != NULL); 142 | long arrRef = env->CallLongMethod(obj, getArrId); 143 | index.idx.arr = (af_array)arrRef; 144 | } 145 | return index; 146 | } 147 | 148 | #define INSTANTIATE(type) \ 149 | template jobject createJavaObject(JNIEnv *, JavaObjects, type, type); 150 | 151 | INSTANTIATE(float) 152 | INSTANTIATE(double) 153 | 154 | #undef INSTANTIATE 155 | 156 | } // namespace java 157 | -------------------------------------------------------------------------------- /src/java/java.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | namespace java { 7 | 8 | enum class JavaObjects { FloatComplex, DoubleComplex }; 9 | 10 | template 11 | jobject createJavaObject(JNIEnv *env, JavaObjects objectType, Args... args); 12 | 13 | af_index_t jIndexToCIndex(JNIEnv *env, jobject obj); 14 | 15 | void throwArrayFireException(JNIEnv *env, const char *functionName, 16 | const char *file, const int line, const int code); 17 | } // namespace java 18 | 19 | #define AF_CHECK(err) \ 20 | if (err != AF_SUCCESS) { \ 21 | java::throwArrayFireException(env, __func__, __FILE__, __LINE__, \ 22 | (int)err); \ 23 | return 0; \ 24 | } 25 | 26 | #define AF_CHECK_VOID(err) \ 27 | if (err != AF_SUCCESS) { \ 28 | java::throwArrayFireException(env, __func__, __FILE__, __LINE__, \ 29 | (int)err); \ 30 | return; \ 31 | } 32 | -------------------------------------------------------------------------------- /src/jni_helper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "java/java.h" 4 | 5 | #ifdef ANDROID 6 | #include 7 | #define LOG(...) \ 8 | __android_log_print(ANDROID_LOG_INFO, "ArrayFireJNI", __VA_ARGS__) 9 | #define AF_INFO() 10 | #else 11 | #define LOG(msg, ...) \ 12 | do { \ 13 | printf(__FILE__ ":%d: " msg "\n", __LINE__, ##__VA_ARGS__); \ 14 | } while (0) 15 | #define AF_INFO() af::info() 16 | #endif 17 | 18 | #ifdef __cplusplus 19 | using af::af_cdouble; 20 | using af::af_cfloat; 21 | 22 | #define BEGIN_EXTERN_C extern "C" { 23 | #define END_EXTERN_C } 24 | #endif 25 | 26 | #define AF_MANGLE(CLASS, FUNC) Java_com_arrayfire_##CLASS##_##FUNC 27 | 28 | const int MaxDimSupported = 4; 29 | 30 | #define AF_TO_JAVA(fn) fn 31 | 32 | #define ARRAY(REF) (af_array)(REF) 33 | 34 | #define JLONG(ARR) (jlong)(ARR) 35 | -------------------------------------------------------------------------------- /src/signal.cpp: -------------------------------------------------------------------------------- 1 | #include "jni_helper.h" 2 | 3 | BEGIN_EXTERN_C 4 | 5 | #define SIGNAL_FUNC(FUNC) AF_MANGLE(Signal, FUNC) 6 | 7 | #define CONVOLVE(N) \ 8 | JNIEXPORT jlong JNICALL SIGNAL_FUNC(convolve##N)( \ 9 | JNIEnv * env, jclass clazz, jlong a, jlong b, int method) { \ 10 | af_array ret = 0; \ 11 | AF_CHECK(af_convolve##N(&ret, ARRAY(a), ARRAY(b), (af_conv_mode)method, \ 12 | AF_CONV_AUTO)); \ 13 | return JLONG(ret); \ 14 | } 15 | 16 | CONVOLVE(1) 17 | CONVOLVE(2) 18 | CONVOLVE(3) 19 | 20 | #define FFT(func, is_inv) \ 21 | JNIEXPORT jlong JNICALL SIGNAL_FUNC(func)(JNIEnv * env, jclass clazz, \ 22 | jlong a, int dim0, int method) { \ 23 | af_array ret = 0; \ 24 | double norm = 1.0; \ 25 | dim_t dims[4]; \ 26 | AF_CHECK(af_get_dims(dims + 0, dims + 1, dims + 2, dims + 3, ARRAY(a))); \ 27 | if (is_inv) norm *= dims[0]; \ 28 | AF_CHECK(af_##func(&ret, ARRAY(a), norm, dim0)); \ 29 | return JLONG(ret); \ 30 | } 31 | 32 | FFT(fft, true) 33 | FFT(ifft, false) 34 | 35 | #define FFT2(func, is_inv) \ 36 | JNIEXPORT jlong JNICALL SIGNAL_FUNC(func)( \ 37 | JNIEnv * env, jclass clazz, jlong a, int dim0, int dim1, int method) { \ 38 | af_array ret = 0; \ 39 | double norm = 1.0; \ 40 | dim_t dims[4]; \ 41 | AF_CHECK(af_get_dims(dims + 0, dims + 1, dims + 2, dims + 3, ARRAY(a))); \ 42 | if (is_inv) norm *= dims[0] * dims[1]; \ 43 | AF_CHECK(af_##func(&ret, ARRAY(a), norm, dim0, dim1)); \ 44 | return JLONG(ret); \ 45 | } 46 | 47 | FFT2(fft2, true) 48 | FFT2(ifft2, false) 49 | 50 | #define FFT3(func, is_inv) \ 51 | JNIEXPORT jlong JNICALL SIGNAL_FUNC(func)(JNIEnv * env, jclass clazz, \ 52 | jlong a, int dim0, int dim1, \ 53 | int dim2, int method) { \ 54 | af_array ret = 0; \ 55 | double norm = 1.0; \ 56 | dim_t dims[4]; \ 57 | AF_CHECK(af_get_dims(dims + 0, dims + 1, dims + 2, dims + 3, ARRAY(a))); \ 58 | if (is_inv) norm *= dims[0] * dims[1] * dims[2]; \ 59 | AF_CHECK(af_##func(&ret, ARRAY(a), norm, dim0, dim1, dim2)); \ 60 | return JLONG(ret); \ 61 | } 62 | 63 | FFT3(fft3, true) 64 | FFT3(ifft3, false) 65 | 66 | END_EXTERN_C 67 | -------------------------------------------------------------------------------- /src/statistics.cpp: -------------------------------------------------------------------------------- 1 | #include "jni_helper.h" 2 | 3 | BEGIN_EXTERN_C 4 | 5 | #define STATISTICS_FUNC(FUNC) AF_MANGLE(Statistics, FUNC) 6 | 7 | #define INSTANTIATE_STAT_ALL_WEIGHTED(Name, name) \ 8 | JNIEXPORT jobject JNICALL STATISTICS_FUNC(af##Name##AllWeighted)( \ 9 | JNIEnv * env, jclass clazz, jlong ref, jlong weightsRef) { \ 10 | double real = 0, img = 0; \ 11 | AF_CHECK( \ 12 | af_##name##_all_weighted(&real, &img, ARRAY(ref), ARRAY(weightsRef))); \ 13 | return java::createJavaObject(env, java::JavaObjects::DoubleComplex, real, \ 14 | img); \ 15 | } 16 | 17 | #define INSTANTIATE_STAT_WEIGHTED(Name, name) \ 18 | JNIEXPORT jlong JNICALL STATISTICS_FUNC(af##Name##Weighted)( \ 19 | JNIEnv * env, jclass clazz, jlong ref, jlong weightsRef, jint dim) { \ 20 | af_array ret = 0; \ 21 | AF_CHECK(af_##name##_weighted(&ret, ARRAY(ref), ARRAY(weightsRef), dim)); \ 22 | return JLONG(ret); \ 23 | } 24 | 25 | #define INSTANTIATE_STAT(Name, name) \ 26 | JNIEXPORT jlong JNICALL STATISTICS_FUNC(af##Name)( \ 27 | JNIEnv * env, jclass clazz, jlong ref, jint dim) { \ 28 | af_array ret = 0; \ 29 | AF_CHECK(af_##name(&ret, ARRAY(ref), dim)); \ 30 | return JLONG(ret); \ 31 | } 32 | 33 | #define INSTANTIATE_STAT_ALL(Name, name) \ 34 | JNIEXPORT jobject JNICALL STATISTICS_FUNC(af##Name##All)( \ 35 | JNIEnv * env, jclass clazz, jlong ref) { \ 36 | double real = 0, img = 0; \ 37 | AF_CHECK(af_##name##_all(&real, &img, ARRAY(ref))); \ 38 | return java::createJavaObject(env, java::JavaObjects::DoubleComplex, real, \ 39 | img); \ 40 | } 41 | 42 | // Mean 43 | INSTANTIATE_STAT(Mean, mean) 44 | INSTANTIATE_STAT_ALL(Mean, mean) 45 | INSTANTIATE_STAT_ALL_WEIGHTED(Mean, mean) 46 | INSTANTIATE_STAT_WEIGHTED(Mean, mean) 47 | 48 | // Variance 49 | JNIEXPORT jlong JNICALL STATISTICS_FUNC(afVar)(JNIEnv *env, jclass clazz, 50 | jlong ref, jboolean isBiased, 51 | jint dim) { 52 | af_array ret = 0; 53 | AF_CHECK(af_var(&ret, ARRAY(ref), isBiased, dim)); 54 | return JLONG(ret); 55 | } 56 | 57 | JNIEXPORT jobject JNICALL STATISTICS_FUNC(afVarAll)(JNIEnv *env, jclass clazz, 58 | jlong ref, jboolean isBiased) { 59 | double real = 0, img = 0; 60 | AF_CHECK(af_var_all(&real, &img, ARRAY(ref), isBiased)); 61 | return java::createJavaObject(env, java::JavaObjects::DoubleComplex, real, img); 62 | } 63 | 64 | INSTANTIATE_STAT_WEIGHTED(Var, var) 65 | INSTANTIATE_STAT_ALL_WEIGHTED(Var, var) 66 | 67 | // Standard dev 68 | INSTANTIATE_STAT(Stdev, stdev) 69 | INSTANTIATE_STAT_ALL(Stdev, stdev) 70 | 71 | // Median 72 | INSTANTIATE_STAT(Median, median) 73 | INSTANTIATE_STAT_ALL(Median, median) 74 | 75 | // Covariance 76 | JNIEXPORT jlong JNICALL STATISTICS_FUNC(afCov)(JNIEnv *env, jclass clazz, 77 | jlong ref, jlong ref2, 78 | jboolean isBiased) { 79 | af_array ret = 0; 80 | AF_CHECK(af_cov(&ret, ARRAY(ref), ARRAY(ref2), isBiased)); 81 | return JLONG(ret); 82 | } 83 | 84 | // Correlation coefficient 85 | JNIEXPORT jobject JNICALL STATISTICS_FUNC(afCorrcoef)(JNIEnv *env, jclass clazz, 86 | jlong ref, jlong ref2) { 87 | double real = 0; 88 | AF_CHECK(af_corrcoef(&real, NULL, ARRAY(ref), ARRAY(ref2))); 89 | return java::createJavaObject(env, java::JavaObjects::DoubleComplex, real, 90 | 0.0); 91 | } 92 | 93 | // Topk elements 94 | JNIEXPORT jlongArray JNICALL STATISTICS_FUNC(afTopk)(JNIEnv *env, jclass clazz, 95 | jlong ref, jint k, 96 | jint dim, jint order) { 97 | af_array vals = 0, idxs = 0; 98 | AF_CHECK(af_topk(&vals, &idxs, ARRAY(ref), k, dim, 99 | static_cast(order))); 100 | jlong refs[2]{JLONG(idxs), JLONG(vals)}; 101 | jlongArray jRefs = env->NewLongArray(2); 102 | env->SetLongArrayRegion(jRefs, 0, 2, refs); 103 | return jRefs; 104 | } 105 | 106 | #undef INSTANTIATE_STAT 107 | #undef INSTANTIATE_STAT_ALL 108 | #undef INSTANTIATE_STAT_WEIGHTED 109 | #undef INSTANTIATE_STAT_ALL_WEIGHTED 110 | 111 | END_EXTERN_C 112 | -------------------------------------------------------------------------------- /src/util.cpp: -------------------------------------------------------------------------------- 1 | #include "jni_helper.h" 2 | 3 | BEGIN_EXTERN_C 4 | 5 | #define UTIL_FUNC(FUNC) AF_MANGLE(Util, FUNC) 6 | 7 | JNIEXPORT void JNICALL UTIL_FUNC(info)(JNIEnv *env, jclass clazz) { af_info(); } 8 | 9 | END_EXTERN_C 10 | -------------------------------------------------------------------------------- /todo.txt: -------------------------------------------------------------------------------- 1 | af_accum 2 | af_alloc_device 3 | af_alloc_host 4 | af_alloc_pinned 5 | af_all_true 6 | af_all_true_all 7 | af_and 8 | af_anisotropic_diffusion 9 | af_any_true 10 | af_any_true_all 11 | af_approx1 12 | af_approx1_uniform 13 | af_approx2 14 | af_approx2_uniform 15 | af_arg 16 | af_assign_seq 17 | af_atan2 18 | af_bitand 19 | af_bitor 20 | af_bitshiftl 21 | af_bitshiftr 22 | af_bitxor 23 | af_canny 24 | af_cast 25 | af_cbrt 26 | af_ceil 27 | af_cholesky 28 | af_cholesky_inplace 29 | af_clamp 30 | af_color_space 31 | af_conjg 32 | af_constant_complex 33 | af_constant_long 34 | af_constant_ulong 35 | af_convolve2_sep 36 | af_copy_array 37 | af_count 38 | af_count_all 39 | af_cplx 40 | af_cplx2 41 | af_create_features 42 | af_create_indexers 43 | af_create_random_engine 44 | af_create_sparse_array 45 | af_create_sparse_array_from_dense 46 | af_create_sparse_array_from_ptr 47 | af_create_strided_array 48 | af_delete_image_memory 49 | af_det 50 | af_device_array 51 | af_device_gc 52 | af_device_info 53 | af_device_mem_info 54 | af_diag_create 55 | af_diag_extract 56 | af_diff1 57 | af_diff2 58 | af_dilate3 59 | af_dog 60 | af_dot 61 | af_dot_all 62 | af_draw_plot 63 | af_draw_plot3 64 | af_draw_scatter 65 | af_draw_scatter3 66 | af_erf 67 | af_erfc 68 | af_erode3 69 | af_err_to_string 70 | af_eval 71 | af_eval_multiple 72 | af_example_function 73 | af_expm1 74 | af_factorial 75 | af_fast 76 | af_fft2_c2r 77 | af_fft2_inplace 78 | af_fft2_r2c 79 | af_fft3_c2r 80 | af_fft3_inplace 81 | af_fft3_r2c 82 | af_fft_c2r 83 | af_fft_convolve1 84 | af_fft_convolve2 85 | af_fft_convolve3 86 | af_fft_inplace 87 | af_fft_r2c 88 | af_fir 89 | af_flat 90 | af_flip 91 | af_floor 92 | af_free_device 93 | af_free_host 94 | af_free_pinned 95 | af_gaussian_kernel 96 | af_gemm 97 | af_get_active_backend 98 | af_get_allocated_bytes 99 | af_get_available_backends 100 | af_get_backend_count 101 | af_get_backend_id 102 | af_get_data_ref_count 103 | af_get_dbl_support 104 | af_get_default_random_engine 105 | af_get_device 106 | af_get_device_count 107 | af_get_device_id 108 | af_get_device_ptr 109 | af_get_features_num 110 | af_get_features_orientation 111 | af_get_features_score 112 | af_get_features_size 113 | af_get_features_xpos 114 | af_get_features_ypos 115 | af_get_half_support 116 | af_get_last_error 117 | af_get_manual_eval_flag 118 | af_get_mem_step_size 119 | af_get_numdims 120 | af_get_offset 121 | af_get_raw_ptr 122 | af_get_revision 123 | af_get_scalar 124 | af_get_seed 125 | af_get_size_of 126 | af_get_strides 127 | af_get_version 128 | af_gloh 129 | af_gradient 130 | af_gray2rgb 131 | af_hamming_matcher 132 | af_harris 133 | af_hist_equal 134 | af_homography 135 | af_hsv2rgb 136 | af_hypot 137 | af_ifft2_inplace 138 | af_ifft3_inplace 139 | af_ifft_inplace 140 | af_iir 141 | af_imag 142 | af_imax 143 | af_imax_all 144 | af_imin 145 | af_imin_all 146 | af_index 147 | af_index_gen 148 | af_info_string 149 | af_init 150 | af_inverse 151 | af_inverse_deconv 152 | af_iota 153 | af_is_bool 154 | af_is_column 155 | af_is_complex 156 | af_is_double 157 | af_is_empty 158 | af_is_floating 159 | af_is_half 160 | af_is_image_io_available 161 | af_isinf 162 | af_is_integer 163 | af_is_lapack_available 164 | af_is_linear 165 | af_is_locked_array 166 | af_isnan 167 | af_is_owner 168 | af_is_real 169 | af_is_realfloating 170 | af_is_row 171 | af_is_scalar 172 | af_is_single 173 | af_is_sparse 174 | af_is_vector 175 | af_iszero 176 | af_iterative_deconv 177 | af_join 178 | af_join_many 179 | af_lgamma 180 | af_load_image 181 | af_load_image_memory 182 | af_load_image_native 183 | af_lock_array 184 | af_lock_device_ptr 185 | af_log10 186 | af_log1p 187 | af_log2 188 | af_lower 189 | af_lu 190 | af_lu_inplace 191 | af_match_template 192 | af_matmul 193 | af_maxfilt 194 | af_maxof 195 | af_meanvar 196 | af_medfilt1 197 | af_medfilt2 198 | af_minfilt 199 | af_minof 200 | af_mod 201 | af_moddims 202 | af_moments 203 | af_moments_all 204 | af_nearest_neighbour 205 | af_norm 206 | af_not 207 | af_or 208 | af_orb 209 | af_pinverse 210 | af_pow2 211 | af_print_array 212 | af_print_array_gen 213 | af_print_mem_info 214 | af_product 215 | af_product_all 216 | af_product_nan 217 | af_product_nan_all 218 | af_qr 219 | af_qr_inplace 220 | af_random_engine_get_seed 221 | af_random_engine_get_type 222 | af_random_engine_set_seed 223 | af_random_engine_set_type 224 | af_random_normal 225 | af_random_uniform 226 | af_rank 227 | af_read_array_index 228 | af_read_array_key 229 | af_read_array_key_check 230 | af_real 231 | af_regions 232 | af_release_features 233 | af_release_indexers 234 | af_release_random_engine 235 | af_rem 236 | af_reorder 237 | af_replace 238 | af_replace_scalar 239 | af_retain_array 240 | af_retain_features 241 | af_retain_random_engine 242 | af_rgb2gray 243 | af_rgb2hsv 244 | af_rgb2ycbcr 245 | af_root 246 | af_round 247 | af_rsqrt 248 | af_sat 249 | af_save_array 250 | af_save_image 251 | af_save_image_memory 252 | af_save_image_native 253 | af_scale 254 | af_scan 255 | af_scan_by_key 256 | af_select 257 | af_select_scalar_l 258 | af_select_scalar_r 259 | af_set_array_indexer 260 | af_set_axes_label_format 261 | af_set_backend 262 | af_set_default_random_engine_type 263 | af_set_device 264 | af_set_fft_plan_cache_size 265 | af_set_intersect 266 | af_set_manual_eval_flag 267 | af_set_mem_step_size 268 | af_set_seed 269 | af_set_seq_indexer 270 | af_set_seq_param_indexer 271 | af_set_union 272 | af_set_unique 273 | af_shift 274 | af_sift 275 | af_sigmoid 276 | af_sign 277 | af_skew 278 | af_sobel_operator 279 | af_solve 280 | af_solve_lu 281 | af_sort 282 | af_sort_by_key 283 | af_sort_index 284 | af_sparse_convert_to 285 | af_sparse_get_col_idx 286 | af_sparse_get_info 287 | af_sparse_get_nnz 288 | af_sparse_get_row_idx 289 | af_sparse_get_storage 290 | af_sparse_get_values 291 | af_sparse_to_dense 292 | af_sum_nan 293 | af_sum_nan_all 294 | af_susan 295 | af_svd 296 | af_svd_inplace 297 | af_sync 298 | af_tgamma 299 | af_tile 300 | af_transform 301 | af_transform_coordinates 302 | af_translate 303 | af_transpose 304 | af_transpose_inplace 305 | af_trunc 306 | af_unlock_array 307 | af_unlock_device_ptr 308 | af_unwrap 309 | af_upper 310 | af_wrap 311 | af_write_array 312 | af_ycbcr2rgb 313 | --------------------------------------------------------------------------------