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 org.apache.commons.math4.complex.Complex; /** * Implementation of MathArray for {@code float[][]} objects. * * <p> Note that even operations reserved for doubles in {@code java.util.Math} are available in the {@code float} MathArrays. * The object converts the values to {@code double} and back. * @author ericbarnhill * @see MathArray * @see MathArrayFactory * @see ArrayMath * @since 0.1 * */ public class MathArrayFloat2D extends MathArray<float[][]> { protected MathArrayFloat2D(float[][] f, int type, int nDims) { super(f, type, nDims); } @Override public float[][] getArray() { return f; } @Override protected MathArrayFloat2D abs() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.abs(ArrayMath.float2Double(f))), getType(), getnDims()); } protected MathArrayFloat2D absC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.absC(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D acos() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.acos(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D acosC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.acosC(ArrayMath.float2Double(f))), getType(), getnDims()); } protected MathArrayFloat2D add(double g) { return new MathArrayFloat2D(ArrayMath.add(f, (float) g), getType(), getnDims()); } protected MathArrayFloat2D add(float g) { return new MathArrayFloat2D(ArrayMath.add(f, g), getType(), getnDims()); } protected MathArrayFloat2D add(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); } @Override protected MathArrayFloat2D add(MathArray<float[][]> g) { return new MathArrayFloat2D(ArrayMath.add(f, g.getArray()), getType(), getnDims()); } protected MathArrayFloat2D add(float[][] g) { return new MathArrayFloat2D(ArrayMath.add(f, g), getType(), getnDims()); } protected MathArrayFloat2D addC(double g) { return new MathArrayFloat2D(ArrayMath.addC(f, (float) g), getType(), getnDims()); } protected MathArrayFloat2D addC(float g) { return new MathArrayFloat2D(ArrayMath.addC(f, g), getType(), getnDims()); } protected MathArrayFloat2D addC(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); } @Override protected MathArrayFloat2D addC(MathArray<float[][]> g) { return new MathArrayFloat2D(ArrayMath.addC(f, g.getArray()), getType(), getnDims()); } protected MathArrayFloat2D asin() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.asin(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D asinC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.asinC(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D atan() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.atan(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D atanC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.atanC(ArrayMath.float2Double(f))), getType(), getnDims()); } protected MathArrayFloat2D ceil() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.ceil(ArrayMath.float2Double(f))), getType(), getnDims()); } protected MathArrayFloat2D ceilC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.ceilC(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D cos() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.cos(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D cosC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.cosC(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D cosh() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.cosh(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D coshC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.coshC(ArrayMath.float2Double(f))), getType(), getnDims()); } protected MathArrayFloat2D divide(double g) { return new MathArrayFloat2D(ArrayMath.divide(f, (float) g), getType(), getnDims()); } protected MathArrayFloat2D divide(float g) { return new MathArrayFloat2D(ArrayMath.divide(f, g), getType(), getnDims()); } protected MathArrayFloat2D divide(Complex g) { throw new ClassCastException("Cannot divide Complex number to double array"); } @Override protected MathArrayFloat2D divide(MathArray<float[][]> g) { return new MathArrayFloat2D(ArrayMath.divide(f, g.getArray()), getType(), getnDims()); } protected MathArrayFloat2D divide(float[][] g) { return new MathArrayFloat2D(ArrayMath.divide(f, g), getType(), getnDims()); } protected MathArrayFloat2D divideC(double g) { return new MathArrayFloat2D(ArrayMath.divideC(f, (float) g), getType(), getnDims()); } protected MathArrayFloat2D divideC(float g) { return new MathArrayFloat2D(ArrayMath.divideC(f, g), getType(), getnDims()); } protected MathArrayFloat2D divideC(Complex g) { throw new ClassCastException("Cannot divide Complex number to double array"); } @Override protected MathArrayFloat2D divideC(MathArray<float[][]> g) { return new MathArrayFloat2D(ArrayMath.divideC(f, g.getArray()), getType(), getnDims()); } protected MathArrayFloat2D floor() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.floor(ArrayMath.float2Double(f))), getType(), getnDims()); } protected MathArrayFloat2D floorC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.floorC(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D log() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.log(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D logC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.logC(ArrayMath.float2Double(f))), getType(), getnDims()); } protected MathArrayFloat2D multiply(double g) { return new MathArrayFloat2D(ArrayMath.multiply(f, (float) g), getType(), getnDims()); } protected MathArrayFloat2D multiply(float g) { return new MathArrayFloat2D(ArrayMath.multiply(f, g), getType(), getnDims()); } protected MathArrayFloat2D multiply(Complex g) { throw new ClassCastException("Cannot multiply Complex number to double array"); } @Override protected MathArrayFloat2D multiply(MathArray<float[][]> g) { return new MathArrayFloat2D(ArrayMath.multiply(f, g.getArray()), getType(), getnDims()); } protected MathArrayFloat2D multiply(float[][] g) { return new MathArrayFloat2D(ArrayMath.multiply(f, g), getType(), getnDims()); } protected MathArrayFloat2D multiplyC(double g) { return new MathArrayFloat2D(ArrayMath.multiplyC(f, (float) g), getType(), getnDims()); } protected MathArrayFloat2D multiplyC(float g) { return new MathArrayFloat2D(ArrayMath.multiplyC(f, g), getType(), getnDims()); } protected MathArrayFloat2D multiplyC(Complex g) { throw new ClassCastException("Cannot multiply Complex number to double array"); } @Override protected MathArrayFloat2D multiplyC(MathArray<float[][]> g) { return new MathArrayFloat2D(ArrayMath.multiplyC(f, g.getArray()), getType(), getnDims()); } protected MathArrayFloat2D reciprocal() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.reciprocal(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D reciprocalC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.reciprocalC(ArrayMath.float2Double(f))), getType(), getnDims()); } protected MathArrayFloat2D round() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.round(ArrayMath.float2Double(f))), getType(), getnDims()); } protected MathArrayFloat2D roundC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.roundC(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D sin() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.sin(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D sinC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.sinC(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D sinh() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.sinh(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D sinhC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.sinhC(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D sqrt() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.sqrt(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D sqrtC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.sqrtC(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D square() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.square(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D squareC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.squareC(ArrayMath.float2Double(f))), getType(), getnDims()); } protected MathArrayFloat2D subtract(double g) { return new MathArrayFloat2D(ArrayMath.subtract(f, (float) g), getType(), getnDims()); } protected MathArrayFloat2D subtract(float g) { return new MathArrayFloat2D(ArrayMath.subtract(f, g), getType(), getnDims()); } protected MathArrayFloat2D subtract(Complex g) { throw new ClassCastException("Cannot subtract Complex number to double array"); } @Override protected MathArrayFloat2D subtract(MathArray<float[][]> g) { return new MathArrayFloat2D(ArrayMath.subtract(f, g.getArray()), getType(), getnDims()); } protected MathArrayFloat2D subtract(float[][] g) { return new MathArrayFloat2D(ArrayMath.subtract(f, g), getType(), getnDims()); } protected MathArrayFloat2D subtractC(double g) { return new MathArrayFloat2D(ArrayMath.subtractC(f, (float) g), getType(), getnDims()); } protected MathArrayFloat2D subtractC(float g) { return new MathArrayFloat2D(ArrayMath.subtractC(f, g), getType(), getnDims()); } protected MathArrayFloat2D subtractC(Complex g) { throw new ClassCastException("Cannot subtract Complex number to double array"); } @Override protected MathArrayFloat2D subtractC(MathArray<float[][]> g) { return new MathArrayFloat2D(ArrayMath.subtractC(f, g.getArray()), getType(), getnDims()); } @Override protected MathArrayFloat2D tan() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.tan(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D tanC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.tanC(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D tanh() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.tanh(ArrayMath.float2Double(f))), getType(), getnDims()); } @Override protected MathArrayFloat2D tanhC() { return new MathArrayFloat2D(ArrayMath.double2Float(ArrayMath.tanhC(ArrayMath.float2Double(f))), getType(), getnDims()); } }