Example usage for org.apache.commons.math3.complex Complex getReal

List of usage examples for org.apache.commons.math3.complex Complex getReal

Introduction

In this page you can find the example usage for org.apache.commons.math3.complex Complex getReal.

Prototype

public double getReal() 

Source Link

Document

Access the real part.

Usage

From source file:org.eclipse.january.dataset.Maths.java

/**
 * arccos - evaluate the inverse cosine function on each element of the dataset
 * @param a/*from   w  w w.j av a2 s  .c  o m*/
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset arccos(final Object a, final Dataset o) {
    final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    final Dataset result = it.getOutput();
    final int is = result.getElementsPerItem();
    final int dt = result.getDType();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(Math.acos(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.acos(ix));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(Math.acos(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.acos(ix));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(Math.acos(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.acos(ix));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(Math.acos(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.acos(ix));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.acos(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.acos(ix));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.acos(ix));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.acos(ix));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.acos(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.acos(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.acos(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.acos(ix));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.acos(ix));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.acos(ix));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.acos(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.acos(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.acos(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.acos(ix));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.acos(ix));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.acos(ix));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.acos(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.acos(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.acos(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.acos(ix));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.acos(ix));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.acos(ix));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.acos(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.acos(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (Math.acos(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.acos(ix));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (Math.acos(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.acos(ix));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.acos(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.acos(ix));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.acos(ix));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.acos(ix));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.acos(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.acos(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.acos(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.acos(ix));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.acos(ix));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.acos(ix));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.acos(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.acos(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                Complex tz;
                float ox;
                float oy;
                tz = new Complex(ix, iy).acos();
                ox = (float) (tz.getReal());
                oy = (float) (tz.getImaginary());
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                Complex tz;
                float ox;
                float oy;
                tz = new Complex(ix, iy).acos();
                ox = (float) (tz.getReal());
                oy = (float) (tz.getImaginary());
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                Complex tz;
                double ox;
                double oy;
                tz = new Complex(ix, iy).acos();
                ox = (tz.getReal());
                oy = (tz.getImaginary());
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                Complex tz;
                double ox;
                double oy;
                tz = new Complex(ix, iy).acos();
                ox = (tz.getReal());
                oy = (tz.getImaginary());
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "arccos supports integer, compound integer, real, compound real, complex datasets only");
    }

    addFunctionName(result, "arccos");
    return result;
}

From source file:org.eclipse.january.dataset.Maths.java

/**
 * arctan - evaluate the inverse tangent function on each element of the dataset
 * @param a//  w  ww  .j  av a 2  s  .  co m
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset arctan(final Object a, final Dataset o) {
    final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    final Dataset result = it.getOutput();
    final int is = result.getElementsPerItem();
    final int dt = result.getDType();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(Math.atan(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.atan(ix));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(Math.atan(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.atan(ix));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(Math.atan(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.atan(ix));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(Math.atan(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.atan(ix));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.atan(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.atan(ix));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.atan(ix));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.atan(ix));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.atan(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.atan(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.atan(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.atan(ix));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.atan(ix));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.atan(ix));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.atan(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.atan(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.atan(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.atan(ix));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.atan(ix));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.atan(ix));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.atan(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.atan(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.atan(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.atan(ix));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.atan(ix));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.atan(ix));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.atan(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.atan(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (Math.atan(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.atan(ix));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (Math.atan(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.atan(ix));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.atan(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.atan(ix));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.atan(ix));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.atan(ix));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.atan(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.atan(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.atan(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.atan(ix));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.atan(ix));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.atan(ix));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.atan(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.atan(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                Complex tz;
                float ox;
                float oy;
                tz = new Complex(ix, iy).atan();
                ox = (float) (tz.getReal());
                oy = (float) (tz.getImaginary());
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                Complex tz;
                float ox;
                float oy;
                tz = new Complex(ix, iy).atan();
                ox = (float) (tz.getReal());
                oy = (float) (tz.getImaginary());
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                Complex tz;
                double ox;
                double oy;
                tz = new Complex(ix, iy).atan();
                ox = (tz.getReal());
                oy = (tz.getImaginary());
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                Complex tz;
                double ox;
                double oy;
                tz = new Complex(ix, iy).atan();
                ox = (tz.getReal());
                oy = (tz.getImaginary());
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "arctan supports integer, compound integer, real, compound real, complex datasets only");
    }

    addFunctionName(result, "arctan");
    return result;
}

From source file:org.eclipse.january.dataset.Maths.java

/**
 * arcsinh - evaluate the inverse hyperbolic sine function on each element of the dataset
 * @param a/*from   ww w .jav a 2 s .  c  om*/
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset arcsinh(final Object a, final Dataset o) {
    final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    final Dataset result = it.getOutput();
    final int is = result.getElementsPerItem();
    final int dt = result.getDType();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix + 1)));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (Math.log(ix + Math.sqrt(ix * ix + 1)));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.log(ix + Math.sqrt(ix * ix + 1)));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (Math.log(ix + Math.sqrt(ix * ix + 1)));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.log(ix + Math.sqrt(ix * ix + 1)));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.log(ix + Math.sqrt(ix * ix + 1)));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.log(ix + Math.sqrt(ix * ix + 1)));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.log(ix + Math.sqrt(ix * ix + 1)));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.log(ix + Math.sqrt(ix * ix + 1)));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.log(ix + Math.sqrt(ix * ix + 1)));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.log(ix + Math.sqrt(ix * ix + 1)));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.log(ix + Math.sqrt(ix * ix + 1)));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.log(ix + Math.sqrt(ix * ix + 1)));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.log(ix + Math.sqrt(ix * ix + 1)));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.log(ix + Math.sqrt(ix * ix + 1)));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.log(ix + Math.sqrt(ix * ix + 1)));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.log(ix + Math.sqrt(ix * ix + 1)));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                Complex tz;
                float ox;
                float oy;
                tz = new Complex(-iy, ix).asin();
                ox = (float) (tz.getImaginary());
                oy = (float) (-tz.getReal());
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                Complex tz;
                float ox;
                float oy;
                tz = new Complex(-iy, ix).asin();
                ox = (float) (tz.getImaginary());
                oy = (float) (-tz.getReal());
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                Complex tz;
                double ox;
                double oy;
                tz = new Complex(-iy, ix).asin();
                ox = (tz.getImaginary());
                oy = (-tz.getReal());
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                Complex tz;
                double ox;
                double oy;
                tz = new Complex(-iy, ix).asin();
                ox = (tz.getImaginary());
                oy = (-tz.getReal());
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "arcsinh supports integer, compound integer, real, compound real, complex datasets only");
    }

    addFunctionName(result, "arcsinh");
    return result;
}

From source file:org.eclipse.january.dataset.Maths.java

/**
 * arccosh - evaluate the inverse hyperbolic cosine function on each element of the dataset
 * @param a//from w w  w .j a  v  a  2  s. c om
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset arccosh(final Object a, final Dataset o) {
    final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    final Dataset result = it.getOutput();
    final int is = result.getElementsPerItem();
    final int dt = result.getDType();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix * ix - 1)));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (Math.log(ix + Math.sqrt(ix * ix - 1)));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.log(ix + Math.sqrt(ix * ix - 1)));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (Math.log(ix + Math.sqrt(ix * ix - 1)));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.log(ix + Math.sqrt(ix * ix - 1)));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.log(ix + Math.sqrt(ix * ix - 1)));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.log(ix + Math.sqrt(ix * ix - 1)));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.log(ix + Math.sqrt(ix * ix - 1)));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.log(ix + Math.sqrt(ix * ix - 1)));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.log(ix + Math.sqrt(ix * ix - 1)));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.log(ix + Math.sqrt(ix * ix - 1)));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.log(ix + Math.sqrt(ix * ix - 1)));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.log(ix + Math.sqrt(ix * ix - 1)));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.log(ix + Math.sqrt(ix * ix - 1)));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.log(ix + Math.sqrt(ix * ix - 1)));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.log(ix + Math.sqrt(ix * ix - 1)));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.log(ix + Math.sqrt(ix * ix - 1)));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                Complex tz;
                float ox;
                float oy;
                tz = new Complex(-iy, ix).acos();
                ox = (float) (tz.getImaginary());
                oy = (float) (-tz.getReal());
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                Complex tz;
                float ox;
                float oy;
                tz = new Complex(-iy, ix).acos();
                ox = (float) (tz.getImaginary());
                oy = (float) (-tz.getReal());
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                Complex tz;
                double ox;
                double oy;
                tz = new Complex(-iy, ix).acos();
                ox = (tz.getImaginary());
                oy = (-tz.getReal());
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                Complex tz;
                double ox;
                double oy;
                tz = new Complex(-iy, ix).acos();
                ox = (tz.getImaginary());
                oy = (-tz.getReal());
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "arccosh supports integer, compound integer, real, compound real, complex datasets only");
    }

    addFunctionName(result, "arccosh");
    return result;
}

From source file:org.eclipse.january.dataset.Maths.java

/**
 * arctanh - evaluate the inverse hyperbolic tangent function on each element of the dataset
 * @param a/*from   w  w  w  . j  ava2 s .c  o m*/
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset arctanh(final Object a, final Dataset o) {
    final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    final Dataset result = it.getOutput();
    final int is = result.getElementsPerItem();
    final int dt = result.getDType();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(0.5 * Math.log((1 + ix) / (1 - ix)));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (0.5 * Math.log((1 + ix) / (1 - ix)));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (0.5 * Math.log((1 + ix) / (1 - ix)));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (0.5 * Math.log((1 + ix) / (1 - ix)));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (0.5 * Math.log((1 + ix) / (1 - ix)));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (0.5 * Math.log((1 + ix) / (1 - ix)));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (0.5 * Math.log((1 + ix) / (1 - ix)));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (0.5 * Math.log((1 + ix) / (1 - ix)));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (0.5 * Math.log((1 + ix) / (1 - ix)));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (0.5 * Math.log((1 + ix) / (1 - ix)));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (0.5 * Math.log((1 + ix) / (1 - ix)));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (0.5 * Math.log((1 + ix) / (1 - ix)));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (0.5 * Math.log((1 + ix) / (1 - ix)));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (0.5 * Math.log((1 + ix) / (1 - ix)));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (0.5 * Math.log((1 + ix) / (1 - ix)));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        double ox;
                        ox = (0.5 * Math.log((1 + ix) / (1 - ix)));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        double ox;
                        ox = (0.5 * Math.log((1 + ix) / (1 - ix)));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                Complex tz;
                float ox;
                float oy;
                tz = new Complex(-iy, ix).atan();
                ox = (float) (tz.getImaginary());
                oy = (float) (-tz.getReal());
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                Complex tz;
                float ox;
                float oy;
                tz = new Complex(-iy, ix).atan();
                ox = (float) (tz.getImaginary());
                oy = (float) (-tz.getReal());
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                Complex tz;
                double ox;
                double oy;
                tz = new Complex(-iy, ix).atan();
                ox = (tz.getImaginary());
                oy = (-tz.getReal());
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                Complex tz;
                double ox;
                double oy;
                tz = new Complex(-iy, ix).atan();
                ox = (tz.getImaginary());
                oy = (-tz.getReal());
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "arctanh supports integer, compound integer, real, compound real, complex datasets only");
    }

    addFunctionName(result, "arctanh");
    return result;
}

From source file:org.eclipse.january.dataset.Maths.java

/**
 * sqrt - evaluate the square root function on each element of the dataset
 * @param a//ww w .j  av  a 2  s.  co m
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset sqrt(final Object a, final Dataset o) {
    final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    final Dataset result = it.getOutput();
    final int is = result.getElementsPerItem();
    final int dt = result.getDType();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(Math.sqrt(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.sqrt(ix));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(Math.sqrt(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.sqrt(ix));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(Math.sqrt(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.sqrt(ix));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(Math.sqrt(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.sqrt(ix));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.sqrt(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.sqrt(ix));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.sqrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.sqrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.sqrt(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.sqrt(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.sqrt(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.sqrt(ix));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.sqrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.sqrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.sqrt(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.sqrt(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.sqrt(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.sqrt(ix));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.sqrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.sqrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.sqrt(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.sqrt(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.sqrt(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.sqrt(ix));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.sqrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.sqrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.sqrt(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.sqrt(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (Math.sqrt(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.sqrt(ix));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (Math.sqrt(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.sqrt(ix));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.sqrt(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.sqrt(ix));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.sqrt(ix));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.sqrt(ix));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.sqrt(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.sqrt(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.sqrt(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.sqrt(ix));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.sqrt(ix));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.sqrt(ix));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.sqrt(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.sqrt(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                Complex tz;
                float ox;
                float oy;
                tz = new Complex(ix, iy).sqrt();
                ox = (float) (tz.getReal());
                oy = (float) (tz.getImaginary());
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                Complex tz;
                float ox;
                float oy;
                tz = new Complex(ix, iy).sqrt();
                ox = (float) (tz.getReal());
                oy = (float) (tz.getImaginary());
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                Complex tz;
                double ox;
                double oy;
                tz = new Complex(ix, iy).sqrt();
                ox = (tz.getReal());
                oy = (tz.getImaginary());
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                Complex tz;
                double ox;
                double oy;
                tz = new Complex(ix, iy).sqrt();
                ox = (tz.getReal());
                oy = (tz.getImaginary());
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "sqrt supports integer, compound integer, real, compound real, complex datasets only");
    }

    addFunctionName(result, "sqrt");
    return result;
}

From source file:org.eclipse.january.dataset.Maths.java

/**
 * cbrt - evaluate the cube root function on each element of the dataset
 * @param a/*from  ww w .  j  a va  2  s  .c  om*/
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset cbrt(final Object a, final Dataset o) {
    final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    final Dataset result = it.getOutput();
    final int is = result.getElementsPerItem();
    final int dt = result.getDType();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(Math.cbrt(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.cbrt(ix));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(Math.cbrt(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.cbrt(ix));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(Math.cbrt(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.cbrt(ix));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(Math.cbrt(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.cbrt(ix));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.cbrt(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.cbrt(ix));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.cbrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.cbrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.cbrt(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.cbrt(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.cbrt(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.cbrt(ix));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.cbrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.cbrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.cbrt(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.cbrt(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.cbrt(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.cbrt(ix));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.cbrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.cbrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.cbrt(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.cbrt(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.cbrt(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.cbrt(ix));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.cbrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.cbrt(ix));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.cbrt(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.cbrt(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (Math.cbrt(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.cbrt(ix));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (Math.cbrt(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.cbrt(ix));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.cbrt(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.cbrt(ix));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.cbrt(ix));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.cbrt(ix));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.cbrt(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.cbrt(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.cbrt(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.cbrt(ix));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.cbrt(ix));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.cbrt(ix));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.cbrt(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.cbrt(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                Complex tz;
                float ox;
                float oy;
                tz = new Complex(ix, iy).pow(new Complex(1. / 3., 0));
                ox = (float) (tz.getReal());
                oy = (float) (tz.getImaginary());
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                Complex tz;
                float ox;
                float oy;
                tz = new Complex(ix, iy).pow(new Complex(1. / 3., 0));
                ox = (float) (tz.getReal());
                oy = (float) (tz.getImaginary());
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                Complex tz;
                double ox;
                double oy;
                tz = new Complex(ix, iy).pow(new Complex(1. / 3., 0));
                ox = (tz.getReal());
                oy = (tz.getImaginary());
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                Complex tz;
                double ox;
                double oy;
                tz = new Complex(ix, iy).pow(new Complex(1. / 3., 0));
                ox = (tz.getReal());
                oy = (tz.getImaginary());
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "cbrt supports integer, compound integer, real, compound real, complex datasets only");
    }

    addFunctionName(result, "cbrt");
    return result;
}

From source file:org.eclipse.january.dataset.MathsTest.java

@Test
public void testAddition() {
    Dataset a, b, c = null, d = null;//from w  w w  .  ja va 2 s  .  co  m
    Complex zv = new Complex(-3.5, 0);
    final double dv = zv.getReal();
    long start;
    int n;
    int eCount = 0;

    for (String dn : classes.keySet()) {
        final int dtype = classes.get(dn);
        Random.seed(12735L);
        for (String en : classes.keySet()) {
            final int etype = classes.get(en);

            TestUtils.verbosePrintf("%s to %s, ", dn, en);

            n = 32;
            for (int i = 0; i < SITER; i++) {
                if (dtype < Dataset.ARRAYINT8) {
                    a = Random.randn(n).imultiply(100);
                    a = a.cast(dtype);
                } else {
                    Dataset[] aa = new Dataset[ISIZEA];
                    for (int j = 0; j < ISIZEA; j++) {
                        aa[j] = Random.randn(n).imultiply(100);
                    }
                    a = DatasetUtils.cast(aa, dtype);
                }
                if (etype < Dataset.ARRAYINT8) {
                    b = Random.randn(n).imultiply(100);
                    b = b.cast(etype);
                } else {
                    Dataset[] ab = new Dataset[ISIZEB];
                    for (int j = 0; j < ISIZEB; j++) {
                        ab[j] = Random.randn(n).imultiply(100);
                    }
                    b = DatasetUtils.cast(ab, etype);
                }

                start = -System.nanoTime();
                try {
                    c = Maths.add(a, b);
                } catch (IllegalArgumentException e) {
                    TestUtils.verbosePrintf("Could not perform this operation: %s\n\n", e.getMessage());
                    eCount++;
                    continue;
                }
                start += System.nanoTime();
                double ntime = ((double) start) / c.getSize();

                d = DatasetFactory.zeros(c);
                start = -System.nanoTime();
                IndexIterator ita = a.getIterator();
                IndexIterator itb = b.getIterator();
                int j = 0;
                if ((dtype == Dataset.COMPLEX64 || dtype == Dataset.COMPLEX128)
                        && (etype == Dataset.COMPLEX64 || etype == Dataset.COMPLEX128)) {
                    final int is = d.getElementsPerItem();
                    while (ita.hasNext() && itb.hasNext()) {
                        d.setObjectAbs(j,
                                ((Complex) a.getObjectAbs(ita.index)).add((Complex) b.getObjectAbs(itb.index)));
                        j += is;
                    }
                } else if ((dtype == Dataset.COMPLEX64 || dtype == Dataset.COMPLEX128)
                        && !(etype == Dataset.COMPLEX64 || etype == Dataset.COMPLEX128)) {
                    final int is = d.getElementsPerItem();
                    while (ita.hasNext() && itb.hasNext()) {
                        d.setObjectAbs(j, ((Complex) a.getObjectAbs(ita.index))
                                .add(new Complex(b.getElementDoubleAbs(itb.index), 0)));
                        j += is;
                    }
                } else if (!(dtype == Dataset.COMPLEX64 || dtype == Dataset.COMPLEX128)
                        && (etype == Dataset.COMPLEX64 || etype == Dataset.COMPLEX128)) {
                    final int is = d.getElementsPerItem();
                    while (ita.hasNext() && itb.hasNext()) {
                        d.setObjectAbs(j, new Complex(a.getElementDoubleAbs(ita.index), 0)
                                .add((Complex) b.getObjectAbs(itb.index)));
                        j += is;
                    }
                } else {
                    if (dtype < Dataset.ARRAYINT8 && etype < Dataset.ARRAYINT8) {
                        while (ita.hasNext() && itb.hasNext()) {
                            d.setObjectAbs(j++, ((Number) a.getObjectAbs(ita.index)).doubleValue()
                                    + ((Number) b.getObjectAbs(itb.index)).doubleValue());
                        }
                    } else {
                        final double[] answer = new double[MAXISIZE];
                        final int is = d.getElementsPerItem();
                        if (a.getElementsPerItem() < is) {
                            while (ita.hasNext() && itb.hasNext()) {
                                final double da = a.getElementDoubleAbs(ita.index);
                                for (int k = 0; k < ISIZEB; k++) {
                                    answer[k] = da + b.getElementDoubleAbs(itb.index + k);
                                }
                                d.setObjectAbs(j, answer);
                                j += is;
                            }
                        } else if (b.getElementsPerItem() < is) {
                            while (ita.hasNext() && itb.hasNext()) {
                                final double db = b.getElementDoubleAbs(itb.index);
                                for (int k = 0; k < ISIZEA; k++) {
                                    answer[k] = a.getElementDoubleAbs(ita.index + k) + db;
                                }
                                d.setObjectAbs(j, answer);
                                j += is;
                            }
                        } else {
                            while (ita.hasNext() && itb.hasNext()) {
                                for (int k = 0; k < is; k++) {
                                    answer[k] = a.getElementDoubleAbs(ita.index + k)
                                            + b.getElementDoubleAbs(itb.index + k);
                                }
                                d.setObjectAbs(j, answer);
                                j += is;
                            }
                        }
                    }
                }
                if (d == null)
                    break;
                start += System.nanoTime();
                double otime = ((double) start) / d.getSize();

                TestUtils.verbosePrintf("Time taken by add for %s: %s; %s (%.1f%%)\n", n, otime, ntime,
                        100. * (otime - ntime) / otime);
                checkDatasets(a, b, c, d);

                n *= SSTEP;
            }
        }

        Random.seed(12735L);
        n = 32;
        TestUtils.verbosePrintf("constant to %s, ", dn);
        for (int i = 0; i < SITER; i++) {
            if (dtype < Dataset.ARRAYINT8) {
                a = Random.randn(n);
                a.imultiply(100);
                a = a.cast(dtype);
            } else {
                Dataset[] aa = new Dataset[ISIZEA];
                for (int j = 0; j < ISIZEA; j++) {
                    aa[j] = Random.randn(n).imultiply(100);
                }
                a = DatasetUtils.cast(aa, dtype);
            }

            start = -System.nanoTime();
            try {
                c = Maths.add(a, dv);
            } catch (IllegalArgumentException e) {
                TestUtils.verbosePrintf("Could not perform this operation: %s\n\n", e.getMessage());
                eCount++;
                continue;
            }
            start += System.nanoTime();
            double ntime = ((double) start) / c.getSize();

            d = DatasetFactory.zeros(c);
            start = -System.nanoTime();
            IndexIterator ita = a.getIterator();
            int j = 0;
            if (dtype == Dataset.COMPLEX64 || dtype == Dataset.COMPLEX128) {
                final int is = d.getElementsPerItem();
                while (ita.hasNext()) {
                    d.setObjectAbs(j, ((Complex) a.getObjectAbs(ita.index)).add(zv));
                    j += is;
                }
            } else {
                if (dtype < Dataset.ARRAYINT8) {
                    while (ita.hasNext()) {
                        d.setObjectAbs(j++, ((Number) a.getObjectAbs(ita.index)).doubleValue() + dv);
                    }
                } else {
                    final double[] answer = new double[ISIZEA];
                    while (ita.hasNext()) {
                        for (int k = 0; k < ISIZEA; k++) {
                            answer[k] = a.getElementDoubleAbs(ita.index + k) + dv;
                        }
                        d.setObjectAbs(j, answer);
                        j += ISIZEA;
                    }
                }
            }
            if (d == null)
                break;
            start += System.nanoTime();

            double otime = ((double) start) / d.getSize();

            TestUtils.verbosePrintf("Time taken by add for %s: %s; %s (%.1f%%)\n", n, otime, ntime,
                    100. * (otime - ntime) / otime);
            checkDatasets(a, dv, c, d);

            n *= SSTEP;
        }
    }

    if (eCount > 0) {
        TestUtils.verbosePrintf("Number of exceptions caught: %d\n", eCount);
    }
}

From source file:org.eclipse.january.dataset.MathsTest.java

@Test
public void testSubtraction() {
    Dataset a, b, c = null, d = null;// www  . java  2 s .  co m
    Complex zv = new Complex(-3.5, 0);
    final double dv = zv.getReal();
    long start;
    int n;
    int eCount = 0;

    for (String dn : classes.keySet()) {
        final int dtype = classes.get(dn);
        Random.seed(12735L);
        for (String en : classes.keySet()) {
            final int etype = classes.get(en);

            TestUtils.verbosePrintf("%s to %s, ", dn, en);

            n = 32;
            for (int i = 0; i < SITER; i++) {
                if (dtype < Dataset.ARRAYINT8) {
                    a = Random.randn(n).imultiply(100);
                    a = a.cast(dtype);
                } else {
                    Dataset[] aa = new Dataset[ISIZEA];
                    for (int j = 0; j < ISIZEA; j++) {
                        aa[j] = Random.randn(n).imultiply(100);
                    }
                    a = DatasetUtils.cast(aa, dtype);
                }
                if (etype < Dataset.ARRAYINT8) {
                    b = Random.randn(n).imultiply(100);
                    b = b.cast(etype);
                } else {
                    Dataset[] ab = new Dataset[ISIZEB];
                    for (int j = 0; j < ISIZEB; j++) {
                        ab[j] = Random.randn(n).imultiply(100);
                    }
                    b = DatasetUtils.cast(ab, etype);
                }

                start = -System.nanoTime();
                try {
                    c = Maths.subtract(a, b);
                } catch (IllegalArgumentException e) {
                    TestUtils.verbosePrintf("Could not perform this operation: %s\n", e.getMessage());
                    eCount++;
                    continue;
                }
                start += System.nanoTime();
                double ntime = ((double) start) / c.getSize();

                d = DatasetFactory.zeros(c);
                start = -System.nanoTime();
                IndexIterator ita = a.getIterator();
                IndexIterator itb = b.getIterator();
                int j = 0;
                if ((dtype == Dataset.COMPLEX64 || dtype == Dataset.COMPLEX128)
                        && (etype == Dataset.COMPLEX64 || etype == Dataset.COMPLEX128)) {
                    final int is = d.getElementsPerItem();
                    while (ita.hasNext() && itb.hasNext()) {
                        d.setObjectAbs(j, ((Complex) a.getObjectAbs(ita.index))
                                .subtract((Complex) b.getObjectAbs(itb.index)));
                        j += is;
                    }
                } else if ((dtype == Dataset.COMPLEX64 || dtype == Dataset.COMPLEX128)
                        && !(etype == Dataset.COMPLEX64 || etype == Dataset.COMPLEX128)) {
                    final int is = d.getElementsPerItem();
                    while (ita.hasNext() && itb.hasNext()) {
                        d.setObjectAbs(j, ((Complex) a.getObjectAbs(ita.index))
                                .subtract(new Complex(b.getElementDoubleAbs(itb.index), 0)));
                        j += is;
                    }
                } else if (!(dtype == Dataset.COMPLEX64 || dtype == Dataset.COMPLEX128)
                        && (etype == Dataset.COMPLEX64 || etype == Dataset.COMPLEX128)) {
                    final int is = d.getElementsPerItem();
                    while (ita.hasNext() && itb.hasNext()) {
                        d.setObjectAbs(j, new Complex(a.getElementDoubleAbs(ita.index), 0)
                                .subtract((Complex) b.getObjectAbs(itb.index)));
                        j += is;
                    }
                } else {
                    if (dtype < Dataset.ARRAYINT8 && etype < Dataset.ARRAYINT8) {
                        while (ita.hasNext() && itb.hasNext()) {
                            d.setObjectAbs(j++, ((Number) a.getObjectAbs(ita.index)).doubleValue()
                                    - ((Number) b.getObjectAbs(itb.index)).doubleValue());
                        }
                    } else {
                        final double[] answer = new double[MAXISIZE];
                        final int is = d.getElementsPerItem();

                        if (a.getElementsPerItem() < is) {
                            while (ita.hasNext() && itb.hasNext()) {
                                final double da = a.getElementDoubleAbs(ita.index);
                                for (int k = 0; k < ISIZEB; k++) {
                                    answer[k] = da - b.getElementDoubleAbs(itb.index + k);
                                }
                                d.setObjectAbs(j, answer);
                                j += is;
                            }
                        } else if (b.getElementsPerItem() < is) {
                            while (ita.hasNext() && itb.hasNext()) {
                                final double db = b.getElementDoubleAbs(itb.index);
                                for (int k = 0; k < ISIZEA; k++) {
                                    answer[k] = a.getElementDoubleAbs(ita.index + k) - db;
                                }
                                d.setObjectAbs(j, answer);
                                j += is;
                            }
                        } else {
                            while (ita.hasNext() && itb.hasNext()) {
                                for (int k = 0; k < is; k++) {
                                    answer[k] = a.getElementDoubleAbs(ita.index + k)
                                            - b.getElementDoubleAbs(itb.index + k);
                                }
                                d.setObjectAbs(j, answer);
                                j += is;
                            }
                        }
                    }
                }
                if (d == null)
                    break;
                start += System.nanoTime();

                double otime = ((double) start) / d.getSize();
                TestUtils.verbosePrintf("Time taken by sub for %s: %s; %s (%.1f%%)\n", n, otime, ntime,
                        100. * (otime - ntime) / otime);
                checkDatasets(a, b, c, d);

                n *= SSTEP;
            }
        }

        Random.seed(12735L);
        n = 32;
        TestUtils.verbosePrintf("constant from %s, ", dn);
        for (int i = 0; i < SITER; i++) {
            if (dtype < Dataset.ARRAYINT8) {
                a = Random.randn(n);
                a.imultiply(100);
                a = a.cast(dtype);
            } else {
                Dataset[] aa = new Dataset[ISIZEA];
                for (int j = 0; j < ISIZEA; j++) {
                    aa[j] = Random.randn(n).imultiply(100);
                }
                a = DatasetUtils.cast(aa, dtype);
            }

            start = -System.nanoTime();
            try {
                c = Maths.subtract(a, dv);
            } catch (IllegalArgumentException e) {
                TestUtils.verbosePrintf("Could not perform this operation: %s\n", e.getMessage());
                eCount++;
                continue;
            }
            start += System.nanoTime();
            double ntime = ((double) start) / c.getSize();

            d = DatasetFactory.zeros(c);
            start = -System.nanoTime();
            IndexIterator ita = a.getIterator();
            int j = 0;
            if (dtype == Dataset.COMPLEX64 || dtype == Dataset.COMPLEX128) {
                final int is = d.getElementsPerItem();
                while (ita.hasNext()) {
                    d.setObjectAbs(j, ((Complex) a.getObjectAbs(ita.index)).subtract(zv));
                    j += is;
                }
            } else {
                if (dtype < Dataset.ARRAYINT8) {
                    while (ita.hasNext()) {
                        d.setObjectAbs(j++, ((Number) a.getObjectAbs(ita.index)).doubleValue() - dv);
                    }
                } else {
                    final double[] answer = new double[ISIZEA];
                    while (ita.hasNext()) {
                        for (int k = 0; k < ISIZEA; k++) {
                            answer[k] = a.getElementDoubleAbs(ita.index + k) - dv;
                        }
                        d.setObjectAbs(j, answer);
                        j += ISIZEA;
                    }
                }
            }
            if (d == null)
                break;
            start += System.nanoTime();
            double otime = ((double) start) / d.getSize();

            TestUtils.verbosePrintf("Time taken by add for %s: %s; %s (%.1f%%)\n", n, otime, ntime,
                    100. * (otime - ntime) / otime);
            checkDatasets(a, dv, c, d);

            n *= SSTEP;
        }

        Random.seed(12735L);
        n = 32;
        TestUtils.verbosePrintf("%s from constant, ", dn);
        for (int i = 0; i < SITER; i++) {
            if (dtype < Dataset.ARRAYINT8) {
                a = Random.randn(n);
                a.imultiply(100);
                a = a.cast(dtype);
            } else {
                Dataset[] aa = new Dataset[ISIZEA];
                for (int j = 0; j < ISIZEA; j++) {
                    aa[j] = Random.randn(n).imultiply(100);
                }
                a = DatasetUtils.cast(aa, dtype);
            }

            start = -System.nanoTime();
            try {
                c = Maths.subtract(dv, a);
            } catch (IllegalArgumentException e) {
                TestUtils.verbosePrintf("Could not perform this operation: %s\n", e.getMessage());
                eCount++;
                continue;
            }
            start += System.nanoTime();
            double ntime = ((double) start) / c.getSize();

            d = DatasetFactory.zeros(c);
            start = -System.nanoTime();
            IndexIterator ita = a.getIterator();
            int j = 0;
            if (dtype == Dataset.COMPLEX64 || dtype == Dataset.COMPLEX128) {
                final int is = d.getElementsPerItem();
                while (ita.hasNext()) {
                    d.setObjectAbs(j, zv.subtract((Complex) a.getObjectAbs(ita.index)));
                    j += is;
                }
            } else {
                if (dtype < Dataset.ARRAYINT8) {
                    while (ita.hasNext()) {
                        d.setObjectAbs(j++, dv - ((Number) a.getObjectAbs(ita.index)).doubleValue());
                    }
                } else {
                    final double[] answer = new double[ISIZEA];
                    while (ita.hasNext()) {
                        for (int k = 0; k < ISIZEA; k++) {
                            answer[k] = dv - a.getElementDoubleAbs(ita.index + k);
                        }
                        d.setObjectAbs(j, answer);
                        j += ISIZEA;
                    }
                }
            }
            if (d == null)
                break;
            start += System.nanoTime();
            double otime = ((double) start) / d.getSize();

            TestUtils.verbosePrintf("Time taken by sub for %s: %s; %s (%.1f%%)\n", n, otime, ntime,
                    100. * (otime - ntime) / otime);
            checkDatasets(dv, a, c, d);

            n *= SSTEP;
        }
    }

    if (eCount > 0) {
        TestUtils.verbosePrintf("Number of exceptions caught: %d\n", eCount);
    }
}

From source file:org.eclipse.january.dataset.MathsTest.java

@Test
public void testMultiplication() {
    Dataset a, b, c = null, d = null;//w ww . jav a 2 s .c o  m
    Complex zv = new Complex(-3.5, 0);
    final double dv = zv.getReal();
    long start;
    int n;
    int eCount = 0;

    for (String dn : classes.keySet()) {
        final int dtype = classes.get(dn);
        Random.seed(12735L);

        for (String en : classes.keySet()) {
            final int etype = classes.get(en);

            TestUtils.verbosePrintf("%s by %s, ", dn, en);
            n = 32;
            for (int i = 0; i < SITER; i++) {
                if (dtype < Dataset.ARRAYINT8) {
                    a = Random.randn(n).imultiply(100);
                    a = a.cast(dtype);
                } else {
                    Dataset[] aa = new Dataset[ISIZEA];
                    for (int j = 0; j < ISIZEA; j++) {
                        aa[j] = Random.randn(n).imultiply(100);
                    }
                    a = DatasetUtils.cast(aa, dtype);
                }
                if (etype < Dataset.ARRAYINT8) {
                    b = Random.randn(n).imultiply(100);
                    b = b.cast(etype);
                } else {
                    Dataset[] ab = new Dataset[ISIZEB];
                    for (int j = 0; j < ISIZEB; j++) {
                        ab[j] = Random.randn(n).imultiply(100);
                    }
                    b = DatasetUtils.cast(ab, etype);
                }

                start = -System.nanoTime();
                try {
                    c = Maths.multiply(a, b);
                } catch (IllegalArgumentException e) {
                    TestUtils.verbosePrintf("Could not perform this operation: %s\n", e.getMessage());
                    eCount++;
                    continue;
                }
                start += System.nanoTime();
                double ntime = ((double) start) / c.getSize();

                d = DatasetFactory.zeros(c);
                start = -System.nanoTime();
                IndexIterator ita = a.getIterator();
                IndexIterator itb = b.getIterator();
                int j = 0;
                if ((dtype == Dataset.COMPLEX64 || dtype == Dataset.COMPLEX128)
                        && (etype == Dataset.COMPLEX64 || etype == Dataset.COMPLEX128)) {
                    final int is = d.getElementsPerItem();
                    while (ita.hasNext() && itb.hasNext()) {
                        d.setObjectAbs(j, ((Complex) a.getObjectAbs(ita.index))
                                .multiply((Complex) b.getObjectAbs(itb.index)));
                        j += is;
                    }
                } else if ((dtype == Dataset.COMPLEX64 || dtype == Dataset.COMPLEX128)
                        && !(etype == Dataset.COMPLEX64 || etype == Dataset.COMPLEX128)) {
                    final int is = d.getElementsPerItem();
                    while (ita.hasNext() && itb.hasNext()) {
                        d.setObjectAbs(j, ((Complex) a.getObjectAbs(ita.index))
                                .multiply(b.getElementDoubleAbs(itb.index)));
                        j += is;
                    }
                } else if (!(dtype == Dataset.COMPLEX64 || dtype == Dataset.COMPLEX128)
                        && (etype == Dataset.COMPLEX64 || etype == Dataset.COMPLEX128)) {
                    final int is = d.getElementsPerItem();
                    while (ita.hasNext() && itb.hasNext()) {
                        d.setObjectAbs(j, new Complex(a.getElementDoubleAbs(ita.index), 0)
                                .multiply((Complex) b.getObjectAbs(itb.index)));
                        j += is;
                    }
                } else {
                    if (dtype < Dataset.ARRAYINT8 && etype < Dataset.ARRAYINT8) {
                        while (ita.hasNext() && itb.hasNext()) {
                            d.setObjectAbs(j++, ((Number) a.getObjectAbs(ita.index)).doubleValue()
                                    * ((Number) b.getObjectAbs(itb.index)).doubleValue());
                        }
                    } else {
                        final double[] answer = new double[MAXISIZE];
                        final int is = d.getElementsPerItem();

                        if (a.getElementsPerItem() < is) {
                            while (ita.hasNext() && itb.hasNext()) {
                                final double da = a.getElementDoubleAbs(ita.index);
                                for (int k = 0; k < ISIZEB; k++) {
                                    answer[k] = da * b.getElementDoubleAbs(itb.index + k);
                                }
                                d.setObjectAbs(j, answer);
                                j += is;
                            }
                        } else if (b.getElementsPerItem() < is) {
                            while (ita.hasNext() && itb.hasNext()) {
                                final double db = b.getElementDoubleAbs(itb.index);
                                for (int k = 0; k < ISIZEA; k++) {
                                    answer[k] = a.getElementDoubleAbs(ita.index + k) * db;
                                }
                                d.setObjectAbs(j, answer);
                                j += is;
                            }
                        } else {
                            while (ita.hasNext() && itb.hasNext()) {
                                for (int k = 0; k < is; k++) {
                                    answer[k] = a.getElementDoubleAbs(ita.index + k)
                                            * b.getElementDoubleAbs(itb.index + k);
                                }
                                d.setObjectAbs(j, answer);
                                j += is;
                            }
                        }
                    }
                }
                if (d == null)
                    break;
                start += System.nanoTime();
                double otime = ((double) start) / d.getSize();

                TestUtils.verbosePrintf("Time taken by mul for %s: %s; %s (%.1f%%)\n", n, otime, ntime,
                        100. * (otime - ntime) / otime);

                checkDatasets(a, b, c, d);

                n *= SSTEP;
            }
        }

        Random.seed(12735L);
        n = 32;
        TestUtils.verbosePrintf("constant with %s, ", dn);
        for (int i = 0; i < SITER; i++) {
            if (dtype < Dataset.ARRAYINT8) {
                a = Random.randn(n);
                a.imultiply(100);
                a = a.cast(dtype);
            } else {
                Dataset[] aa = new Dataset[ISIZEA];
                for (int j = 0; j < ISIZEA; j++) {
                    aa[j] = Random.randn(n).imultiply(100);
                }
                a = DatasetUtils.cast(aa, dtype);
            }

            start = -System.nanoTime();
            try {
                c = Maths.multiply(a, dv);
            } catch (IllegalArgumentException e) {
                TestUtils.verbosePrintf("Could not perform this operation: %s\n", e.getMessage());
                eCount++;
                continue;
            }
            start += System.nanoTime();
            double ntime = ((double) start) / c.getSize();

            d = DatasetFactory.zeros(c);
            start = -System.nanoTime();
            IndexIterator ita = a.getIterator();
            int j = 0;
            if (dtype == Dataset.COMPLEX64 || dtype == Dataset.COMPLEX128) {
                final int is = d.getElementsPerItem();
                while (ita.hasNext()) {
                    d.setObjectAbs(j, ((Complex) a.getObjectAbs(ita.index)).multiply(zv));
                    j += is;
                }
            } else {
                if (dtype < Dataset.ARRAYINT8) {
                    while (ita.hasNext()) {
                        d.setObjectAbs(j++, ((Number) a.getObjectAbs(ita.index)).doubleValue() * dv);
                    }
                } else {
                    final double[] answer = new double[ISIZEA];
                    while (ita.hasNext()) {
                        for (int k = 0; k < ISIZEA; k++) {
                            answer[k] = a.getElementDoubleAbs(ita.index + k) * dv;
                        }
                        d.setObjectAbs(j, answer);
                        j += ISIZEA;
                    }
                }
            }
            if (d == null)
                break;
            start += System.nanoTime();
            double otime = ((double) start) / d.getSize();

            TestUtils.verbosePrintf("Time taken by mul for %s: %s; %s (%.1f%%)\n", n, otime, ntime,
                    100. * (otime - ntime) / otime);
            checkDatasets(a, dv, c, d);

            n *= SSTEP;
        }
    }

    if (eCount > 0) {
        TestUtils.verbosePrintf("Number of exceptions caught: %d\n", eCount);
    }
}