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 double[][]} objects. * @author ericbarnhill * @see MathArray * @see MathArrayFactory * @see ArrayMath * @since 0.1 * */ public class MathArrayDouble2D extends MathArray<double[][]> { protected MathArrayDouble2D(double[][] f, int type, int nDims) { super(f, type, nDims); } @Override public double[][] getArray() { return f; } @Override protected MathArrayDouble2D abs() { return new MathArrayDouble2D(ArrayMath.abs(f), getType(), getnDims()); } @Override protected MathArrayDouble2D acos() { return new MathArrayDouble2D(ArrayMath.acos(f), getType(), getnDims()); } @Override protected MathArrayDouble2D acosC() { return new MathArrayDouble2D(ArrayMath.acosC(f), getType(), getnDims()); } protected MathArrayDouble2D add(double g) { return new MathArrayDouble2D(ArrayMath.add(f, g), getType(), getnDims()); } protected MathArrayDouble2D add(float g) { return new MathArrayDouble2D(ArrayMath.add(f, g), getType(), getnDims()); } protected MathArrayDouble2D add(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); } @Override protected MathArrayDouble2D add(MathArray<double[][]> g) { return new MathArrayDouble2D(ArrayMath.add(f, g.getArray()), getType(), getnDims()); } protected MathArrayDouble2D add(double[][] g) { return new MathArrayDouble2D(ArrayMath.add(f, g), getType(), getnDims()); } protected MathArrayDouble2D addC(double g) { return new MathArrayDouble2D(ArrayMath.addC(f, g), getType(), getnDims()); } protected MathArrayDouble2D addC(float g) { return new MathArrayDouble2D(ArrayMath.addC(f, g), getType(), getnDims()); } protected MathArrayDouble2D addC(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); } @Override protected MathArrayDouble2D addC(MathArray<double[][]> g) { return new MathArrayDouble2D(ArrayMath.addC(f, g.getArray()), getType(), getnDims()); } protected MathArrayDouble2D addC(double[][] g) { return new MathArrayDouble2D(ArrayMath.addC(f, g), getType(), getnDims()); } @Override protected MathArrayDouble2D asin() { return new MathArrayDouble2D(ArrayMath.asin(f), getType(), getnDims()); } @Override protected MathArrayDouble2D asinC() { return new MathArrayDouble2D(ArrayMath.asinC(f), getType(), getnDims()); } @Override protected MathArrayDouble2D atan() { return new MathArrayDouble2D(ArrayMath.atan(f), getType(), getnDims()); } @Override protected MathArrayDouble2D atanC() { return new MathArrayDouble2D(ArrayMath.atanC(f), getType(), getnDims()); } @Override protected MathArrayDouble2D cos() { return new MathArrayDouble2D(ArrayMath.cos(f), getType(), getnDims()); } @Override protected MathArrayDouble2D cosC() { return new MathArrayDouble2D(ArrayMath.cosC(f), getType(), getnDims()); } @Override protected MathArrayDouble2D cosh() { return new MathArrayDouble2D(ArrayMath.cosh(f), getType(), getnDims()); } @Override protected MathArrayDouble2D coshC() { return new MathArrayDouble2D(ArrayMath.coshC(f), getType(), getnDims()); } protected MathArrayDouble2D divide(double g) { return new MathArrayDouble2D(ArrayMath.divide(f, g), getType(), getnDims()); } protected MathArrayDouble2D divide(float g) { return new MathArrayDouble2D(ArrayMath.divide(f, g), getType(), getnDims()); } protected MathArrayDouble2D divide(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); } @Override protected MathArrayDouble2D divide(MathArray<double[][]> g) { return new MathArrayDouble2D(ArrayMath.divide(f, g.getArray()), getType(), getnDims()); } protected MathArrayDouble2D divide(double[][] g) { return new MathArrayDouble2D(ArrayMath.divide(f, g), getType(), getnDims()); } protected MathArrayDouble2D divideC(double g) { return new MathArrayDouble2D(ArrayMath.divideC(f, g), getType(), getnDims()); } protected MathArrayDouble2D divideC(float g) { return new MathArrayDouble2D(ArrayMath.divideC(f, g), getType(), getnDims()); } protected MathArrayDouble2D divideC(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); } @Override protected MathArrayDouble2D divideC(MathArray<double[][]> g) { return new MathArrayDouble2D(ArrayMath.divideC(f, g.getArray()), getType(), getnDims()); } protected MathArrayDouble2D divideC(double[][] g) { return new MathArrayDouble2D(ArrayMath.divideC(f, g), getType(), getnDims()); } @Override protected MathArrayDouble2D log() { return new MathArrayDouble2D(ArrayMath.log(f), getType(), getnDims()); } @Override protected MathArrayDouble2D logC() { return new MathArrayDouble2D(ArrayMath.logC(f), getType(), getnDims()); } protected MathArrayDouble2D multiply(double g) { return new MathArrayDouble2D(ArrayMath.multiply(f, g), getType(), getnDims()); } protected MathArrayDouble2D multiply(float g) { return new MathArrayDouble2D(ArrayMath.multiply(f, g), getType(), getnDims()); } protected MathArrayDouble2D multiply(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); } @Override protected MathArrayDouble2D multiply(MathArray<double[][]> g) { return new MathArrayDouble2D(ArrayMath.multiply(f, g.getArray()), getType(), getnDims()); } protected MathArrayDouble2D multiply(double[][] g) { return new MathArrayDouble2D(ArrayMath.multiply(f, g), getType(), getnDims()); } protected MathArrayDouble2D multiplyC(double g) { return new MathArrayDouble2D(ArrayMath.multiplyC(f, g), getType(), getnDims()); } protected MathArrayDouble2D multiplyC(float g) { return new MathArrayDouble2D(ArrayMath.multiplyC(f, g), getType(), getnDims()); } protected MathArrayDouble2D multiplyC(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); } @Override protected MathArrayDouble2D multiplyC(MathArray<double[][]> g) { return new MathArrayDouble2D(ArrayMath.multiplyC(f, g.getArray()), getType(), getnDims()); } protected MathArrayDouble2D multiplyC(double[][] g) { return new MathArrayDouble2D(ArrayMath.multiplyC(f, g), getType(), getnDims()); } @Override protected MathArrayDouble2D reciprocal() { return new MathArrayDouble2D(ArrayMath.reciprocal(f), getType(), getnDims()); } @Override protected MathArrayDouble2D reciprocalC() { return new MathArrayDouble2D(ArrayMath.reciprocalC(f), getType(), getnDims()); } @Override protected MathArrayDouble2D sin() { return new MathArrayDouble2D(ArrayMath.sin(f), getType(), getnDims()); } @Override protected MathArrayDouble2D sinC() { return new MathArrayDouble2D(ArrayMath.sinC(f), getType(), getnDims()); } @Override protected MathArrayDouble2D sinh() { return new MathArrayDouble2D(ArrayMath.sinh(f), getType(), getnDims()); } @Override protected MathArrayDouble2D sinhC() { return new MathArrayDouble2D(ArrayMath.sinhC(f), getType(), getnDims()); } @Override protected MathArrayDouble2D sqrt() { return new MathArrayDouble2D(ArrayMath.sqrt(f), getType(), getnDims()); } @Override protected MathArrayDouble2D sqrtC() { return new MathArrayDouble2D(ArrayMath.sqrtC(f), getType(), getnDims()); } @Override protected MathArrayDouble2D square() { return new MathArrayDouble2D(ArrayMath.square(f), getType(), getnDims()); } @Override protected MathArrayDouble2D squareC() { return new MathArrayDouble2D(ArrayMath.squareC(f), getType(), getnDims()); } protected MathArrayDouble2D subtract(double g) { return new MathArrayDouble2D(ArrayMath.subtract(f, g), getType(), getnDims()); } protected MathArrayDouble2D subtract(float g) { return new MathArrayDouble2D(ArrayMath.subtract(f, g), getType(), getnDims()); } protected MathArrayDouble2D subtract(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); } @Override protected MathArrayDouble2D subtract(MathArray<double[][]> g) { return new MathArrayDouble2D(ArrayMath.subtract(f, g.getArray()), getType(), getnDims()); } protected MathArrayDouble2D subtractC(double g) { return new MathArrayDouble2D(ArrayMath.subtractC(f, g), getType(), getnDims()); } protected MathArrayDouble2D subtractC(float g) { return new MathArrayDouble2D(ArrayMath.subtractC(f, g), getType(), getnDims()); } protected MathArrayDouble2D subtractC(Complex g) { throw new ClassCastException("Cannot add Complex number to double array"); } @Override protected MathArrayDouble2D subtractC(MathArray<double[][]> g) { return new MathArrayDouble2D(ArrayMath.subtractC(f, g.getArray()), getType(), getnDims()); } protected MathArrayDouble2D subtractC(double[][] g) { return new MathArrayDouble2D(ArrayMath.subtractC(f, g), getType(), getnDims()); } @Override protected MathArrayDouble2D tan() { return new MathArrayDouble2D(ArrayMath.tan(f), getType(), getnDims()); } @Override protected MathArrayDouble2D tanC() { return new MathArrayDouble2D(ArrayMath.tanC(f), getType(), getnDims()); } @Override protected MathArrayDouble2D tanh() { return new MathArrayDouble2D(ArrayMath.tanh(f), getType(), getnDims()); } @Override protected MathArrayDouble2D tanhC() { return new MathArrayDouble2D(ArrayMath.tanhC(f), getType(), getnDims()); } }