com.ericbarnhill.arrayMath.MathArrayFloat1D.java Source code

Java tutorial

Introduction

Here is the source code for com.ericbarnhill.arrayMath.MathArrayFloat1D.java

Source

/*
 * (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 MathArrayFloat1D extends MathArray<float[]> {

    protected MathArrayFloat1D(float[] f, int type, int nDims) {
        super(f, type, nDims);
    }

    @Override
    public float[] getArray() {
        return f;
    }

    @Override
    protected MathArrayFloat1D abs() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.abs(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    protected MathArrayFloat1D absC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.absC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D acos() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.acos(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D acosC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.acosC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    protected MathArrayFloat1D add(double g) {
        return new MathArrayFloat1D(ArrayMath.add(f, (float) g), getType(), getnDims());
    }

    protected MathArrayFloat1D add(float g) {
        return new MathArrayFloat1D(ArrayMath.add(f, g), getType(), getnDims());
    }

    protected MathArrayFloat1D add(Complex g) {
        throw new ClassCastException("Cannot add Complex number to double array");
    }

    @Override
    protected MathArrayFloat1D add(MathArray<float[]> g) {
        return new MathArrayFloat1D(ArrayMath.add(f, g.getArray()), getType(), getnDims());
    }

    protected MathArrayFloat1D add(float[] g) {
        return new MathArrayFloat1D(ArrayMath.add(f, g), getType(), getnDims());
    }

    protected MathArrayFloat1D addC(double g) {
        return new MathArrayFloat1D(ArrayMath.addC(f, (float) g), getType(), getnDims());
    }

    protected MathArrayFloat1D addC(float g) {
        return new MathArrayFloat1D(ArrayMath.addC(f, g), getType(), getnDims());
    }

    protected MathArrayFloat1D addC(Complex g) {
        throw new ClassCastException("Cannot add Complex number to double array");
    }

    @Override
    protected MathArrayFloat1D addC(MathArray<float[]> g) {
        return new MathArrayFloat1D(ArrayMath.addC(f, g.getArray()), getType(), getnDims());
    }

    protected MathArrayFloat1D asin() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.asin(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D asinC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.asinC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D atan() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.atan(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D atanC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.atanC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    protected MathArrayFloat1D ceil() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.ceil(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    protected MathArrayFloat1D ceilC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.ceilC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D cos() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.cos(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D cosC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.cosC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D cosh() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.cosh(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D coshC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.coshC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    protected MathArrayFloat1D divide(double g) {
        return new MathArrayFloat1D(ArrayMath.divide(f, (float) g), getType(), getnDims());
    }

    protected MathArrayFloat1D divide(float g) {
        return new MathArrayFloat1D(ArrayMath.divide(f, g), getType(), getnDims());
    }

    protected MathArrayFloat1D divide(Complex g) {
        throw new ClassCastException("Cannot divide Complex number to double array");
    }

    @Override
    protected MathArrayFloat1D divide(MathArray<float[]> g) {
        return new MathArrayFloat1D(ArrayMath.divide(f, g.getArray()), getType(), getnDims());
    }

    protected MathArrayFloat1D divide(float[] g) {
        return new MathArrayFloat1D(ArrayMath.divide(f, g), getType(), getnDims());
    }

    protected MathArrayFloat1D divideC(double g) {
        return new MathArrayFloat1D(ArrayMath.divideC(f, (float) g), getType(), getnDims());
    }

    protected MathArrayFloat1D divideC(float g) {
        return new MathArrayFloat1D(ArrayMath.divideC(f, g), getType(), getnDims());
    }

    protected MathArrayFloat1D divideC(Complex g) {
        throw new ClassCastException("Cannot divide Complex number to double array");
    }

    @Override
    protected MathArrayFloat1D divideC(MathArray<float[]> g) {
        return new MathArrayFloat1D(ArrayMath.divideC(f, g.getArray()), getType(), getnDims());
    }

    protected MathArrayFloat1D floor() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.floor(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    protected MathArrayFloat1D floorC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.floorC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D log() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.log(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D logC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.logC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    protected MathArrayFloat1D multiply(double g) {
        return new MathArrayFloat1D(ArrayMath.multiply(f, (float) g), getType(), getnDims());
    }

    protected MathArrayFloat1D multiply(float g) {
        return new MathArrayFloat1D(ArrayMath.multiply(f, g), getType(), getnDims());
    }

    protected MathArrayFloat1D multiply(Complex g) {
        throw new ClassCastException("Cannot multiply Complex number to double array");
    }

    @Override
    protected MathArrayFloat1D multiply(MathArray<float[]> g) {
        return new MathArrayFloat1D(ArrayMath.multiply(f, g.getArray()), getType(), getnDims());
    }

    protected MathArrayFloat1D multiply(float[] g) {
        return new MathArrayFloat1D(ArrayMath.multiply(f, g), getType(), getnDims());
    }

    protected MathArrayFloat1D multiplyC(double g) {
        return new MathArrayFloat1D(ArrayMath.multiplyC(f, (float) g), getType(), getnDims());
    }

    protected MathArrayFloat1D multiplyC(float g) {
        return new MathArrayFloat1D(ArrayMath.multiplyC(f, g), getType(), getnDims());
    }

    protected MathArrayFloat1D multiplyC(Complex g) {
        throw new ClassCastException("Cannot multiply Complex number to double array");
    }

    @Override
    protected MathArrayFloat1D multiplyC(MathArray<float[]> g) {
        return new MathArrayFloat1D(ArrayMath.multiplyC(f, g.getArray()), getType(), getnDims());
    }

    protected MathArrayFloat1D reciprocal() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.reciprocal(ArrayMath.float2Double(f))),
                getType(), getnDims());
    }

    @Override
    protected MathArrayFloat1D reciprocalC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.reciprocalC(ArrayMath.float2Double(f))),
                getType(), getnDims());
    }

    protected MathArrayFloat1D round() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.round(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    protected MathArrayFloat1D roundC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.roundC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D sin() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.sin(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D sinC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.sinC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D sinh() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.sinh(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D sinhC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.sinhC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D sqrt() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.sqrt(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D sqrtC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.sqrtC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D square() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.square(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D squareC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.squareC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    protected MathArrayFloat1D subtract(double g) {
        return new MathArrayFloat1D(ArrayMath.subtract(f, (float) g), getType(), getnDims());
    }

    protected MathArrayFloat1D subtract(float g) {
        return new MathArrayFloat1D(ArrayMath.subtract(f, g), getType(), getnDims());
    }

    protected MathArrayFloat1D subtract(Complex g) {
        throw new ClassCastException("Cannot subtract Complex number to double array");
    }

    @Override
    protected MathArrayFloat1D subtract(MathArray<float[]> g) {
        return new MathArrayFloat1D(ArrayMath.subtract(f, g.getArray()), getType(), getnDims());
    }

    protected MathArrayFloat1D subtract(float[] g) {
        return new MathArrayFloat1D(ArrayMath.subtract(f, g), getType(), getnDims());
    }

    protected MathArrayFloat1D subtractC(double g) {
        return new MathArrayFloat1D(ArrayMath.subtractC(f, (float) g), getType(), getnDims());
    }

    protected MathArrayFloat1D subtractC(float g) {
        return new MathArrayFloat1D(ArrayMath.subtractC(f, g), getType(), getnDims());
    }

    protected MathArrayFloat1D subtractC(Complex g) {
        throw new ClassCastException("Cannot subtract Complex number to double array");
    }

    @Override
    protected MathArrayFloat1D subtractC(MathArray<float[]> g) {
        return new MathArrayFloat1D(ArrayMath.subtractC(f, g.getArray()), getType(), getnDims());
    }

    @Override
    protected MathArrayFloat1D tan() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.tan(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D tanC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.tanC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D tanh() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.tanh(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

    @Override
    protected MathArrayFloat1D tanhC() {
        return new MathArrayFloat1D(ArrayMath.double2Float(ArrayMath.tanhC(ArrayMath.float2Double(f))), getType(),
                getnDims());
    }

}