Example usage for java.lang Math cosh

List of usage examples for java.lang Math cosh

Introduction

In this page you can find the example usage for java.lang Math cosh.

Prototype

public static double cosh(double x) 

Source Link

Document

Returns the hyperbolic cosine of a double value.

Usage

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

/**
 * cos - evaluate the cosine function on each element of the dataset
 * @param a// ww  w.  ja  v  a2s.c o m
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset cos(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.cos(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.cos(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.cos(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.cos(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.cos(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.cos(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.cos(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.cos(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.cos(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.cos(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.cos(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.cos(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.cos(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.cos(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.cos(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.cos(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.cos(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.cos(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.cos(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.cos(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.cos(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.cos(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.cos(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.cos(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.cos(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.cos(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.cos(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.cos(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.cos(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.cos(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.cos(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.cos(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.cos(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.cos(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.cos(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.cos(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.cos(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.cos(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.cos(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.cos(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.cos(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.cos(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.cos(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.cos(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.cos(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.cos(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.cos(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.cos(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;
                float ox;
                float oy;
                ox = (float) (Math.cos(ix) * Math.cosh(iy));
                oy = (float) (-Math.sin(ix) * Math.sinh(iy));
                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);
                float ox;
                float oy;
                ox = (float) (Math.cos(ix) * Math.cosh(iy));
                oy = (float) (-Math.sin(ix) * Math.sinh(iy));
                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;
                double ox;
                double oy;
                ox = (Math.cos(ix) * Math.cosh(iy));
                oy = (-Math.sin(ix) * Math.sinh(iy));
                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);
                double ox;
                double oy;
                ox = (Math.cos(ix) * Math.cosh(iy));
                oy = (-Math.sin(ix) * Math.sinh(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "cos supports integer, compound integer, real, compound real, complex datasets only");
    }

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

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

/**
 * tan - evaluate the tangent function on each element of the dataset
 * @param a//from w  w w .  j a  v  a2s.c  o  m
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset tan(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.tan(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.tan(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.tan(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.tan(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.tan(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.tan(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.tan(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.tan(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.tan(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.tan(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.tan(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.tan(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.tan(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.tan(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.tan(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.tan(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.tan(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.tan(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.tan(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.tan(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.tan(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.tan(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.tan(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.tan(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.tan(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.tan(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.tan(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.tan(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.tan(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.tan(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.tan(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.tan(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.tan(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.tan(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.tan(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.tan(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.tan(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.tan(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.tan(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.tan(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.tan(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.tan(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.tan(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.tan(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.tan(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.tan(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.tan(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.tan(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;
                float x;
                float y;
                float tf;
                float ox;
                float oy;
                x = (float) (2. * ix);
                y = (float) (2. * iy);
                tf = (float) (1. / (Math.cos(x) + Math.cosh(y)));
                ox = (float) (tf * Math.sin(x));
                oy = (float) (tf * Math.sinh(y));
                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);
                float x;
                float y;
                float tf;
                float ox;
                float oy;
                x = (float) (2. * ix);
                y = (float) (2. * iy);
                tf = (float) (1. / (Math.cos(x) + Math.cosh(y)));
                ox = (float) (tf * Math.sin(x));
                oy = (float) (tf * Math.sinh(y));
                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;
                double x;
                double y;
                double tf;
                double ox;
                double oy;
                x = (2. * ix);
                y = (2. * iy);
                tf = (1. / (Math.cos(x) + Math.cosh(y)));
                ox = (tf * Math.sin(x));
                oy = (tf * Math.sinh(y));
                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);
                double x;
                double y;
                double tf;
                double ox;
                double oy;
                x = (2. * ix);
                y = (2. * iy);
                tf = (1. / (Math.cos(x) + Math.cosh(y)));
                ox = (tf * Math.sin(x));
                oy = (tf * Math.sinh(y));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "tan supports integer, compound integer, real, compound real, complex datasets only");
    }

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

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

/**
 * sinh - evaluate the hyperbolic sine function on each element of the dataset
 * @param a/*  w w w  .  ja  v  a 2 s.c o  m*/
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset sinh(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.sinh(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.sinh(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.sinh(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.sinh(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.sinh(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.sinh(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.sinh(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.sinh(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.sinh(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.sinh(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.sinh(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.sinh(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.sinh(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.sinh(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.sinh(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.sinh(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.sinh(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.sinh(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.sinh(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.sinh(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.sinh(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.sinh(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.sinh(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.sinh(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.sinh(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.sinh(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.sinh(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.sinh(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.sinh(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.sinh(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.sinh(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.sinh(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.sinh(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.sinh(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.sinh(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.sinh(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.sinh(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.sinh(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.sinh(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.sinh(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.sinh(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.sinh(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.sinh(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.sinh(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.sinh(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.sinh(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.sinh(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.sinh(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;
                float ox;
                float oy;
                ox = (float) (Math.sinh(ix) * Math.cos(iy));
                oy = (float) (Math.cosh(ix) * Math.sin(iy));
                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);
                float ox;
                float oy;
                ox = (float) (Math.sinh(ix) * Math.cos(iy));
                oy = (float) (Math.cosh(ix) * Math.sin(iy));
                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;
                double ox;
                double oy;
                ox = (Math.sinh(ix) * Math.cos(iy));
                oy = (Math.cosh(ix) * Math.sin(iy));
                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);
                double ox;
                double oy;
                ox = (Math.sinh(ix) * Math.cos(iy));
                oy = (Math.cosh(ix) * Math.sin(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "sinh supports integer, compound integer, real, compound real, complex datasets only");
    }

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

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

/**
 * cosh - evaluate the hyperbolic cosine function on each element of the dataset
 * @param a//  www  .j  a v a 2 s .  c  o  m
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset cosh(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.cosh(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.cosh(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.cosh(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.cosh(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.cosh(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.cosh(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.cosh(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.cosh(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.cosh(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.cosh(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.cosh(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.cosh(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.cosh(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.cosh(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.cosh(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.cosh(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.cosh(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.cosh(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.cosh(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.cosh(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.cosh(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.cosh(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.cosh(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.cosh(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.cosh(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.cosh(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.cosh(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.cosh(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.cosh(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.cosh(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.cosh(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.cosh(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.cosh(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.cosh(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.cosh(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.cosh(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.cosh(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.cosh(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.cosh(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.cosh(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.cosh(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.cosh(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.cosh(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.cosh(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.cosh(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.cosh(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.cosh(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.cosh(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;
                float ox;
                float oy;
                ox = (float) (Math.cosh(ix) * Math.cos(iy));
                oy = (float) (Math.sinh(ix) * Math.sin(iy));
                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);
                float ox;
                float oy;
                ox = (float) (Math.cosh(ix) * Math.cos(iy));
                oy = (float) (Math.sinh(ix) * Math.sin(iy));
                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;
                double ox;
                double oy;
                ox = (Math.cosh(ix) * Math.cos(iy));
                oy = (Math.sinh(ix) * Math.sin(iy));
                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);
                double ox;
                double oy;
                ox = (Math.cosh(ix) * Math.cos(iy));
                oy = (Math.sinh(ix) * Math.sin(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "cosh supports integer, compound integer, real, compound real, complex datasets only");
    }

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

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

/**
 * tanh - evaluate the tangent hyperbolic function on each element of the dataset
 * @param a/*www  .ja  v a2 s  .  c  o  m*/
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset tanh(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.tanh(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.tanh(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.tanh(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.tanh(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.tanh(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.tanh(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.tanh(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.tanh(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.tanh(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.tanh(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.tanh(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.tanh(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.tanh(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.tanh(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.tanh(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.tanh(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.tanh(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.tanh(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.tanh(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.tanh(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.tanh(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.tanh(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.tanh(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.tanh(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.tanh(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.tanh(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.tanh(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.tanh(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.tanh(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.tanh(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.tanh(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.tanh(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.tanh(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.tanh(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.tanh(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.tanh(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.tanh(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.tanh(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.tanh(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.tanh(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.tanh(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.tanh(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.tanh(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.tanh(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.tanh(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.tanh(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.tanh(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.tanh(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;
                float tx;
                float ty;
                float tf;
                float ox;
                float oy;
                tx = (float) (2. * ix);
                ty = (float) (2. * iy);
                tf = (float) (1. / (Math.cos(tx) + Math.cosh(ty)));
                ox = (float) (tf * Math.sinh(tx));
                oy = (float) (tf * Math.sin(ty));
                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);
                float tx;
                float ty;
                float tf;
                float ox;
                float oy;
                tx = (float) (2. * ix);
                ty = (float) (2. * iy);
                tf = (float) (1. / (Math.cos(tx) + Math.cosh(ty)));
                ox = (float) (tf * Math.sinh(tx));
                oy = (float) (tf * Math.sin(ty));
                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;
                double tx;
                double ty;
                double tf;
                double ox;
                double oy;
                tx = (2. * ix);
                ty = (2. * iy);
                tf = (1. / (Math.cos(tx) + Math.cosh(ty)));
                ox = (tf * Math.sinh(tx));
                oy = (tf * Math.sin(ty));
                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);
                double tx;
                double ty;
                double tf;
                double ox;
                double oy;
                tx = (2. * ix);
                ty = (2. * iy);
                tf = (1. / (Math.cos(tx) + Math.cosh(ty)));
                ox = (tf * Math.sinh(tx));
                oy = (tf * Math.sin(ty));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "tanh supports integer, compound integer, real, compound real, complex datasets only");
    }

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

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

/**
 * sin - evaluate the sine function on each element of the dataset
 * @param a//from   www  .j  a  v  a 2 s  .com
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset sin(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 as = da.getElementsPerItem();
    final int dt = result.getDType();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(Math.sin(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.sin(ix));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(Math.sin(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.sin(ix));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(Math.sin(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.sin(ix));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(Math.sin(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.sin(ix));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.sin(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.sin(ix));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.sin(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.sin(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.sin(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.sin(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.sin(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.sin(ix));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.sin(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.sin(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.sin(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.sin(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.sin(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.sin(ix));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.sin(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.sin(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.sin(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.sin(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.sin(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.sin(ix));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.sin(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.sin(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.sin(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.sin(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (Math.sin(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.sin(ix));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (Math.sin(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.sin(ix));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.sin(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.sin(ix));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.sin(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.sin(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.sin(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.sin(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.sin(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.sin(ix));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.sin(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.sin(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.sin(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.sin(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).getData();
        if (as == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                float oy;
                ox = (float) (Math.sin(ix) * Math.cosh(iy));
                oy = (float) (Math.cos(ix) * Math.sinh(iy));
                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);
                float ox;
                float oy;
                ox = (float) (Math.sin(ix) * Math.cosh(iy));
                oy = (float) (Math.cos(ix) * Math.sinh(iy));
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
        if (as == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                double oy;
                ox = (Math.sin(ix) * Math.cosh(iy));
                oy = (Math.cos(ix) * Math.sinh(iy));
                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);
                double ox;
                double oy;
                ox = (Math.sin(ix) * Math.cosh(iy));
                oy = (Math.cos(ix) * Math.sinh(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "sin supports integer, compound integer, real, compound real, complex datasets only");
    }

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

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

/**
 * cos - evaluate the cosine function on each element of the dataset
 * @param a/*from  ww  w .  jav  a  2 s .  co m*/
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset cos(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 as = da.getElementsPerItem();
    final int dt = result.getDType();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(Math.cos(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.cos(ix));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(Math.cos(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.cos(ix));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(Math.cos(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.cos(ix));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(Math.cos(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.cos(ix));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.cos(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.cos(ix));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.cos(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.cos(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.cos(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.cos(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.cos(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.cos(ix));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.cos(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.cos(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.cos(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.cos(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.cos(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.cos(ix));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.cos(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.cos(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.cos(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.cos(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.cos(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.cos(ix));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.cos(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.cos(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.cos(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.cos(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (Math.cos(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.cos(ix));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (Math.cos(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.cos(ix));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.cos(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.cos(ix));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.cos(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.cos(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.cos(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.cos(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.cos(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.cos(ix));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.cos(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.cos(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.cos(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.cos(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).getData();
        if (as == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                float oy;
                ox = (float) (Math.cos(ix) * Math.cosh(iy));
                oy = (float) (-Math.sin(ix) * Math.sinh(iy));
                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);
                float ox;
                float oy;
                ox = (float) (Math.cos(ix) * Math.cosh(iy));
                oy = (float) (-Math.sin(ix) * Math.sinh(iy));
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
        if (as == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                double oy;
                ox = (Math.cos(ix) * Math.cosh(iy));
                oy = (-Math.sin(ix) * Math.sinh(iy));
                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);
                double ox;
                double oy;
                ox = (Math.cos(ix) * Math.cosh(iy));
                oy = (-Math.sin(ix) * Math.sinh(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "cos supports integer, compound integer, real, compound real, complex datasets only");
    }

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

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

/**
 * tan - evaluate the tangent function on each element of the dataset
 * @param a//from w w w .  ja va  2s.c  om
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset tan(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 as = da.getElementsPerItem();
    final int dt = result.getDType();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(Math.tan(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.tan(ix));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(Math.tan(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.tan(ix));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(Math.tan(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.tan(ix));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(Math.tan(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.tan(ix));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.tan(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.tan(ix));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.tan(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.tan(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.tan(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.tan(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.tan(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.tan(ix));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.tan(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.tan(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.tan(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.tan(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.tan(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.tan(ix));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.tan(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.tan(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.tan(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.tan(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.tan(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.tan(ix));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.tan(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.tan(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.tan(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.tan(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (Math.tan(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.tan(ix));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (Math.tan(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.tan(ix));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.tan(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.tan(ix));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.tan(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.tan(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.tan(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.tan(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.tan(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.tan(ix));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.tan(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.tan(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.tan(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.tan(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).getData();
        if (as == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float x;
                float y;
                float tf;
                float ox;
                float oy;
                x = (float) (2. * ix);
                y = (float) (2. * iy);
                tf = (float) (1. / (Math.cos(x) + Math.cosh(y)));
                ox = (float) (tf * Math.sin(x));
                oy = (float) (tf * Math.sinh(y));
                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);
                float x;
                float y;
                float tf;
                float ox;
                float oy;
                x = (float) (2. * ix);
                y = (float) (2. * iy);
                tf = (float) (1. / (Math.cos(x) + Math.cosh(y)));
                ox = (float) (tf * Math.sin(x));
                oy = (float) (tf * Math.sinh(y));
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
        if (as == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double x;
                double y;
                double tf;
                double ox;
                double oy;
                x = (2. * ix);
                y = (2. * iy);
                tf = (1. / (Math.cos(x) + Math.cosh(y)));
                ox = (tf * Math.sin(x));
                oy = (tf * Math.sinh(y));
                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);
                double x;
                double y;
                double tf;
                double ox;
                double oy;
                x = (2. * ix);
                y = (2. * iy);
                tf = (1. / (Math.cos(x) + Math.cosh(y)));
                ox = (tf * Math.sin(x));
                oy = (tf * Math.sinh(y));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "tan supports integer, compound integer, real, compound real, complex datasets only");
    }

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

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

/**
 * sinh - evaluate the hyperbolic sine function on each element of the dataset
 * @param a//from  w  w  w.j a  v a  2s . co m
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset sinh(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 as = da.getElementsPerItem();
    final int dt = result.getDType();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(Math.sinh(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.sinh(ix));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(Math.sinh(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.sinh(ix));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(Math.sinh(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.sinh(ix));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(Math.sinh(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.sinh(ix));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.sinh(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.sinh(ix));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.sinh(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.sinh(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.sinh(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.sinh(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.sinh(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.sinh(ix));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.sinh(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.sinh(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.sinh(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.sinh(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.sinh(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.sinh(ix));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.sinh(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.sinh(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.sinh(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.sinh(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.sinh(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.sinh(ix));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.sinh(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.sinh(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.sinh(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.sinh(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (Math.sinh(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.sinh(ix));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (Math.sinh(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.sinh(ix));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.sinh(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.sinh(ix));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.sinh(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.sinh(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.sinh(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.sinh(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.sinh(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.sinh(ix));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.sinh(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.sinh(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.sinh(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.sinh(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).getData();
        if (as == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                float oy;
                ox = (float) (Math.sinh(ix) * Math.cos(iy));
                oy = (float) (Math.cosh(ix) * Math.sin(iy));
                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);
                float ox;
                float oy;
                ox = (float) (Math.sinh(ix) * Math.cos(iy));
                oy = (float) (Math.cosh(ix) * Math.sin(iy));
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
        if (as == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                double oy;
                ox = (Math.sinh(ix) * Math.cos(iy));
                oy = (Math.cosh(ix) * Math.sin(iy));
                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);
                double ox;
                double oy;
                ox = (Math.sinh(ix) * Math.cos(iy));
                oy = (Math.cosh(ix) * Math.sin(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "sinh supports integer, compound integer, real, compound real, complex datasets only");
    }

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

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

/**
 * cosh - evaluate the hyperbolic cosine function on each element of the dataset
 * @param a/*from  w  w w.j a v  a2s. c o m*/
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset cosh(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 as = da.getElementsPerItem();
    final int dt = result.getDType();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(Math.cosh(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.cosh(ix));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(Math.cosh(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.cosh(ix));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(Math.cosh(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.cosh(ix));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(Math.cosh(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.cosh(ix));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.cosh(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.cosh(ix));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.cosh(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.cosh(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.cosh(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.cosh(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.cosh(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.cosh(ix));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.cosh(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.cosh(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.cosh(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.cosh(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.cosh(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.cosh(ix));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.cosh(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.cosh(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.cosh(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.cosh(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.cosh(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.cosh(ix));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.cosh(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.cosh(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.cosh(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.cosh(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (Math.cosh(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.cosh(ix));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (Math.cosh(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.cosh(ix));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.cosh(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.cosh(ix));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.cosh(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.cosh(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.cosh(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.cosh(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.cosh(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.cosh(ix));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.cosh(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.cosh(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.cosh(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.cosh(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).getData();
        if (as == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                float oy;
                ox = (float) (Math.cosh(ix) * Math.cos(iy));
                oy = (float) (Math.sinh(ix) * Math.sin(iy));
                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);
                float ox;
                float oy;
                ox = (float) (Math.cosh(ix) * Math.cos(iy));
                oy = (float) (Math.sinh(ix) * Math.sin(iy));
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
        if (as == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                double oy;
                ox = (Math.cosh(ix) * Math.cos(iy));
                oy = (Math.sinh(ix) * Math.sin(iy));
                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);
                double ox;
                double oy;
                ox = (Math.cosh(ix) * Math.cos(iy));
                oy = (Math.sinh(ix) * Math.sin(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "cosh supports integer, compound integer, real, compound real, complex datasets only");
    }

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