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