Java tutorial
/* * (c) Eric Barnhill 2016 All Rights Reserved. * * This file is part of Java ArrayMath. Java ArrayMath is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by the Free Software Foundation, * either version 3 of the License, or (at your option) any later version. * * Java ArrayMath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. You should have received a copy of * the GNU General Public License along with Java ArrayMath. If not, see http://www.gnu.org/licenses/ . * * This code uses software from the Apache Software Foundation. The Apache Software License can be found at: http://www.apache.org/licenses/LICENSE-2.0.txt . */ package com.ericbarnhill.arrayMath; import java.util.Random; import org.apache.commons.math4.complex.Complex; import org.apache.commons.math4.util.FastMath; /** * * This class contains the mathematical operations libraries for Java ArrayMath. * * <p>The goal of this package is to create fluid and optimised processing of element-wise array operations * with emphasis on support for 3D volumes and complex numbers. The motivation was to enable elegant * and rapid code design for work with complex-valued 3D medical image volumes. * * <p>In particular, Java array operations need to alternate between in-place calls, for which the passed * object can be kept, and calls for which the solution is desired separate from the passed object, * which require a deep copy. ArrayMath methods that return deep copies have a C appended to the name * of the math function, for example, {@code sin(double[] d)} will operate in-place and return a reference * to the first passed array, while {@code sinC(double[] d)} will return a new {@code double[]} object. * * <p>This way the user can use the copy-and-assign approach typical of other scientific programming software by * adding the letter C, while using in-place calls whenever desired to reduce memory and garbage collection demands. * * <p>The methods are public and can be used on their own, but are also embedded into the accompanying * MathArray superclass, the use of which enables more elegant syntax. * * <p>Vectorisation and matrix generation methods produce or take square arrays but all other methods handle * ragged arrays. * * <p>The library follows all formatting standards of Apache Commons and applies useful libraries from * commons-math such as FastMath, Complex, and ComplexUtils. * * @author ericbarnhill * @see MathArray * @see MathArrayFactory * @version 0.1 * */ public class ArrayMath { // ABS // -- double /** * In-place element-wise {@code abs} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] abs(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.abs(f[i]); } return f; } /** * In-place element-wise {@code abs} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][]} arrqy. * * @since 0.1 */ public static double[][] abs(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { abs(f[i]); } return f; } /** * In-place element-wise {@code abs} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] abs(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { abs(f[i]); } return f; } // -- Complex /** * Returns absolute values of a {@code Complex[]} array as a {@code double[]}. * * @param f {@code Complex[]} array. * @return {@code double[]} array of absolute values}. * * @since 0.1 */ public static double[] abs(Complex[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i].abs(); } return h; } /** * Returns absolute values of a {@code Complex[][]} array as a {@code double[][]}. * * @param f {@code Complex[][]} array. * @return {@code double[][]} array of absolute values}. * * @since 0.1 */ public static double[][] abs(Complex[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = abs(f[i]); } return h; } /** * Returns absolute values of a {@code Complex[][][]} array as a {@code double[][][]}. * * @param f {@code Complex[][][]} array. * @return {@code double[][][]} array of absolute values}. * * @since 0.1 */ public static double[][][] abs(Complex[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = abs(f[i]); } return h; } // ABSC // -- double /** * Element-wise {@code abs} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] absC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.abs(f[i]); } return h; } /** * Element-wise {@code abs} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] absC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = absC(f[i]); } return h; } /** * Element-wise {@code abs} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] absC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = absC(f[i]); } return h; } // ACOS // -- double /** * In-place element-wise {@code acos} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] acos(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.acos(f[i]); } return f; } /** * In-place element-wise {@code acos} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] acos(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { acos(f[i]); } return f; } /** * In-place element-wise {@code acos} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] acos(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { acos(f[i]); } return f; } // -- Complex /** * In-place element-wise {@code acos} of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] acos(Complex[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = f[i].acos(); } return f; } /** * In-place element-wise {@code acos} of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] acos(Complex[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { acos(f[i]); } return f; } /** * In-place element-wise {@code acos} of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] acos(Complex[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { acos(f[i]); } return f; } // ACOSC // -- double /** * Element-wise {@code acos} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] acosC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.acos(f[i]); } return h; } /** * Element-wise {@code acos} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] acosC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = acosC(f[i]); } return h; } /** * Element-wise {@code acos} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] acosC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = acosC(f[i]); } return h; } // -- Complex /** * Element-wise {@code acos} of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] acosC(Complex[] f) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i].acos(); } return h; } /** * Element-wise {@code acos} of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] acosC(Complex[][] f) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = acosC(f[i]); } return h; } /** * Element-wise {@code acos} of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] acosC(Complex[][][] f) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = acosC(f[i]); } return h; } // ADD // -- scalar // -- -- double /** * Adds a scalar {@code double} to every element of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @param g {@code double}. * @return {@code double[]} array. * * @since 0.1 */ public static double[] add(double[] f, double g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] += g; } return f; } /** * Adds a scalar {@code double} to every element of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @param g {@code double}. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] add(double[][] f, double g) { final int fi = f.length; for (int i = 0; i < fi; i++) { add(f[i], g); } return f; } /** * Adds a scalar {@code double} to every element of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @param g {@code double}. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] add(double[][][] f, double g) { final int fi = f.length; for (int i = 0; i < fi; i++) { add(f[i], g); } return f; } // -- -- float /** * Adds a scalar {@code float} to every element of a {@code float[]}. Returns reference to first passed array. * * @param f {@code float[]} array. * @param g {@code float}. * @return {@code float[]} array. * * @since 0.1 */ public static float[] add(float[] f, float g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] += g; } return f; } /** * Adds a scalar {@code float} to every element of a {@code float[][]}. Returns reference to first passed array. * * @param f {@code float[][]} array. * @param g {@code float}. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] add(float[][] f, float g) { final int fi = f.length; for (int i = 0; i < fi; i++) { add(f[i], g); } return f; } /** * Adds a scalar {@code float} to every element of a {@code float[][][]}. Returns reference to first passed array. * * @param f {@code float[][][]} array. * @param g {@code float}. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] add(float[][][] f, float g) { final int fi = f.length; for (int i = 0; i < fi; i++) { add(f[i], g); } return f; } // -- -- Complex /** * Adds a scalar {@code Complex} to every element of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @param g {@code Complex}. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] add(Complex[] f, Complex g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i].add(g); } return f; } /** * Adds a scalar {@code Complex} to every element of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @param g {@code Complex}. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] add(Complex[][] f, Complex g) { final int fi = f.length; for (int i = 0; i < fi; i++) { add(f[i], g); } return f; } /** * Adds a scalar {@code Complex} to every element of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @param g {@code Complex}. * @return {{@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] add(Complex[][][] f, Complex g) { final int fi = f.length; for (int i = 0; i < fi; i++) { add(f[i], g); } return f; } // -- vector // -- -- double /** * Element-wise add {@code double[]} to {@code double[]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code double[]} array. * @param g {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] add(double[] f, double[] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] += g[i]; } return f; } /** * Element-wise add {@code double[][]} to {@code double[][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code double[][]} array. * @param g {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] add(double[][] f, double[][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { add(f[i], g[i]); } return f; } /** * Element-wise add {@code double[][][]} to {@code double[][][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @param g {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] add(double[][][] f, double[][][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { add(f[i], g[i]); } return f; } // -- -- float /** * Element-wise add {@code float[]} to {@code float[]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code float[]} array. * @param g {@code float[]} array. * @return {@code float[]} array. * * @since 0.1 */ public static float[] add(float[] f, float[] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] += g[i]; } return f; } /** * Element-wise add {@code float[][]} to {@code float[][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code float[][]} array. * @param g {@code float[][]} array. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] add(float[][] f, float[][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { add(f[i], g[i]); } return f; } /** * Element-wise add {@code float[][][]} to {@code float[][][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code float[][][]} array. * @param g {@code float[][][]} array. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] add(float[][][] f, float[][][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { add(f[i], g[i]); } return f; } // -- -- Complex /** * Element-wise add {@code Complex[]} to {@code Complex[]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @param g {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] add(Complex[] f, Complex[] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i].add(g[i]); } return f; } /** * Element-wise add {@code Complex[][]} to {@code Complex[][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @param g {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] add(Complex[][] f, Complex[][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { add(f[i], g[i]); } return f; } /** * Element-wise add {@code Complex[][][]} to {@code Complex[][][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @param g {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] add(Complex[][][] f, Complex[][][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { add(f[i], g[i]); } return f; } // ADDC // -- scalar // -- -- double /** * Adds a scalar {@code double} to every element of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @param g {@code double}. * @return {@code double[]} array. * * @since 0.1 */ public static double[] addC(double[] f, double g) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] + g; } return h; } /** * Adds a scalar {@code double} to every element of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @param g {@code double}. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] addC(double[][] f, double g) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = addC(f[i], g); } return h; } /** * Adds a scalar {@code double} to every element of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @param g {@code double}. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] addC(double[][][] f, double g) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = addC(f[i], g); } return h; } // -- -- float /** * Adds a scalar {@code float} to every element of a {@code float[]}. Returns deep copy. * * @param f {@code float[]} array. * @param g {@code float}. * @return {@code float[]} array. * * @since 0.1 */ public static float[] addC(float[] f, float g) { final int fi = f.length; float[] h = new float[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] + g; } return h; } /** * Adds a scalar {@code float} to every element of a {@code float[][]}. Returns deep copy. * * @param f {@code float[][]} array. * @param g {@code float}. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] addC(float[][] f, float g) { final int fi = f.length; float[][] h = new float[fi][]; for (int i = 0; i < fi; i++) { h[i] = addC(f[i], g); } return h; } /** * Adds a scalar {@code float} to every element of a {@code float[][][]}. Returns deep copy. * * @param f {@code float[][][]} array. * @param g {@code float}. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] addC(float[][][] f, float g) { final int fi = f.length; float[][][] h = new float[fi][][]; for (int i = 0; i < fi; i++) { h[i] = addC(f[i], g); } return h; } // -- -- Complex /** * Adds a scalar {@code Complex} to every element of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @param g {@code Complex}. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] addC(Complex[] f, Complex g) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = new Complex(f[i].getReal(), f[i].getImaginary()).add(g); } return h; } /** * Adds a scalar {@code Complex} to every element of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @param g {@code Complex}. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] addC(Complex[][] f, Complex g) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = addC(f[i], g); } return h; } /** * Adds a scalar {@code Complex} to every element of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @param g {@code Complex}. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] addC(Complex[][][] f, Complex g) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = addC(f[i], g); } return h; } // -- vector // -- -- double /** * Element-wise add {@code double[]} to {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @param g {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] addC(double[] f, double[] g) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] + g[i]; } return h; } /** * Element-wise add {@code double[][]} to {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @param g {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] addC(double[][] f, double[][] g) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = addC(f[i], g[i]); } return h; } /** * Element-wise add {@code double[][][]} to {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @param g {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] addC(double[][][] f, double[][][] g) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = addC(f[i], g[i]); } return h; } // -- -- float /** * Element-wise add {@code float[]} to {@code float[]}. Returns deep copy. * * @param f {@code float[]} array. * @param g {@code float[]} array. * @return {@code float[]} array. * * @since 0.1 */ public static float[] addC(float[] f, float[] g) { final int fi = f.length; float[] h = new float[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] + g[i]; } return h; } /** * Element-wise add {@code float[][]} to {@code float[][]}. Returns deep copy. * * @param f {@code float[][]} array. * @param g {@code float[][]} array. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] addC(float[][] f, float[][] g) { final int fi = f.length; float[][] h = new float[fi][]; for (int i = 0; i < fi; i++) { h[i] = addC(f[i], g[i]); } return h; } /** * Element-wise add {@code float[][][]} to {@code float[][][]}. Returns deep copy. * * @param f {@code float[][][]} array. * @param g {@code float[][][]} array. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] addC(float[][][] f, float[][][] g) { final int fi = f.length; float[][][] h = new float[fi][][]; for (int i = 0; i < fi; i++) { h[i] = addC(f[i], g[i]); } return h; } // -- -- Complex /** * Element-wise add {@code Complex[]} to {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @param g {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] addC(Complex[] f, Complex[] g) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = new Complex(f[i].getReal(), f[i].getImaginary()).add(g[i]); } return h; } /** * Element-wise add {@code Complex[][]} to {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @param g {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] addC(Complex[][] f, Complex[][] g) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = addC(f[i], g[i]); } return h; } /** * Element-wise add {@code Complex[][][]} to {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @param g {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] addC(Complex[][][] f, Complex[][][] g) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = addC(f[i], g[i]); } return h; } // ASIN // -- double /** * In-place element-wise {@code asin} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] asin(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.asin(f[i]); } return f; } /** * In-place element-wise {@code asin} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] asin(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { asin(f[i]); } return f; } /** * In-place element-wise {@code asin} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] asin(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { asin(f[i]); } return f; } // -- Complex /** * In-place element-wise {@code asin} of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] asin(Complex[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = f[i].asin(); } return f; } /** * In-place element-wise {@code asin} of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] asin(Complex[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { asin(f[i]); } return f; } /** * In-place element-wise {@code asin} of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] asin(Complex[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { asin(f[i]); } return f; } // ASINC // -- double /** * Element-wise {@code round} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] asinC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.round(f[i]); } return h; } /** * Element-wise {@code round} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] asinC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = asinC(f[i]); } return h; } /** * Element-wise {@code round} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] asinC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = asinC(f[i]); } return h; } // -- Complex /** * Element-wise {@code round} of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] asinC(Complex[] f) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i].asin(); } return h; } /** * Element-wise {@code round} of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] asinC(Complex[][] f) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = asinC(f[i]); } return h; } /** * Element-wise {@code round} of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] asinC(Complex[][][] f) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = asinC(f[i]); } return h; } // ATAN // -- double /** * In-place element-wise {@code atan} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[] array} * * @since 0.1 */ public static double[] atan(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.atan(f[i]); } return f; } /** * In-place element-wise {@code atan} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][] array} * * @since 0.1 */ public static double[][] atan(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { atan(f[i]); } return f; } /** * In-place element-wise {@code atan} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] atan(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { atan(f[i]); } return f; } // -- Complex /** * In-place element-wise {@code atan} of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @return {@code Complex[] array} * * @since 0.1 */ public static Complex[] atan(Complex[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = f[i].atan(); } return f; } /** * In-place element-wise {@code atan} of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @return {@code Complex[][] array} * * @since 0.1 */ public static Complex[][] atan(Complex[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { atan(f[i]); } return f; } /** * In-place element-wise {@code atan} of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][] array} * * @since 0.1 */ public static Complex[][][] atan(Complex[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { atan(f[i]); } return f; } // ATANC // -- double /** * Element-wise {@code atan} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] atanC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.atan(f[i]); } return h; } /** * Element-wise {@code atan} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] atanC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = atanC(f[i]); } return h; } /** * Element-wise {@code atan} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] atanC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = atanC(f[i]); } return h; } // -- Complex /** * Element-wise {@code atan} of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] atanC(Complex[] f) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i].atan(); } return h; } /** * Element-wise {@code atan} of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] atanC(Complex[][] f) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = atanC(f[i]); } return h; } /** * Element-wise {@code atan} of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] atanC(Complex[][][] f) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = atanC(f[i]); } return h; } // CEIL // -- double /** * In-place element-wise {@code ceil} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[] array} * * @since 0.1 */ public static double[] ceil(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.ceil(f[i]); } return f; } /** * In-place element-wise {@code ceil} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][] array} * * @since 0.1 */ public static double[][] ceil(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { ceil(f[i]); } return f; } /** * In-place element-wise {@code ceil} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] ceil(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { ceil(f[i]); } return f; } // CEILC // -- double /** * Element-wise {@code ceil} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] ceilC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.ceil(f[i]); } return h; } /** * Element-wise {@code ceil} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] ceilC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = ceilC(f[i]); } return h; } /** * Element-wise {@code ceil} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] ceilC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = ceilC(f[i]); } return h; } // COS // -- double /** * In-place element-wise {@code cos} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] cos(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.cos(f[i]); } return f; } /** * In-place element-wise {@code cos} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] cos(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { cos(f[i]); } return f; } /** * In-place element-wise {@code cos} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] cos(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { cos(f[i]); } return f; } // -- Complex /** * In-place element-wise {@code cos} of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] cos(Complex[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = f[i].cos(); } return f; } /** * In-place element-wise {@code cos} of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] cos(Complex[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { cos(f[i]); } return f; } /** * In-place element-wise {@code cos} of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] cos(Complex[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { cos(f[i]); } return f; } // COSC // -- double /** * Element-wise {@code cos} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] cosC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.cos(f[i]); } return h; } /** * Element-wise {@code cos} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] cosC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = cosC(f[i]); } return h; } /** * Element-wise {@code cos} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] cosC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = cosC(f[i]); } return h; } // -- Complex /** * Element-wise {@code cos} of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] cosC(Complex[] f) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i].cos(); } return h; } /** * Element-wise {@code cos} of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] cosC(Complex[][] f) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = cosC(f[i]); } return h; } /** * Element-wise {@code cos} of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] cosC(Complex[][][] f) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = cosC(f[i]); } return h; } // COSH // -- double /** * In-place element-wise {@code cosh} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] cosh(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.cosh(f[i]); } return f; } /** * In-place element-wise {@code cosh} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] cosh(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { cosh(f[i]); } return f; } /** * In-place element-wise {@code cosh} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] cosh(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { cosh(f[i]); } return f; } // -- Complex /** * In-place element-wise {@code cosh} of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] cosh(Complex[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = f[i].cosh(); } return f; } /** * In-place element-wise {@code cosh} of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] cosh(Complex[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { cosh(f[i]); } return f; } /** * In-place element-wise {@code cosh} of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] cosh(Complex[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { cosh(f[i]); } return f; } // COSHC // -- double /** * Element-wise {@code cosh} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] coshC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.cosh(f[i]); } return h; } /** * Element-wise {@code cosh} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] coshC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = coshC(f[i]); } return h; } /** * Element-wise {@code cosh} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] coshC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = coshC(f[i]); } return h; } // -- Complex /** * Element-wise {@code cosh} of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] coshC(Complex[] f) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i].cosh(); } return h; } /** * Element-wise {@code cosh} of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] coshC(Complex[][] f) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = coshC(f[i]); } return h; } /** * Element-wise {@code cosh} of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] coshC(Complex[][][] f) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = coshC(f[i]); } return h; } // DEVECTORISE /** * Restructure {@code double[]} vector as a square {@code double[][]}. * * @param f {@code double[]} vector * @param fi first dimension of array * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] devectorise(double[] f, int fi) { final int fl = f.length; final int fj = fl / fi; double[][] h = new double[fi][fj]; for (int x = 0; x < fi; x++) { for (int y = 0; y < fj; y++) { h[x][y] = f[y * fi + x]; } } return h; } /** * Restructure {@code double[]} vector as a square {@code double[][][]}. * * @param f {@code double[]} vector * @param fi first dimension of array * @param fj second dimension of array * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] devectorise(double[] f, int fi, int fj) { final int fl = f.length; final int fk = fl / (fi * fj); final int area = fi * fj; double[][][] h = new double[fi][fj][fk]; for (int x = 0; x < fi; x++) { for (int y = 0; y < fj; y++) { for (int z = 0; z < fk; z++) { h[x][y][z] = f[z * area + y * fi + x]; } } } return h; } /** * Restructure {@code float[]} vector as a square {@code float[][]}. * * @param f {@code float[]} vector * @param fi first dimension of array * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] devectorise(float[] f, int fi) { final int fl = f.length; final int fj = fl / fi; float[][] h = new float[fi][fj]; for (int x = 0; x < fi; x++) { for (int y = 0; y < fj; y++) { h[x][y] = f[y * fi + x]; } } return h; } /** * Restructure {@code float[]} vector as a square {@code float[][][]}. * * @param f {@code float[]} vector * @param fi first dimension of array * @param fj second dimension of array * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] devectorise(float[] f, int fi, int fj) { final int fl = f.length; final int area = fi * fj; final int fk = fl / area; float[][][] h = new float[fi][fj][fk]; for (int x = 0; x < fi; x++) { for (int y = 0; y < fj; y++) { for (int z = 0; z < fk; z++) { h[x][y][z] = f[z * area + y * fi + x]; } } } return h; } /** * Restructure {@code Complex[]} vector as a square {@code Complex[][]}. * * @param f {@code Complex[]} vector * @param fi first dimension of array * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] devectorise(Complex[] f, int fi) { final int fl = f.length; final int fj = fl / fi; Complex[][] h = new Complex[fi][fj]; for (int x = 0; x < fi; x++) { for (int y = 0; y < fj; y++) { h[x][y] = f[y * fi + x]; } } return h; } /** * Restructure {@code Complex[]} vector as a square {@code Complex[][][]}. * * @param f {@code Complex[]} vector * @param fi first dimension of array * @param fj second dimension of array * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] devectorise(Complex[] f, int fi, int fj) { final int fl = f.length; final int area = fi * fj; final int fk = fl / (fi * fj); Complex[][][] h = new Complex[fi][fj][fk]; for (int x = 0; x < fi; x++) { for (int y = 0; y < fj; y++) { for (int z = 0; z < fk; z++) { h[x][y][z] = f[z * area + y * fi + x]; } } } return h; } // DIVIDE // -- scalar // -- -- double /** * Divides a scalar {@code double} to every element of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @param g {@code double}. * @return {@code double[]} array. * * @since 0.1 */ public static double[] divide(double[] f, double g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] /= g; } return f; } /** * Divides a scalar {@code double} to every element of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @param g {@code double}. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] divide(double[][] f, double g) { final int fi = f.length; for (int i = 0; i < fi; i++) { divide(f[i], g); } return f; } /** * Divides a scalar {@code double} to every element of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @param g {@code double}. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] divide(double[][][] f, double g) { final int fi = f.length; for (int i = 0; i < fi; i++) { divide(f[i], g); } return f; } // -- -- float /** * Divides a scalar {@code float} to every element of a {@code float[]}. Returns reference to first passed array. * * @param f {@code float[]} array. * @param g {@code float}. * @return {@code float[]} array. * * @since 0.1 */ public static float[] divide(float[] f, float g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] /= g; } return f; } /** * Divides a scalar {@code float} to every element of a {@code float[][]}. Returns reference to first passed array. * * @param f {@code float[][]} array. * @param g {@code float}. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] divide(float[][] f, float g) { final int fi = f.length; for (int i = 0; i < fi; i++) { divide(f[i], g); } return f; } /** * Divides a scalar {@code float} to every element of a {@code float[][][]}. Returns reference to first passed array. * * @param f {@code float[][][]} array. * @param g {@code float}. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] divide(float[][][] f, float g) { final int fi = f.length; for (int i = 0; i < fi; i++) { divide(f[i], g); } return f; } // -- -- Complex /** * Divides a scalar {@code Complex} to every element of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @param g {@code Complex}. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] divide(Complex[] f, Complex g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i].divide(g); } return f; } /** * Divides a scalar {@code Complex} to every element of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @param g {@code Complex}. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] divide(Complex[][] f, Complex g) { final int fi = f.length; for (int i = 0; i < fi; i++) { divide(f[i], g); } return f; } /** * Divides a scalar {@code Complex} to every element of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @param g {@code Complex}. * @return {{@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] divide(Complex[][][] f, Complex g) { final int fi = f.length; for (int i = 0; i < fi; i++) { divide(f[i], g); } return f; } // -- vector // -- -- double /** * Element-wise divide {@code double[]} by {@code double[]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code double[]} array. * @param g {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] divide(double[] f, double[] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] /= g[i]; } return f; } /** * Element-wise divide {@code double[][]} by {@code double[][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code double[][]} array. * @param g {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] divide(double[][] f, double[][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { divide(f[i], g[i]); } return f; } /** * Element-wise divide {@code double[][][]} by {@code double[][][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @param g {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] divide(double[][][] f, double[][][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { divide(f[i], g[i]); } return f; } // -- -- float /** * Element-wise divide {@code float[]} by {@code float[]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code float[]} array. * @param g {@code float[]} array. * @return {@code float[]} array. * * @since 0.1 */ public static float[] divide(float[] f, float[] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] /= g[i]; } return f; } /** * Element-wise divide {@code float[][]} by {@code float[][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code float[][]} array. * @param g {@code float[][]} array. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] divide(float[][] f, float[][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { divide(f[i], g[i]); } return f; } /** * Element-wise divide {@code float[][][]} by {@code float[][][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code float[][][]} array. * @param g {@code float[][][]} array. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] divide(float[][][] f, float[][][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { divide(f[i], g[i]); } return f; } // -- -- Complex /** * Element-wise divide {@code Complex[]} by {@code Complex[]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @param g {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] divide(Complex[] f, Complex[] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i].divide(g[i]); } return f; } /** * Element-wise divide {@code Complex[][]} by {@code Complex[][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @param g {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] divide(Complex[][] f, Complex[][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { divide(f[i], g[i]); } return f; } /** * Element-wise divide {@code Complex[][][]} by {@code Complex[][][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @param g {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] divide(Complex[][][] f, Complex[][][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { divide(f[i], g[i]); } return f; } // DIVIDEC // -- scalar // -- -- double /** * Divides a scalar {@code double} by every element of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @param g {@code double}. * @return {@code double[]} array. * * @since 0.1 */ public static double[] divideC(double[] f, double g) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] / g; } return h; } /** * Divides a scalar {@code double} by every element of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @param g {@code double}. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] divideC(double[][] f, double g) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = divideC(f[i], g); } return h; } /** * Divides a scalar {@code double} by every element of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @param g {@code double}. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] divideC(double[][][] f, double g) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = divideC(f[i], g); } return h; } // -- -- float /** * Divides a scalar {@code float} by every element of a {@code float[]}. Returns deep copy. * * @param f {@code float[]} array. * @param g {@code float}. * @return {@code float[]} array. * * @since 0.1 */ public static float[] divideC(float[] f, float g) { final int fi = f.length; float[] h = new float[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] / g; } return h; } /** * Divides a scalar {@code float} by every element of a {@code float[][]}. Returns deep copy. * * @param f {@code float[][]} array. * @param g {@code float}. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] divideC(float[][] f, float g) { final int fi = f.length; float[][] h = new float[fi][]; for (int i = 0; i < fi; i++) { h[i] = divideC(f[i], g); } return h; } /** * Divides a scalar {@code float} by every element of a {@code float[][][]}. Returns deep copy. * * @param f {@code float[][][]} array. * @param g {@code float}. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] divideC(float[][][] f, float g) { final int fi = f.length; float[][][] h = new float[fi][][]; for (int i = 0; i < fi; i++) { h[i] = divideC(f[i], g); } return h; } // -- -- Complex /** * Divides a scalar {@code Complex} by every element of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @param g {@code Complex}. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] divideC(Complex[] f, Complex g) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = new Complex(f[i].getReal(), f[i].getImaginary()).divide(g); } return h; } /** * Divides a scalar {@code Complex} by every element of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @param g {@code Complex}. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] divideC(Complex[][] f, Complex g) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = divideC(f[i], g); } return h; } /** * Divides a scalar {@code Complex} by every element of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @param g {@code Complex}. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] divideC(Complex[][][] f, Complex g) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = divideC(f[i], g); } return h; } // -- vector // -- -- double /** * Element-wise divide {@code double[]} by {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @param g {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] divideC(double[] f, double[] g) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] / g[i]; } return h; } /** * Element-wise divide {@code double[][]} by {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @param g {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] divideC(double[][] f, double[][] g) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = divideC(f[i], g[i]); } return h; } /** * Element-wise divide {@code double[][][]} by {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @param g {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] divideC(double[][][] f, double[][][] g) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = divideC(f[i], g[i]); } return h; } // -- -- float /** * Element-wise divide {@code float[]} by {@code float[]}. Returns deep copy. * * @param f {@code float[]} array. * @param g {@code float[]} array. * @return {@code float[]} array. * * @since 0.1 */ public static float[] divideC(float[] f, float[] g) { final int fi = f.length; float[] h = new float[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] / g[i]; } return h; } /** * Element-wise divide {@code float[][]} by {@code float[][]}. Returns deep copy. * * @param f {@code float[][]} array. * @param g {@code float[][]} array. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] divideC(float[][] f, float[][] g) { final int fi = f.length; float[][] h = new float[fi][]; for (int i = 0; i < fi; i++) { h[i] = divideC(f[i], g[i]); } return h; } /** * Element-wise divide {@code float[][][]} by {@code float[][][]}. Returns deep copy. * * @param f {@code float[][][]} array. * @param g {@code float[][][]} array. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] divideC(float[][][] f, float[][][] g) { final int fi = f.length; float[][][] h = new float[fi][][]; for (int i = 0; i < fi; i++) { h[i] = divideC(f[i], g[i]); } return h; } // -- -- Complex /** * Element-wise divide {@code Complex[]} by {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @param g {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] divideC(Complex[] f, Complex[] g) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = new Complex(f[i].getReal(), f[i].getImaginary()).divide(g[i]); } return h; } /** * Element-wise divide {@code Complex[][]} by {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @param g {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] divideC(Complex[][] f, Complex[][] g) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = divideC(f[i], g[i]); } return h; } /** * Element-wise divide {@code Complex[][][]} by {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @param g {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] divideC(Complex[][][] f, Complex[][][] g) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = divideC(f[i], g[i]); } return h; } // DOUBLE2FLOAT /** * Convert {@code float[]} array to {@code double[]}. * * @param f {@code float[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static float[] double2Float(double[] f) { final int fi = f.length; float[] h = new float[fi]; for (int i = 0; i < fi; i++) { h[i] = (float) f[i]; } return h; } /** * Convert {@code float[][]} array to {@code double[][]}. * * @param f {@code float[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static float[][] double2Float(double[][] f) { final int fi = f.length; float[][] h = new float[fi][]; for (int i = 0; i < fi; i++) { h[i] = double2Float(f[i]); } return h; } /** * Convert {@code float[][][]} array to {@code double[][][]}. * * @param f {@code float[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static float[][][] double2Float(double[][][] f) { final int fi = f.length; float[][][] h = new float[fi][][]; for (int i = 0; i < fi; i++) { h[i] = double2Float(f[i]); } return h; } // FLOAT2DOUBLE /** * Convert {@code float[]} array to {@code double[]}. * * @param f {@code float[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] float2Double(float[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i]; } return h; } /** * Convert {@code float[][]} array to {@code double[][]}. * * @param f {@code float[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] float2Double(float[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = float2Double(f[i]); } return h; } /** * Convert {@code float[][][]} array to {@code double[][][]}. * * @param f {@code float[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] float2Double(float[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = float2Double(f[i]); } return h; } // FLOOR // -- double /** * In-place element-wise {@code floor} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[] array} * * @since 0.1 */ public static double[] floor(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.floor(f[i]); } return f; } /** * In-place element-wise {@code floor} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][] array} * * @since 0.1 */ public static double[][] floor(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { floor(f[i]); } return f; } /** * In-place element-wise {@code floor} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] floor(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { floor(f[i]); } return f; } // FLOORC // -- double /** * Element-wise {@code floor} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] floorC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.floor(f[i]); } return h; } /** * Element-wise {@code floor} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] floorC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = floorC(f[i]); } return h; } /** * Element-wise {@code floor} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] floorC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = floorC(f[i]); } return h; } // GRADIENT /** * Returns a {@code double[]} containing a 1D gradient, starting value 1. * * @param fi {@code int} array dimension. * @return {@code double[]} array. * * @since 0.1 */ public static double[] gradient(int fi) { double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = i; } return h; } /** * Returns a square {@code double[][]} containing a 2D gradient. * * @param fi {@code int} dimension of first array. * @param fj {@code int} dimension of second array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] gradient(int fi, int fj) { double[][] h = new double[fi][fj]; for (int i = 0; i < fi; i++) { for (int j = 0; j < fj; j++) { h[i][j] = i + j; } } return h; } /** * Returns a square {@code double[][][]} containing a 3D gradient. * * @param fi {@code int} dimension of first level array. * @param fj {@code int} dimension of second level array. * @param fk {@code int} dimension of third level array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] gradient(int fi, int fj, int fk) { double[][][] h = new double[fi][fj][fk]; for (int i = 0; i < fi; i++) { for (int j = 0; j < fj; j++) { for (int k = 0; k < fk; k++) { h[i][j][k] = i + j + k; } } } return h; } // LOG // -- double /** * In-place element-wise {@code log} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] log(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.log(f[i]); } return f; } /** * In-place element-wise {@code log} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] log(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { log(f[i]); } return f; } /** * In-place element-wise {@code log} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] log(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { log(f[i]); } return f; } // -- Complex /** * In-place element-wise {@code log} of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] log(Complex[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = f[i].log(); } return f; } /** * In-place element-wise {@code log} of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] log(Complex[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { log(f[i]); } return f; } /** * In-place element-wise {@code log} of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] log(Complex[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { log(f[i]); } return f; } // LOGC // -- double /** * Element-wise {@code log} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] logC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.log(f[i]); } return h; } /** * Element-wise {@code log} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] logC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = logC(f[i]); } return h; } /** * Element-wise {@code log} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] logC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = logC(f[i]); } return h; } // -- Complex /** * Element-wise {@code log} of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] logC(Complex[] f) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i].log(); } return h; } /** * Element-wise {@code log} of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] logC(Complex[][] f) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = logC(f[i]); } return h; } /** * Element-wise {@code log} of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] logC(Complex[][][] f) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = logC(f[i]); } return h; } // MULTIPLY // -- scalar // -- -- double /** * Multiplies a scalar {@code double} to every element of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @param g {@code double}. * @return {@code double[]} array. * * @since 0.1 */ public static double[] multiply(double[] f, double g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] *= g; } return f; } /** * Multiplies a scalar {@code double} to every element of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @param g {@code double}. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] multiply(double[][] f, double g) { final int fi = f.length; for (int i = 0; i < fi; i++) { multiply(f[i], g); } return f; } /** * Multiplies a scalar {@code double} to every element of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @param g {@code double}. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] multiply(double[][][] f, double g) { final int fi = f.length; for (int i = 0; i < fi; i++) { multiply(f[i], g); } return f; } // -- -- float /** * Multiplies a scalar {@code float} to every element of a {@code float[]}. Returns reference to first passed array. * * @param f {@code float[]} array. * @param g {@code float}. * @return {@code float[]} array. * * @since 0.1 */ public static float[] multiply(float[] f, float g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] *= g; } return f; } /** * Multiplies a scalar {@code float} to every element of a {@code float[][]}. Returns reference to first passed array. * * @param f {@code float[][]} array. * @param g {@code float}. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] multiply(float[][] f, float g) { final int fi = f.length; for (int i = 0; i < fi; i++) { multiply(f[i], g); } return f; } /** * Multiplies a scalar {@code float} to every element of a {@code float[][][]}. Returns reference to first passed array. * * @param f {@code float[][][]} array. * @param g {@code float}. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] multiply(float[][][] f, float g) { final int fi = f.length; for (int i = 0; i < fi; i++) { multiply(f[i], g); } return f; } // -- -- Complex /** * Multiplies a scalar {@code Complex} to every element of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @param g {@code Complex}. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] multiply(Complex[] f, Complex g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i].multiply(g); } return f; } /** * Multiplies a scalar {@code Complex} to every element of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @param g {@code Complex}. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] multiply(Complex[][] f, Complex g) { final int fi = f.length; for (int i = 0; i < fi; i++) { multiply(f[i], g); } return f; } /** * Multiplies a scalar {@code Complex} to every element of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @param g {@code Complex}. * @return {{@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] multiply(Complex[][][] f, Complex g) { final int fi = f.length; for (int i = 0; i < fi; i++) { multiply(f[i], g); } return f; } // -- vector // -- -- double /** * Element-wise multiply {@code double[]} by {@code double[]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code double[]} array. * @param g {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] multiply(double[] f, double[] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] *= g[i]; } return f; } /** * Element-wise multiply {@code double[][]} by {@code double[][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code double[][]} array. * @param g {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] multiply(double[][] f, double[][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { multiply(f[i], g[i]); } return f; } /** * Element-wise multiply {@code double[][][]} by {@code double[][][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @param g {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] multiply(double[][][] f, double[][][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { multiply(f[i], g[i]); } return f; } // -- -- float /** * Element-wise multiply {@code float[]} by {@code float[]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code float[]} array. * @param g {@code float[]} array. * @return {@code float[]} array. * * @since 0.1 */ public static float[] multiply(float[] f, float[] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] *= g[i]; } return f; } /** * Element-wise multiply {@code float[][]} by {@code float[][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code float[][]} array. * @param g {@code float[][]} array. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] multiply(float[][] f, float[][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { multiply(f[i], g[i]); } return f; } /** * Element-wise multiply {@code float[][][]} by {@code float[][][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code float[][][]} array. * @param g {@code float[][][]} array. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] multiply(float[][][] f, float[][][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { multiply(f[i], g[i]); } return f; } // -- -- Complex /** * Element-wise multiply {@code Complex[]} by {@code Complex[]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @param g {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] multiply(Complex[] f, Complex[] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i].multiply(g[i]); } return f; } /** * Element-wise multiply {@code Complex[][]} by {@code Complex[][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @param g {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] multiply(Complex[][] f, Complex[][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { multiply(f[i], g[i]); } return f; } /** * Element-wise multiply {@code Complex[][][]} by {@code Complex[][][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @param g {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] multiply(Complex[][][] f, Complex[][][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { multiply(f[i], g[i]); } return f; } // MULTIPLYC // -- scalar // -- -- double /** * Multiplies a scalar {@code double} by every element of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @param g {@code double}. * @return {@code double[]} array. * * @since 0.1 */ public static double[] multiplyC(double[] f, double g) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] * g; } return h; } /** * Multiplies a scalar {@code double} by every element of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @param g {@code double}. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] multiplyC(double[][] f, double g) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = multiplyC(f[i], g); } return h; } /** * Multiplies a scalar {@code double} by every element of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @param g {@code double}. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] multiplyC(double[][][] f, double g) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = multiplyC(f[i], g); } return h; } // -- -- float /** * Multiplies a scalar {@code float} by every element of a {@code float[]}. Returns deep copy. * * @param f {@code float[]} array. * @param g {@code float}. * @return {@code float[]} array. * * @since 0.1 */ public static float[] multiplyC(float[] f, float g) { final int fi = f.length; float[] h = new float[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] * g; } return h; } /** * Multiplies a scalar {@code float} by every element of a {@code float[][]}. Returns deep copy. * * @param f {@code float[][]} array. * @param g {@code float}. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] multiplyC(float[][] f, float g) { final int fi = f.length; float[][] h = new float[fi][]; for (int i = 0; i < fi; i++) { h[i] = multiplyC(f[i], g); } return h; } /** * Multiplies a scalar {@code float} by every element of a {@code float[][][]}. Returns deep copy. * * @param f {@code float[][][]} array. * @param g {@code float}. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] multiplyC(float[][][] f, float g) { final int fi = f.length; float[][][] h = new float[fi][][]; for (int i = 0; i < fi; i++) { h[i] = multiplyC(f[i], g); } return h; } // -- -- Complex /** * Multiplies a scalar {@code Complex} by every element of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @param g {@code Complex}. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] multiplyC(Complex[] f, Complex g) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = new Complex(f[i].getReal(), f[i].getImaginary()).multiply(g); } return h; } /** * Multiplies a scalar {@code Complex} by every element of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @param g {@code Complex}. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] multiplyC(Complex[][] f, Complex g) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = multiplyC(f[i], g); } return h; } /** * Multiplies a scalar {@code Complex} by every element of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @param g {@code Complex}. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] multiplyC(Complex[][][] f, Complex g) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = multiplyC(f[i], g); } return h; } // -- vector // -- -- double /** * Element-wise multiply {@code double[]} by {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @param g {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] multiplyC(double[] f, double[] g) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] * g[i]; } return h; } /** * Element-wise multiply {@code double[][]} by {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @param g {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] multiplyC(double[][] f, double[][] g) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = multiplyC(f[i], g[i]); } return h; } /** * Element-wise multiply {@code double[][][]} by {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @param g {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] multiplyC(double[][][] f, double[][][] g) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = multiplyC(f[i], g[i]); } return h; } // -- -- float /** * Element-wise multiply {@code float[]} by {@code float[]}. Returns deep copy. * * @param f {@code float[]} array. * @param g {@code float[]} array. * @return {@code float[]} array. * * @since 0.1 */ public static float[] multiplyC(float[] f, float[] g) { final int fi = f.length; float[] h = new float[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] * g[i]; } return h; } /** * Element-wise multiply {@code float[][]} by {@code float[][]}. Returns deep copy. * * @param f {@code float[][]} array. * @param g {@code float[][]} array. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] multiplyC(float[][] f, float[][] g) { final int fi = f.length; float[][] h = new float[fi][]; for (int i = 0; i < fi; i++) { h[i] = multiplyC(f[i], g[i]); } return h; } /** * Element-wise multiply {@code float[][][]} by {@code float[][][]}. Returns deep copy. * * @param f {@code float[][][]} array. * @param g {@code float[][][]} array. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] multiplyC(float[][][] f, float[][][] g) { final int fi = f.length; float[][][] h = new float[fi][][]; for (int i = 0; i < fi; i++) { h[i] = multiplyC(f[i], g[i]); } return h; } // -- -- Complex /** * Element-wise multiply {@code Complex[]} by {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @param g {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] multiplyC(Complex[] f, Complex[] g) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = new Complex(f[i].getReal(), f[i].getImaginary()).multiply(g[i]); } return h; } /** * Element-wise multiply {@code Complex[][]} by {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @param g {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] multiplyC(Complex[][] f, Complex[][] g) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = multiplyC(f[i], g[i]); } return h; } /** * Element-wise multiply {@code Complex[][][]} by {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @param g {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] multiplyC(Complex[][][] f, Complex[][][] g) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = multiplyC(f[i], g[i]); } return h; } // ONES /** * Returns a {@code double[]} containing ones of specified dimension. * * @param fi {@code int} array dimension. * @return {@code double[]} array. * * @since 0.1 */ public static double[] ones(int fi) { double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = 1; } return h; } /** * Returns a square {@code double[][]} containing ones of specified dimension. * * @param fi {@code int} dimension of first array. * @param fj {@code int} dimension of second array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] ones(int fi, int fj) { double[][] h = new double[fi][fj]; for (int i = 0; i < fi; i++) { h[i] = ones(fj); } return h; } /** * Returns a square {@code double[][][]} containing ones of specified dimension. * * @param fi {@code int} dimension of first level array. * @param fj {@code int} dimension of second level array. * @param fk {@code int} dimension of third level array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] ones(int fi, int fj, int fk) { double[][][] h = new double[fi][fj][fk]; for (int i = 0; i < fi; i++) { h[i] = ones(fj, fk); } return h; } // RANDOM /** * Returns a {@code double[]} containing uniform distribution Random values. * * @param fi {@code int} array dimension. * @return {@code double[]} array. * * @since 0.1 */ public static double[] random(int fi) { double[] h = new double[fi]; Random r = new Random(); for (int i = 0; i < fi; i++) { h[i] = r.nextDouble(); } return h; } /** * Returns a square {@code double[][]} containing uniform distribution Random values. * * @param fi {@code int} dimension of first array. * @param fj {@code int} dimension of second array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] random(int fi, int fj) { double[][] h = new double[fi][fj]; Random r = new Random(); for (int i = 0; i < fi; i++) { for (int j = 0; j < fj; j++) { h[i][j] = r.nextDouble(); } } return h; } /** * Returns a square {@code double[][][]} containing uniform distribution Random values. * * @param fi {@code int} dimension of first level array. * @param fj {@code int} dimension of second level array. * @param fk {@code int} dimension of third level array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] random(int fi, int fj, int fk) { double[][][] h = new double[fi][fj][fk]; Random r = new Random(); for (int i = 0; i < fi; i++) { for (int j = 0; j < fj; j++) { for (int k = 0; k < fk; k++) { h[i][j][k] = r.nextDouble(); } } } return h; } // RECIPROCAL // -- double /** * In-place element-wise {@code reciprocal} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] reciprocal(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = 1.0 / f[i]; } return f; } /** * In-place element-wise {@code reciprocal} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] reciprocal(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { reciprocal(f[i]); } return f; } /** * In-place element-wise {@code reciprocal} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] reciprocal(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { reciprocal(f[i]); } return f; } // -- Complex /** * In-place element-wise {@code reciprocal} of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] reciprocal(Complex[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = f[i].reciprocal(); } return f; } /** * In-place element-wise {@code reciprocal} of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] reciprocal(Complex[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { reciprocal(f[i]); } return f; } /** * In-place element-wise {@code reciprocal} of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] reciprocal(Complex[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { reciprocal(f[i]); } return f; } // RECIPROCALC // -- double /** * Element-wise {@code reciprocal} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] reciprocalC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = 1.0 / f[i]; } return h; } /** * Element-wise {@code reciprocal} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] reciprocalC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = reciprocalC(f[i]); } return h; } /** * Element-wise {@code reciprocal} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] reciprocalC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = reciprocalC(f[i]); } return h; } // -- Complex /** * Element-wise {@code reciprocal} of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] reciprocalC(Complex[] f) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i].reciprocal(); } return h; } /** * Element-wise {@code reciprocal} of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] reciprocalC(Complex[][] f) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { reciprocalC(f[i]); } return h; } /** * Element-wise {@code reciprocal} of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] reciprocalC(Complex[][][] f) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { reciprocalC(f[i]); } return h; } // ROUND // -- double /** * In-place element-wise {@code round} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] round(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.round(f[i]); } return f; } /** * In-place element-wise {@code round} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] round(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { round(f[i]); } return f; } /** * In-place element-wise {@code round} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] round(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { round(f[i]); } return f; } // ROUNDC // -- double /** * Element-wise {@code round} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] roundC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.round(f[i]); } return h; } /** * Element-wise {@code round} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] roundC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = roundC(f[i]); } return h; } /** * Element-wise {@code round} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] roundC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = roundC(f[i]); } return h; } // SECOND ORDER /** * Returns a {@code double[]} containing a squared gradient, starting value 1. * * @param fi {@code int} array dimension. * @return {@code double[]} array. * * @since 0.1 */ public static double[] secondOrder(int fi) { double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = i * i; } return h; } /** * Returns a square {@code double[][]} containing a 2D squared gradient. * * @param fi {@code int} dimension of first array. * @param fj {@code int} dimension of second array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] secondOrder(int fi, int fj) { double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { for (int j = 0; j < fj; j++) { h[i][j] = i * i + j * j; } } return h; } /** * Returns a square {@code double[][][]} containing a 3D squared gradient. * * @param fi {@code int} dimension of first level array. * @param fj {@code int} dimension of second level array. * @param fk {@code int} dimension of third level array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] secondOrder(int fi, int fj, int fk) { double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { for (int j = 0; j < fj; j++) { for (int k = 0; k < fk; k++) { h[i][j][k] = i * i + j * j + k * k; } } } return h; } // SIN // -- double /** * In-place element-wise {@code sin} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] sin(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.sin(f[i]); } return f; } /** * In-place element-wise {@code sin} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] sin(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { sin(f[i]); } return f; } /** * In-place element-wise {@code sin} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] sin(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { sin(f[i]); } return f; } // -- Complex /** * In-place element-wise {@code sin} of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] sin(Complex[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = f[i].sin(); } return f; } /** * In-place element-wise {@code sin} of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] sin(Complex[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { sin(f[i]); } return f; } /** * In-place element-wise {@code sin} of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] sin(Complex[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { sin(f[i]); } return f; } // SINC // -- double /** * Element-wise {@code sin} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] sinC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.sin(f[i]); } return h; } /** * Element-wise {@code sin} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] sinC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = sinC(f[i]); } return h; } /** * Element-wise {@code sin} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] sinC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = sinC(f[i]); } return h; } // -- Complex /** * Element-wise {@code sin} of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] sinC(Complex[] f) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i].sin(); } return h; } /** * Element-wise {@code sin} of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] sinC(Complex[][] f) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = sinC(f[i]); } return h; } /** * Element-wise {@code sin} of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] sinC(Complex[][][] f) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = sinC(f[i]); } return h; } // SINH // -- double /** * In-place element-wise {@code sinh} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] sinh(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.sinh(f[i]); } return f; } /** * In-place element-wise {@code sinh} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] sinh(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { sinh(f[i]); } return f; } /** * In-place element-wise {@code sinh} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] sinh(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { sinh(f[i]); } return f; } // -- Complex /** * In-place element-wise {@code sinh} of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] sinh(Complex[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = f[i].sinh(); } return f; } /** * In-place element-wise {@code sinh} of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] sinh(Complex[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { sinh(f[i]); } return f; } /** * In-place element-wise {@code sinh} of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] sinh(Complex[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { sinh(f[i]); } return f; } // SINHC // -- double /** * Element-wise {@code sinh} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] sinhC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.sinh(f[i]); } return h; } /** * Element-wise {@code sinh} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] sinhC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = sinhC(f[i]); } return h; } /** * Element-wise {@code sinh} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] sinhC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = sinhC(f[i]); } return h; } // -- Complex /** * Element-wise {@code sinh} of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] sinhC(Complex[] f) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i].sinh(); } return h; } /** * Element-wise {@code sinh} of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] sinhC(Complex[][] f) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = sinhC(f[i]); } return h; } /** * Element-wise {@code sinh} of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] sinhC(Complex[][][] f) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = sinhC(f[i]); } return h; } // SQRT // -- double /** * In-place element-wise {@code sqrt} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] sqrt(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.sqrt(f[i]); } return f; } /** * In-place element-wise {@code sqrt} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] sqrt(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { sqrt(f[i]); } return f; } /** * In-place element-wise {@code sqrt} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] sqrt(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { sqrt(f[i]); } return f; } // -- Complex /** * In-place element-wise {@code sqrt} of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] sqrt(Complex[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = f[i].sqrt(); } return f; } /** * In-place element-wise {@code sqrt} of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] sqrt(Complex[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { sqrt(f[i]); } return f; } /** * In-place element-wise {@code sqrt} of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] sqrt(Complex[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { sqrt(f[i]); } return f; } // SQRTC // -- double /** * Element-wise {@code sqrt} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] sqrtC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] * f[i]; } return h; } /** * Element-wise {@code sqrt} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] sqrtC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = sqrtC(f[i]); } return h; } /** * Element-wise {@code sqrt} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] sqrtC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = sqrtC(f[i]); } return h; } // -- Complex /** * Element-wise {@code sqrt} of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] sqrtC(Complex[] f) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i].multiply(f[i]); } return h; } /** * Element-wise {@code sqrt} of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] sqrtC(Complex[][] f) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { sqrtC(f[i]); } return h; } /** * Element-wise {@code sqrt} of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] sqrtC(Complex[][][] f) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { sqrtC(f[i]); } return h; } // SQUARE // -- double /** * In-place element-wise {@code square} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] square(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] *= f[i]; } return f; } /** * In-place element-wise {@code square} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] square(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { square(f[i]); } return f; } /** * In-place element-wise {@code square} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] square(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { square(f[i]); } return f; } // -- Complex /** * In-place element-wise {@code square} of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] square(Complex[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = f[i].multiply(f[i]); } return f; } /** * In-place element-wise {@code square} of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] square(Complex[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { square(f[i]); } return f; } /** * In-place element-wise {@code square} of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] square(Complex[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { square(f[i]); } return f; } // SQUAREC // -- double /** * Element-wise {@code square} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] squareC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] * f[i]; } return h; } /** * Element-wise {@code square} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] squareC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = squareC(f[i]); } return h; } /** * Element-wise {@code square} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] squareC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = squareC(f[i]); } return h; } // -- Complex /** * Element-wise {@code square} of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] squareC(Complex[] f) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i].multiply(f[i]); } return h; } /** * Element-wise {@code square} of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] squareC(Complex[][] f) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { squareC(f[i]); } return h; } /** * Element-wise {@code square} of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] squareC(Complex[][][] f) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { squareC(f[i]); } return h; } /** * Sum of a {@code double[]}. * * @param f {@code double[]} array. * @return sum of the array as a {@code double}. * * @since 0.1 */ public static double sum(double[] f) { final int fi = f.length; double sum = 0; for (int i = 0; i < fi; i++) { sum += f[i]; } return sum; } /** * Sum of a {@code double[][]}. * * @param f {@code double[][]} array. * @return sum of the array as a {@code double}. * * @since 0.1 */ public static double sum(double[][] f) { final int fi = f.length; double sum = 0; for (int i = 0; i < fi; i++) { sum += sum(f[i]); } return sum; } /** * Sum of a {@code double[][][]}. * * @param f {@code double[][][]} array. * @return sum of the array as a {@code double}. * * @since 0.1 */ public static double sum(double[][][] f) { final int fi = f.length; double sum = 0; for (int i = 0; i < fi; i++) { sum += sum(f[i]); } return sum; } // SUBTRACT // -- scalar // -- -- double /** * Subtracts a scalar {@code double} to every element of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @param g {@code double}. * @return {@code double[]} array. * * @since 0.1 */ public static double[] subtract(double[] f, double g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] -= g; } return f; } /** * Subtracts a scalar {@code double} to every element of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @param g {@code double}. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] subtract(double[][] f, double g) { final int fi = f.length; for (int i = 0; i < fi; i++) { subtract(f[i], g); } return f; } /** * Subtracts a scalar {@code double} to every element of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @param g {@code double}. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] subtract(double[][][] f, double g) { final int fi = f.length; for (int i = 0; i < fi; i++) { subtract(f[i], g); } return f; } // -- -- float /** * Subtracts a scalar {@code float} to every element of a {@code float[]}. Returns reference to first passed array. * * @param f {@code float[]} array. * @param g {@code float}. * @return {@code float[]} array. * * @since 0.1 */ public static float[] subtract(float[] f, float g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] -= g; } return f; } /** * Subtracts a scalar {@code float} to every element of a {@code float[][]}. Returns reference to first passed array. * * @param f {@code float[][]} array. * @param g {@code float}. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] subtract(float[][] f, float g) { final int fi = f.length; for (int i = 0; i < fi; i++) { subtract(f[i], g); } return f; } /** * Subtracts a scalar {@code float} to every element of a {@code float[][][]}. Returns reference to first passed array. * * @param f {@code float[][][]} array. * @param g {@code float}. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] subtract(float[][][] f, float g) { final int fi = f.length; for (int i = 0; i < fi; i++) { subtract(f[i], g); } return f; } // -- -- Complex /** * Subtracts a scalar {@code Complex} to every element of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @param g {@code Complex}. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] subtract(Complex[] f, Complex g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i].subtract(g); } return f; } /** * Subtracts a scalar {@code Complex} to every element of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @param g {@code Complex}. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] subtract(Complex[][] f, Complex g) { final int fi = f.length; for (int i = 0; i < fi; i++) { subtract(f[i], g); } return f; } /** * Subtracts a scalar {@code Complex} to every element of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @param g {@code Complex}. * @return {{@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] subtract(Complex[][][] f, Complex g) { final int fi = f.length; for (int i = 0; i < fi; i++) { subtract(f[i], g); } return f; } // -- vector // -- -- double /** * Element-wise subtract {@code double[]} from {@code double[]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code double[]} array. * @param g {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] subtract(double[] f, double[] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] -= g[i]; } return f; } /** * Element-wise subtract {@code double[][]} from {@code double[][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code double[][]} array. * @param g {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] subtract(double[][] f, double[][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { subtract(f[i], g[i]); } return f; } /** * Element-wise subtract {@code double[][][]} from {@code double[][][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @param g {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] subtract(double[][][] f, double[][][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { subtract(f[i], g[i]); } return f; } // -- -- float /** * Element-wise subtract {@code float[]} from {@code float[]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code float[]} array. * @param g {@code float[]} array. * @return {@code float[]} array. * * @since 0.1 */ public static float[] subtract(float[] f, float[] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] -= g[i]; } return f; } /** * Element-wise subtract {@code float[][]} from {@code float[][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code float[][]} array. * @param g {@code float[][]} array. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] subtract(float[][] f, float[][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { subtract(f[i], g[i]); } return f; } /** * Element-wise subtract {@code float[][][]} from {@code float[][][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code float[][][]} array. * @param g {@code float[][][]} array. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] subtract(float[][][] f, float[][][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { subtract(f[i], g[i]); } return f; } // -- -- Complex /** * Element-wise subtract {@code Complex[]} from {@code Complex[]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @param g {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] subtract(Complex[] f, Complex[] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i].subtract(g[i]); } return f; } /** * Element-wise subtract {@code Complex[][]} from {@code Complex[][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @param g {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] subtract(Complex[][] f, Complex[][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { subtract(f[i], g[i]); } return f; } /** * Element-wise subtract {@code Complex[][][]} from {@code Complex[][][]} in place. Changes impact array f. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @param g {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] subtract(Complex[][][] f, Complex[][][] g) { final int fi = f.length; for (int i = 0; i < fi; i++) { subtract(f[i], g[i]); } return f; } // SUBTRACTC // -- scalar // -- -- double /** * subtracts a scalar {@code double} to every element of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @param g {@code double}. * @return {@code double[]} array. * * @since 0.1 */ public static double[] subtractC(double[] f, double g) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] - g; } return h; } /** * subtracts a scalar {@code double} to every element of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @param g {@code double}. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] subtractC(double[][] f, double g) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = subtractC(f[i], g); } return h; } /** * subtracts a scalar {@code double} to every element of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @param g {@code double}. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] subtractC(double[][][] f, double g) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = subtractC(f[i], g); } return h; } // -- -- float /** * subtracts a scalar {@code float} to every element of a {@code float[]}. Returns deep copy. * * @param f {@code float[]} array. * @param g {@code float}. * @return {@code float[]} array. * * @since 0.1 */ public static float[] subtractC(float[] f, float g) { final int fi = f.length; float[] h = new float[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] - g; } return h; } /** * subtracts a scalar {@code float} to every element of a {@code float[][]}. Returns deep copy. * * @param f {@code float[][]} array. * @param g {@code float}. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] subtractC(float[][] f, float g) { final int fi = f.length; float[][] h = new float[fi][]; for (int i = 0; i < fi; i++) { h[i] = subtractC(f[i], g); } return h; } /** * subtracts a scalar {@code float} to every element of a {@code float[][][]}. Returns deep copy. * * @param f {@code float[][][]} array. * @param g {@code float}. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] subtractC(float[][][] f, float g) { final int fi = f.length; float[][][] h = new float[fi][][]; for (int i = 0; i < fi; i++) { h[i] = subtractC(f[i], g); } return h; } // -- -- Complex /** * subtracts a scalar {@code Complex} to every element of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @param g {@code Complex}. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] subtractC(Complex[] f, Complex g) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = new Complex(f[i].getReal(), f[i].getImaginary()).subtract(g); } return h; } /** * subtracts a scalar {@code Complex} to every element of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @param g {@code Complex}. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] subtractC(Complex[][] f, Complex g) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = subtractC(f[i], g); } return h; } /** * subtracts a scalar {@code Complex} to every element of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @param g {@code Complex}. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] subtractC(Complex[][][] f, Complex g) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = subtractC(f[i], g); } return h; } // -- vector // -- -- double /** * Element-wise subtract {@code double[]} to {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @param g {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] subtractC(double[] f, double[] g) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] - g[i]; } return h; } /** * Element-wise subtract {@code double[][]} to {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @param g {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] subtractC(double[][] f, double[][] g) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = subtractC(f[i], g[i]); } return h; } /** * Element-wise subtract {@code double[][][]} to {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @param g {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] subtractC(double[][][] f, double[][][] g) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = subtractC(f[i], g[i]); } return h; } // -- -- float /** * Element-wise subtract {@code float[]} to {@code float[]}. Returns deep copy. * * @param f {@code float[]} array. * @param g {@code float[]} array. * @return {@code float[]} array. * * @since 0.1 */ public static float[] subtractC(float[] f, float[] g) { final int fi = f.length; float[] h = new float[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i] - g[i]; } return h; } /** * Element-wise subtract {@code float[][]} to {@code float[][]}. Returns deep copy. * * @param f {@code float[][]} array. * @param g {@code float[][]} array. * @return {@code float[][]} array. * * @since 0.1 */ public static float[][] subtractC(float[][] f, float[][] g) { final int fi = f.length; float[][] h = new float[fi][]; for (int i = 0; i < fi; i++) { h[i] = subtractC(f[i], g[i]); } return h; } /** * Element-wise subtract {@code float[][][]} to {@code float[][][]}. Returns deep copy. * * @param f {@code float[][][]} array. * @param g {@code float[][][]} array. * @return {@code float[][][]} array. * * @since 0.1 */ public static float[][][] subtractC(float[][][] f, float[][][] g) { final int fi = f.length; float[][][] h = new float[fi][][]; for (int i = 0; i < fi; i++) { h[i] = subtractC(f[i], g[i]); } return h; } // -- -- Complex /** * Element-wise subtract {@code Complex[]} to {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @param g {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] subtractC(Complex[] f, Complex[] g) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = new Complex(f[i].getReal(), f[i].getImaginary()).subtract(g[i]); } return h; } /** * Element-wise subtract {@code Complex[][]} to {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @param g {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] subtractC(Complex[][] f, Complex[][] g) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = subtractC(f[i], g[i]); } return h; } /** * Element-wise subtract {@code Complex[][][]} to {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @param g {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] subtractC(Complex[][][] f, Complex[][][] g) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = subtractC(f[i], g[i]); } return h; } // TAN // -- double /** * In-place element-wise {@code tan} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] tan(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.tan(f[i]); } return f; } /** * In-place element-wise {@code tan} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] tan(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { tan(f[i]); } return f; } /** * In-place element-wise {@code tan} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] tan(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { tan(f[i]); } return f; } // -- Complex /** * In-place element-wise {@code tan} of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] tan(Complex[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = f[i].tan(); } return f; } /** * In-place element-wise {@code tan} of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] tan(Complex[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { tan(f[i]); } return f; } /** * In-place element-wise {@code tan} of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] tan(Complex[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { tan(f[i]); } return f; } // TANC // -- double /** * Element-wise {@code tan} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] tanC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.tan(f[i]); } return h; } /** * Element-wise {@code tan} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] tanC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = tanC(f[i]); } return h; } /** * Element-wise {@code tan} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] tanC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = tanC(f[i]); } return h; } // -- Complex /** * Element-wise {@code tan} of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] tanC(Complex[] f) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i].tan(); } return h; } /** * Element-wise {@code tan} of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] tanC(Complex[][] f) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = tanC(f[i]); } return h; } /** * Element-wise {@code tan} of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] tanC(Complex[][][] f) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = tanC(f[i]); } return h; } // TANH // -- double /** * In-place element-wise {@code tanh} of a {@code double[]}. Returns reference to first passed array. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] tanh(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.tanh(f[i]); } return f; } /** * In-place element-wise {@code tanh} of a {@code double[][]}. Returns reference to first passed array. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] tanh(double[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { tanh(f[i]); } return f; } /** * In-place element-wise {@code tanh} of a {@code double[][][]}. Returns reference to first passed array. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] tanh(double[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { tanh(f[i]); } return f; } // -- Complex /** * In-place element-wise {@code tanh} of a {@code Complex[]}. Returns reference to first passed array. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] tanh(Complex[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = f[i].tanh(); } return f; } /** * In-place element-wise {@code tanh} of a {@code Complex[][]}. Returns reference to first passed array. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] tanh(Complex[][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { tanh(f[i]); } return f; } /** * In-place element-wise {@code tanh} of a {@code Complex[][][]}. Returns reference to first passed array. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] tanh(Complex[][][] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { tanh(f[i]); } return f; } // TANHC // -- double /** * Element-wise {@code tanh} of a {@code double[]}. Returns deep copy. * * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] tanhC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.tanh(f[i]); } return h; } /** * Element-wise {@code tanh} of a {@code double[][]}. Returns deep copy. * * @param f {@code double[][]} array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] tanhC(double[][] f) { final int fi = f.length; double[][] h = new double[fi][]; for (int i = 0; i < fi; i++) { h[i] = tanhC(f[i]); } return h; } /** * Element-wise {@code tanh} of a {@code double[][][]}. Returns deep copy. * * @param f {@code double[][][]} array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] tanhC(double[][][] f) { final int fi = f.length; double[][][] h = new double[fi][][]; for (int i = 0; i < fi; i++) { h[i] = tanhC(f[i]); } return h; } // -- Complex /** * Element-wise {@code tanh} of a {@code Complex[]}. Returns deep copy. * * @param f {@code Complex[]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] tanhC(Complex[] f) { final int fi = f.length; Complex[] h = new Complex[fi]; for (int i = 0; i < fi; i++) { h[i] = f[i].tanh(); } return h; } /** * Element-wise {@code tanh} of a {@code Complex[][]}. Returns deep copy. * * @param f {@code Complex[][]} array. * @return {@code Complex[][]} array. * * @since 0.1 */ public static Complex[][] tanhC(Complex[][] f) { final int fi = f.length; Complex[][] h = new Complex[fi][]; for (int i = 0; i < fi; i++) { h[i] = tanhC(f[i]); } return h; } /** * Element-wise {@code tanh} of a {@code Complex[][][]}. Returns deep copy. * * @param f {@code Complex[][][]} array. * @return {@code Complex[][][]} array. * * @since 0.1 */ public static Complex[][][] tanhC(Complex[][][] f) { final int fi = f.length; Complex[][][] h = new Complex[fi][][]; for (int i = 0; i < fi; i++) { h[i] = tanhC(f[i]); } return h; } // VECTORISE /** * Restructure square {@code double[][]} as a {@code double[]}. * * @param f {@code double[][]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] vectorise(double[][] f) { final int fi = f.length; final int fj = f[0].length; final int area = fi * fj; double[] h = new double[area]; for (int x = 0; x < fi; x++) { for (int y = 0; y < fj; y++) { h[y * fi + x] = f[x][y]; } } return h; } /** * Restructure square {@code double[][][]} as a {@code double[]}. * * @param f {@code double[][][]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] vectorise(double[][][] f) { final int fi = f.length; final int fj = f[0].length; final int area = fi * fj; final int fk = f[0][0].length; int volume = fi * fj * fk; double[] h = new double[volume]; for (int x = 0; x < fi; x++) { for (int y = 0; y < fj; y++) { for (int z = 0; z < fk; z++) { h[z * area + y * fi + x] = f[x][y][z]; } } } return h; } /** * Restructure square {@code float[][]} as a {@code float[]}. * * @param f {@code float[][]} array. * @return {@code float[]} array. * * @since 0.1 */ public static float[] vectorise(float[][] f) { final int fi = f.length; final int fj = f[0].length; final int area = fi * fj; float[] h = new float[area]; for (int x = 0; x < fi; x++) { for (int y = 0; y < fj; y++) { h[y * fi + x] = f[x][y]; } } return h; } /** * Restructure square {@code float[][][]} as a {@code float[]}. * * @param f {@code float[][][]} array. * @return {@code float[]} array. * * @since 0.1 */ public static float[] vectorise(float[][][] f) { final int fi = f.length; final int fj = f[0].length; final int area = fi * fj; final int fk = f[0][0].length; int volume = fi * fj * fk; float[] h = new float[volume]; for (int x = 0; x < fi; x++) { for (int y = 0; y < fj; y++) { for (int z = 0; z < fk; z++) { h[z * area + y * fi + x] = f[x][y][z]; } } } return h; } /** * Restructure square {@code Complex[][]} as a {@code Complex[]}. * * @param f {@code Complex[][]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] vectorise(Complex[][] f) { final int fi = f.length; final int fj = f[0].length; final int area = fi * fj; Complex[] h = new Complex[area]; for (int x = 0; x < fi; x++) { for (int y = 0; y < fj; y++) { h[y * fi + x] = f[x][y]; } } return h; } /** * Restructure square {@code Complex[][][]} as a {@code Complex[]}. * * @param f {@code Complex[][][]} array. * @return {@code Complex[]} array. * * @since 0.1 */ public static Complex[] vectorise(Complex[][][] f) { final int fi = f.length; final int fj = f[0].length; final int fk = f[0][0].length; final int area = fi * fj; int volume = fi * fj * fk; Complex[] h = new Complex[volume]; for (int x = 0; x < fi; x++) { for (int y = 0; y < fj; y++) { for (int z = 0; z < fk; z++) { h[z * area + y * fi + x] = f[x][y][z]; } } } return h; } // zeros /** * Returns a {@code double[]} containing zeros of specified dimension. * * @param fi {@code int} array dimension. * @return {@code double[]} array. * * @since 0.1 */ public static double[] zeros(int fi) { double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = 0; } return h; } /** * Returns a square {@code double[][]} containing zeros of specified dimension. * * @param fi {@code int} dimension of first array. * @param fj {@code int} dimension of second array. * @return {@code double[][]} array. * * @since 0.1 */ public static double[][] zeros(int fi, int fj) { double[][] h = new double[fi][fj]; for (int i = 0; i < fi; i++) { h[i] = zeros(fj); } return h; } /** * Returns a square {@code double[][][]} containing zeros of specified dimension. * * @param fi {@code int} dimension of first level array. * @param fj {@code int} dimension of second level array. * @param fk {@code int} dimension of third level array. * @return {@code double[][][]} array. * * @since 0.1 */ public static double[][][] zeros(int fi, int fj, int fk) { double[][][] h = new double[fi][fj][fk]; for (int i = 0; i < fi; i++) { h[i] = zeros(fj, fk); } return h; } }