    001/*-
    002 *******************************************************************************
    003 * Copyright (c) 2011, 2016 Diamond Light Source Ltd.
    004 * All rights reserved. This program and the accompanying materials
    005 * are made available under the terms of the Eclipse Public License v1.0
    006 * which accompanies this distribution, and is available at
    007 * http://www.eclipse.org/legal/epl-v10.html
    008 *
    009 * Contributors:
    010 *    Peter Chang - initial API and implementation and/or initial documentation
    011 *******************************************************************************/
    012
    013// This is generated from CompoundDoubleDataset.java by fromcpddouble.py
    014
    015package org.eclipse.january.dataset;
    016
    017import java.util.Arrays;
    018
    019import org.apache.commons.math3.complex.Complex;
    020
    021/**
    022 * Extend compound dataset for float values // PRIM_TYPE
    023 */
    024public class CompoundFloatDataset extends AbstractCompoundDataset {
    025        // pin UID to base class
    026        private static final long serialVersionUID = Dataset.serialVersionUID;
    027
    028        protected float[] data; // subclass alias // PRIM_TYPE
    029
    030        @Override
    031        protected void setData() {
    032                data = (float[]) odata; // PRIM_TYPE
    033        }
    034
    035        protected float[] createArray(final int size) { // PRIM_TYPE
    036                float[] array = null; // PRIM_TYPE
    037
    038                try {
    039                        array = new float[isize * size]; // PRIM_TYPE
    040                } catch (OutOfMemoryError e) {
    041                        logger.error("The size of the dataset ({}) that is being created is too large "
    042                                        + "and there is not enough memory to hold it.", size);
    043                        throw new OutOfMemoryError("The dimensions given are too large, and there is "
    044                                        + "not enough memory available in the Java Virtual Machine");
    045                }
    046                return array;
    047        }
    048
    049        @Override
    050        public int getDType() {
    051                return Dataset.ARRAYFLOAT32; // DATA_TYPE
    052        }
    053
    054        /**
    055         * Create a null dataset
    056         */
    057        CompoundFloatDataset() {
    058        }
    059
    060        /**
    061         * Create a null dataset
    062         * @param itemSize
    063         */
    064        CompoundFloatDataset(final int itemSize) {
    065                isize = itemSize;
    066        }
    067
    068        /**
    069         * Create a zero-filled dataset of given item size and shape
    070         * @param itemSize
    071         * @param shape
    072         */
    073        CompoundFloatDataset(final int itemSize, final int[] shape) {
    074                isize = itemSize;
    075                if (shape != null) {
    076                        size = ShapeUtils.calcSize(shape);
    077                        this.shape = shape.clone();
    078
    079                        try {
    080                                odata = data = createArray(size);
    081                        } catch (Throwable t) {
    082                                logger.error("Could not create a dataset of shape {}", Arrays.toString(shape), t);
    083                                throw new IllegalArgumentException(t);
    084                        }
    085                }
    086        }
    087
    088        /**
    089         * Copy a dataset
    090         * @param dataset
    091         */
    092        CompoundFloatDataset(final CompoundFloatDataset dataset) {
    093                isize = dataset.isize;
    094
    095                copyToView(dataset, this, true, true);
    096                try {
    097                        if (dataset.stride == null) {
    098                                if (dataset.data != null) {
    099                                        odata = data = dataset.data.clone();
    100                                }
    101                        } else {
    102                                offset = 0;
    103                                stride = null;
    104                                base = null;
    105                                odata = data = createArray(size);
    106                                IndexIterator iter = dataset.getIterator();
    107                                for (int j = 0; iter.hasNext();) {
    108                                        for (int i = 0; i < isize; i++) {
    109                                                data[j++] = dataset.data[iter.index + i];
    110                                        }
    111                                }
    112                        }
    113                } catch (Throwable t) {
    114                        logger.error("Could not create a dataset of shape {}", Arrays.toString(shape), t);
    115                        throw new IllegalArgumentException(t);
    116                }
    117        }
    118
    119        /**
    120         * Create a dataset using given dataset
    121         * @param dataset
    122         */
    123        CompoundFloatDataset(final CompoundDataset dataset) {
    124                copyToView(dataset, this, true, false);
    125                offset = 0;
    126                stride = null;
    127                base = null;
    128                isize = dataset.getElementsPerItem();
    129                try {
    130                        odata = data = createArray(size);
    131                } catch (Throwable t) {
    132                        logger.error("Could not create a dataset of shape {}", Arrays.toString(shape), t);
    133                        throw new IllegalArgumentException(t);
    134                }
    135
    136                IndexIterator iter = dataset.getIterator();
    137                for (int j = 0; iter.hasNext();) {
    138                        for (int i = 0; i < isize; i++) {
    139                                data[j++] = (float) dataset.getElementDoubleAbs(iter.index + i); // GET_ELEMENT_WITH_CAST
    140                        }
    141                }
    142        }
    143
    144        /**
    145         * Create a dataset using given data (elements are grouped together)
    146         * @param itemSize
    147         * @param data
    148         * @param shape
    149         *            (can be null to create 1D dataset)
    150         */
    151        CompoundFloatDataset(final int itemSize, final float[] data, int... shape) { // PRIM_TYPE
    152                isize = itemSize;
    153                if (data != null) {
    154                        if (shape == null || (shape.length == 0 && data.length > isize)) {
    155                                shape = new int[] { data.length / isize };
    156                        }
    157                        size = ShapeUtils.calcSize(shape);
    158                        if (size * isize != data.length) {
    159                                throw new IllegalArgumentException(String.format("Shape %s is not compatible with size of data array, %d",
    160                                                Arrays.toString(shape), data.length / isize));
    161                        }
    162                        this.shape = size == 0 ? null : shape.clone();
    163
    164                        odata = this.data = data;
    165                }
    166        }
    167
    168        /**
    169         * Create a dataset using given datasets
    170         * @param datasets
    171         */
    172        CompoundFloatDataset(final Dataset... datasets) {
    173                if (datasets.length < 1) {
    174                        throw new IllegalArgumentException("Array of datasets must have length greater than zero");
    175                }
    176
    177                for (int i = 1; i < datasets.length; i++) {
    178                        datasets[0].checkCompatibility(datasets[i]);
    179                }
    180
    181                isize = datasets.length;
    182                size = ShapeUtils.calcSize(datasets[0].getShapeRef());
    183                shape = datasets[0].getShape();
    184
    185                try {
    186                        odata = data = createArray(size);
    187                } catch (Throwable t) {
    188                        logger.error("Could not create a dataset of shape {}", Arrays.toString(shape), t);
    189                        throw new IllegalArgumentException(t);
    190                }
    191
    192                IndexIterator[] iters = new IndexIterator[isize];
    193                for (int i = 0; i < datasets.length; i++) {
    194                        iters[i] = datasets[i].getIterator();
    195                }
    196
    197                for (int j = 0; iters[0].hasNext();) {
    198                        data[j++] = (float) datasets[0].getElementDoubleAbs(iters[0].index); // GET_ELEMENT_WITH_CAST
    199                        for (int i = 1; i < datasets.length; i++) {
    200                                iters[i].hasNext();
    201                                data[j++] = (float) datasets[i].getElementDoubleAbs(iters[i].index); // GET_ELEMENT_WITH_CAST
    202                        }
    203                }
    204        }
    205
    206        /**
    207         * Cast a dataset to this compound type. If repeat is set, the first element of each item in the given dataset is
    208         * repeated across all elements of an item. Otherwise, each item comprises a truncated or zero-padded copy of
    209         * elements from the given dataset.
    210         * @param itemSize
    211         * @param repeat
    212         *            repeat first element
    213         * @param dataset
    214         */
    215        CompoundFloatDataset(final int itemSize, final boolean repeat, final Dataset dataset) {
    216                isize = itemSize;
    217                size = dataset.getSize();
    218                shape = dataset.getShape();
    219                name = new String(dataset.getName());
    220
    221                try {
    222                        odata = data = createArray(size);
    223                } catch (Throwable t) {
    224                        logger.error("Could not create a dataset of shape {}", Arrays.toString(shape), t);
    225                        throw new IllegalArgumentException(t);
    226                }
    227                final int os = dataset.getElementsPerItem();
    228
    229                IndexIterator iter = dataset.getIterator();
    230                if (repeat) {
    231                        int i = 0;
    232                        while (iter.hasNext()) {
    233                                final float v = (float) dataset.getElementDoubleAbs(iter.index); // PRIM_TYPE // GET_ELEMENT_WITH_CAST
    234                                for (int k = 0; k < isize; k++) {
    235                                        data[i++] = v;
    236                                }
    237                        }
    238                } else {
    239                        final int kmax = Math.min(isize, os);
    240                        int i = 0;
    241                        while (iter.hasNext()) {
    242                                for (int k = 0; k < kmax; k++) {
    243                                        data[i + k] = (float) dataset.getElementDoubleAbs(iter.index + k); // GET_ELEMENT_WITH_CAST
    244                                }
    245                                i += isize;
    246                        }
    247                }
    248        }
    249
    250        @Override
    251        public boolean equals(Object obj) {
    252                if (this == obj) {
    253                        return true;
    254                }
    255
    256                if (obj == null) {
    257                        return false;
    258                }
    259
    260                if (!getClass().equals(obj.getClass())) {
    261                        if (getRank() == 0) { // for zero-rank datasets
    262                                return obj.equals(getObjectAbs(offset));
    263                        }
    264                        return false;
    265                }
    266
    267                CompoundFloatDataset other = (CompoundFloatDataset) obj;
    268                if (isize != other.isize) {
    269                        return false;
    270                }
    271                if (size != other.size) {
    272                        return false;
    273                }
    274                if (!Arrays.equals(shape, other.shape)) {
    275                        return false;
    276                }
    277                if (data == other.data && stride == null && other.stride == null) {
    278                        return true;
    279                }
    280
    281                IndexIterator iter = getIterator();
    282                IndexIterator oiter = other.getIterator();
    283                while (iter.hasNext() && oiter.hasNext()) {
    284                        for (int j = 0; j < isize; j++) {
    285                                if (data[iter.index+j] != other.data[oiter.index+j]) {
    286                                        return false;
    287                                }
    288                        }
    289                }
    290                return true;
    291        }
    292
    293        @Override
    294        public int hashCode() {
    295                return super.hashCode();
    296        }
    297
    298        @Override
    299        public CompoundFloatDataset clone() {
    300                return new CompoundFloatDataset(this);
    301        }
    302
    303        /**
    304         * Create a dataset from an object which could be a Java list, array (of arrays...) or Number. Ragged
    305         * sequences or arrays are padded with zeros. The item size is the last dimension of the corresponding
    306         * elemental dataset
    307         *
    308         * @param obj
    309         * @return dataset with contents given by input
    310         */
    311        static CompoundFloatDataset createFromObject(final Object obj) {
    312                FloatDataset result = FloatDataset.createFromObject(obj); // CLASS_TYPE
    313                return createCompoundDatasetWithLastDimension(result, true);
    314        }
    315
    316        /**
    317         * Create a 1D dataset from an object which could be a Java list, array (of arrays...) or Number. Ragged
    318         * sequences or arrays are padded with zeros.
    319         *
    320         * @param itemSize
    321         * @param obj
    322         * @return dataset with contents given by input
    323         */
    324        public static CompoundFloatDataset createFromObject(final int itemSize, final Object obj) {
    325                FloatDataset result = FloatDataset.createFromObject(obj); // CLASS_TYPE
    326                boolean zeroRank = result.shape == null ? false : result.shape.length == 0;
    327                if (zeroRank) {
    328                        result.resize(itemSize); // special case of single item
    329                        result.fill(obj);
    330                }
    331                CompoundFloatDataset ds = new CompoundFloatDataset(itemSize, result.getData(), null);
    332                if (zeroRank) {
    333                        ds.setShape(new int[0]);
    334                }
    335                return ds;
    336        }
    337
    338        /**
    339         * @param stop
    340         * @return a new 1D dataset, filled with values determined by parameters
    341         */
    342        static CompoundFloatDataset createRange(final int itemSize, final double stop) {
    343                return createRange(itemSize, 0., stop, 1.);
    344        }
    345
    346        /**
    347         * @param start
    348         * @param stop
    349         * @param step
    350         * @return a new 1D dataset, filled with values determined by parameters
    351         */
    352        static CompoundFloatDataset createRange(final int itemSize, final double start, final double stop,
    353                        final double step) {
    354                int size = calcSteps(start, stop, step);
    355                CompoundFloatDataset result = new CompoundFloatDataset(itemSize, new int[] { size });
    356                for (int i = 0; i < size; i++) {
    357                        result.data[i * result.isize] = (float) (start + i * step); // PRIM_TYPE // ADD_CAST
    358                }
    359                return result;
    360        }
    361
    362        /**
    363         * @param shape
    364         * @return a dataset filled with ones
    365         */
    366        static CompoundFloatDataset ones(final int itemSize, final int... shape) {
    367                return new CompoundFloatDataset(itemSize, shape).fill(1);
    368        }
    369
    370        /**
    371         * Create a compound dataset using last dimension of given dataset
    372         * @param a
    373         * @param shareData if true, then share data when possible otherwise copy it
    374         * @return compound dataset
    375         */
    376        public static CompoundFloatDataset createCompoundDatasetWithLastDimension(final Dataset a, final boolean shareData) {
    377                if (a.getElementsPerItem() != 1) {
    378                        logger.error("Need a single-element dataset");
    379                        throw new IllegalArgumentException("Need a single-element dataset");
    380                }
    381                if (a.getDType() != Dataset.FLOAT32) { // DATA_TYPE
    382                        logger.error("Dataset type must be float"); // PRIM_TYPE
    383                        throw new IllegalArgumentException("Dataset type must be float"); // PRIM_TYPE
    384                }
    385
    386                final int[] shape = a.getShapeRef();
    387                if (shape == null) {
    388                        return new CompoundFloatDataset(0);
    389                }
    390
    391                final int rank = shape.length - 1;
    392                final int is = rank < 0 ? 1 : shape[rank];
    393
    394                CompoundFloatDataset result = new CompoundFloatDataset(is);
    395
    396                result.shape = rank > 0 ? Arrays.copyOf(shape, rank) : (rank < 0 ? new int[0] : new int[] {1});
    397                result.size = ShapeUtils.calcSize(result.shape);
    398                result.odata = shareData ? a.flatten().getBuffer() : a.clone().getBuffer();
    399                result.setName(a.getName());
    400                result.setData();
    401                return result;
    402        }
    403
    404        @Override
    405        public FloatDataset asNonCompoundDataset(final boolean shareData) { // CLASS_TYPE
    406                FloatDataset result = new FloatDataset(); // CLASS_TYPE
    407                final int is = getElementsPerItem();
    408                final int rank = is == 1 ? shape.length : shape.length + 1;
    409                final int[] nshape = Arrays.copyOf(shape, rank);
    410                if (is != 1)
    411                        nshape[rank-1] = is;
    412
    413                result.shape = nshape;
    414                result.size = ShapeUtils.calcSize(nshape);
    415                result.odata = shareData && isContiguous() ? data : clone().getBuffer();
    416                result.setName(name);
    417                result.setData();
    418                return result;
    419        }
    420
    421        @Override
    422        public CompoundFloatDataset fill(final Object obj) {
    423                setDirty();
    424                float[] vr = DTypeUtils.toFloatArray(obj, isize); // PRIM_TYPE // CLASS_TYPE
    425                IndexIterator iter = getIterator();
    426
    427                while (iter.hasNext()) {
    428                        for (int i = 0; i < isize; i++) {
    429                                data[iter.index + i] = vr[i]; // PRIM_TYPE
    430                        }
    431                }
    432
    433                return this;
    434        }
    435
    436        /**
    437         * This is a typed version of {@link #getBuffer()}
    438         * @return data buffer as linear array
    439         */
    440        public float[] getData() { // PRIM_TYPE
    441                return data;
    442        }
    443
    444        @Override
    445        protected int getBufferLength() {
    446                if (data == null)
    447                        return 0;
    448                return data.length;
    449        }
    450
    451        @Override
    452        public CompoundFloatDataset getView(boolean deepCopyMetadata) {
    453                CompoundFloatDataset view = new CompoundFloatDataset(isize);
    454                copyToView(this, view, true, deepCopyMetadata);
    455                view.setData();
    456                return view;
    457        }
    458
    459        /**
    460         * Get values at absolute index in the internal array. This is an internal method with no checks so can be
    461         * dangerous. Use with care or ideally with an iterator.
    462         *
    463         * @param index
    464         *            absolute index
    465         * @return values
    466         */
    467        public float[] getAbs(final int index) { // PRIM_TYPE
    468                float[] result = new float[isize]; // PRIM_TYPE
    469                for (int i = 0; i < isize; i++) {
    470                        result[i] = data[index + i];
    471                }
    472                return result;
    473        }
    474
    475        /**
    476         * Get values at absolute index in the internal array. This is an internal method with no checks so can be
    477         * dangerous. Use with care or ideally with an iterator.
    478         *
    479         * @param index
    480         *            absolute index
    481         * @param values
    482         */
    483        public void getAbs(final int index, final float[] values) { // PRIM_TYPE
    484                for (int i = 0; i < isize; i++) {
    485                        values[i] = data[index + i];
    486                }
    487        }
    488
    489        @Override
    490        public boolean getElementBooleanAbs(final int index) {
    491                return data[index] != 0;
    492        }
    493
    494        @Override
    495        public double getElementDoubleAbs(final int index) {
    496                return data[index];
    497        }
    498
    499        @Override
    500        public long getElementLongAbs(final int index) {
    501                return DTypeUtils.toLong(data[index]); // OMIT_TOLONG_INT
    502        }
    503
    504        @Override
    505        protected void setItemDirect(final int dindex, final int sindex, final Object src) {
    506                setDirty();
    507                float[] dsrc = (float[]) src; // PRIM_TYPE
    508                for (int i = 0; i < isize; i++) {
    509                        data[dindex + i] = dsrc[sindex + i];
    510                }
    511        }
    512
    513        /**
    514         * Set values at absolute index in the internal array. This is an internal method with no checks so can be
    515         * dangerous. Use with care or ideally with an iterator.
    516         *
    517         * @param index
    518         *            absolute index
    519         * @param val
    520         *            new values
    521         */
    522        public void setAbs(final int index, final float[] val) { // PRIM_TYPE
    523                setDirty();
    524                for (int i = 0; i < isize; i++) {
    525                        data[index + i] = val[i];
    526                }
    527        }
    528
    529        /**
    530         * Set element value at absolute index in the internal array. This is an internal method with no checks so can be
    531         * dangerous. Use with care or ideally with an iterator.
    532         *
    533         * @param index
    534         *            absolute index
    535         * @param val
    536         *            new value
    537         */
    538        public void setAbs(final int index, final float val) { // PRIM_TYPE
    539                setDirty();
    540                data[index] = val;
    541        }
    542
    543        @Override
    544        public Object getObject() {
    545                return getFloatArray(); // PRIM_TYPE
    546        }
    547
    548        @Override
    549        public Object getObject(final int i) {
    550                return getFloatArray(i); // PRIM_TYPE
    551        }
    552
    553        @Override
    554        public Object getObject(final int i, final int j) {
    555                return getFloatArray(i, j); // PRIM_TYPE
    556        }
    557
    558        @Override
    559        public Object getObject(final int... pos) {
    560                return getFloatArray(pos); // PRIM_TYPE
    561        }
    562
    563        @Override
    564        public byte[] getByteArray() {
    565                byte[] result = new byte[isize];
    566                int index = getFirst1DIndex();
    567                for (int k = 0; k < isize; k++) {
    568                        result[k] = (byte) data[index + k]; // OMIT_UPCAST
    569                }
    570                return result;
    571        }
    572
    573        @Override
    574        public byte[] getByteArray(final int i) {
    575                byte[] result = new byte[isize];
    576                int index = get1DIndex(i);
    577                for (int k = 0; k < isize; k++) {
    578                        result[k] = (byte) data[index + k]; // OMIT_UPCAST
    579                }
    580                return result;
    581        }
    582
    583        @Override
    584        public byte[] getByteArray(final int i, final int j) {
    585                byte[] result = new byte[isize];
    586                int index = get1DIndex(i, j);
    587                for (int k = 0; k < isize; k++) {
    588                        result[k] = (byte) data[index + k]; // OMIT_UPCAST
    589                }
    590                return result;
    591        }
    592
    593        @Override
    594        public byte[] getByteArray(final int... pos) {
    595                byte[] result = new byte[isize];
    596                int index = get1DIndex(pos);
    597                for (int k = 0; k < isize; k++) {
    598                        result[k] = (byte) data[index + k]; // OMIT_UPCAST
    599                }
    600                return result;
    601        }
    602
    603        @Override
    604        public short[] getShortArray() {
    605                short[] result = new short[isize];
    606                int index = getFirst1DIndex();
    607                for (int k = 0; k < isize; k++) {
    608                        result[k] = (short) data[index + k]; // OMIT_UPCAST
    609                }
    610                return result;
    611        }
    612
    613        @Override
    614        public short[] getShortArray(final int i) {
    615                short[] result = new short[isize];
    616                int index = get1DIndex(i);
    617                for (int k = 0; k < isize; k++) {
    618                        result[k] = (short) data[index + k]; // OMIT_UPCAST
    619                }
    620                return result;
    621        }
    622
    623        @Override
    624        public short[] getShortArray(final int i, final int j) {
    625                short[] result = new short[isize];
    626                int index = get1DIndex(i, j);
    627                for (int k = 0; k < isize; k++) {
    628                        result[k] = (short) data[index + k]; // OMIT_UPCAST
    629                }
    630                return result;
    631        }
    632
    633        @Override
    634        public short[] getShortArray(final int... pos) {
    635                short[] result = new short[isize];
    636                int index = get1DIndex(pos);
    637                for (int k = 0; k < isize; k++) {
    638                        result[k] = (short) data[index + k]; // OMIT_UPCAST
    639                }
    640                return result;
    641        }
    642
    643        @Override
    644        public int[] getIntArray() {
    645                int[] result = new int[isize];
    646                int index = getFirst1DIndex();
    647                for (int k = 0; k < isize; k++) {
    648                        result[k] = (int) data[index + k]; // OMIT_UPCAST
    649                }
    650                return result;
    651        }
    652
    653        @Override
    654        public int[] getIntArray(final int i) {
    655                int[] result = new int[isize];
    656                int index = get1DIndex(i);
    657                for (int k = 0; k < isize; k++) {
    658                        result[k] = (int) data[index + k]; // OMIT_UPCAST
    659                }
    660                return result;
    661        }
    662
    663        @Override
    664        public int[] getIntArray(final int i, final int j) {
    665                int[] result = new int[isize];
    666                int index = get1DIndex(i, j);
    667                for (int k = 0; k < isize; k++) {
    668                        result[k] = (int) data[index + k]; // OMIT_UPCAST
    669                }
    670                return result;
    671        }
    672
    673        @Override
    674        public int[] getIntArray(final int... pos) {
    675                int[] result = new int[isize];
    676                int index = get1DIndex(pos);
    677                for (int k = 0; k < isize; k++) {
    678                        result[k] = (int) data[index + k]; // OMIT_UPCAST
    679                }
    680                return result;
    681        }
    682
    683        @Override
    684        public long[] getLongArray() {
    685                long[] result = new long[isize];
    686                int index = getFirst1DIndex();
    687                for (int k = 0; k < isize; k++) {
    688                        result[k] = (long) data[index + k]; // OMIT_UPCAST
    689                }
    690                return result;
    691        }
    692
    693        @Override
    694        public long[] getLongArray(final int i) {
    695                long[] result = new long[isize];
    696                int index = get1DIndex(i);
    697                for (int k = 0; k < isize; k++) {
    698                        result[k] = (long) data[index + k]; // OMIT_UPCAST
    699                }
    700                return result;
    701        }
    702
    703        @Override
    704        public long[] getLongArray(final int i, final int j) {
    705                long[] result = new long[isize];
    706                int index = get1DIndex(i, j);
    707                for (int k = 0; k < isize; k++) {
    708                        result[k] = (long) data[index + k]; // OMIT_UPCAST
    709                }
    710                return result;
    711        }
    712
    713        @Override
    714        public long[] getLongArray(final int... pos) {
    715                long[] result = new long[isize];
    716                int index = get1DIndex(pos);
    717                for (int k = 0; k < isize; k++) {
    718                        result[k] = (long) data[index + k]; // OMIT_UPCAST
    719                }
    720                return result;
    721        }
    722
    723        @Override
    724        public float[] getFloatArray() {
    725                float[] result = new float[isize];
    726                int index = getFirst1DIndex();
    727                for (int k = 0; k < isize; k++) {
    728                        result[k] = data[index + k]; // OMIT_REAL_CAST
    729                }
    730                return result;
    731        }
    732
    733        @Override
    734        public float[] getFloatArray(final int i) {
    735                float[] result = new float[isize];
    736                int index = get1DIndex(i);
    737                for (int k = 0; k < isize; k++) {
    738                        result[k] = data[index + k]; // OMIT_REAL_CAST
    739                }
    740                return result;
    741        }
    742
    743        @Override
    744        public float[] getFloatArray(final int i, final int j) {
    745                float[] result = new float[isize];
    746                int index = get1DIndex(i, j);
    747                for (int k = 0; k < isize; k++) {
    748                        result[k] = data[index + k]; // OMIT_REAL_CAST
    749                }
    750                return result;
    751        }
    752
    753        @Override
    754        public float[] getFloatArray(final int... pos) {
    755                float[] result = new float[isize];
    756                int index = get1DIndex(pos);
    757                for (int k = 0; k < isize; k++) {
    758                        result[k] = data[index + k]; // OMIT_REAL_CAST
    759                }
    760                return result;
    761        }
    762
    763        @Override
    764        public double[] getDoubleArray() {
    765                double[] result = new double[isize];
    766                int index = getFirst1DIndex();
    767                for (int k = 0; k < isize; k++) {
    768                        result[k] = data[index + k]; // OMIT_REAL_CAST
    769                }
    770                return result;
    771        }
    772
    773        @Override
    774        public double[] getDoubleArray(final int i) {
    775                double[] result = new double[isize];
    776                int index = get1DIndex(i);
    777                for (int k = 0; k < isize; k++) {
    778                        result[k] = data[index + k]; // OMIT_REAL_CAST
    779                }
    780                return result;
    781        }
    782
    783        @Override
    784        public double[] getDoubleArray(final int i, final int j) {
    785                double[] result = new double[isize];
    786                int index = get1DIndex(i, j);
    787                for (int k = 0; k < isize; k++) {
    788                        result[k] = data[index + k]; // OMIT_REAL_CAST
    789                }
    790                return result;
    791        }
    792
    793        @Override
    794        public double[] getDoubleArray(final int... pos) {
    795                double[] result = new double[isize];
    796                int index = get1DIndex(pos);
    797                for (int k = 0; k < isize; k++) {
    798                        result[k] = data[index + k]; // OMIT_REAL_CAST
    799                }
    800                return result;
    801        }
    802
    803        @Override
    804        public void getDoubleArrayAbs(final int index, final double[] darray) {
    805                for (int i = 0; i < isize; i++) {
    806                        darray[i] = data[index + i];
    807                }
    808        }
    809
    810        @Override
    811        public String getString() {
    812                return getStringAbs(getFirst1DIndex());
    813        }
    814
    815        @Override
    816        public String getString(final int i) {
    817                return getStringAbs(get1DIndex(i));
    818        }
    819
    820        @Override
    821        public String getString(final int i, final int j) {
    822                return getStringAbs(get1DIndex(i, j));
    823        }
    824
    825        @Override
    826        public String getString(final int... pos) {
    827                return getStringAbs(get1DIndex(pos));
    828        }
    829
    830        @Override
    831        protected double getFirstValue() {
    832                return data[getFirst1DIndex()];
    833        }
    834
    835        @Override
    836        protected double getFirstValue(int i) {
    837                return data[get1DIndex(i)];
    838        }
    839
    840        @Override
    841        protected double getFirstValue(int i, int j) {
    842                return data[get1DIndex(i, j)];
    843        }
    844
    845        @Override
    846        protected double getFirstValue(final int... pos) {
    847                return data[get1DIndex(pos)];
    848        }
    849
    850        @Override
    851        public Object getObjectAbs(final int index) {
    852                float[] result = new float[isize]; // PRIM_TYPE
    853                for (int i = 0; i < isize; i++) {
    854                        result[i] = data[index + i];
    855                }
    856                return result;
    857        }
    858
    859        @Override
    860        public String getStringAbs(final int index) {
    861                StringBuilder s = new StringBuilder();
    862                s.append('(');
    863                s.append(stringFormat == null ? String.format("%.8g", data[index]) : // FORMAT_STRING
    864                        stringFormat.format(data[index]));
    865                for (int i = 1; i < isize; i++) {
    866                        s.append(' ');
    867                        s.append(stringFormat == null ? String.format("%.8g", data[index + i]) : // FORMAT_STRING
    868                                stringFormat.format(data[index + i]));
    869                }
    870                s.append(')');
    871                return s.toString();
    872        }
    873
    874        @Override
    875        public void setObjectAbs(final int index, final Object obj) {
    876                float[] oa = DTypeUtils.toFloatArray(obj, isize); // PRIM_TYPE // CLASS_TYPE
    877                setAbs(index, oa);
    878        }
    879
    880        @Override
    881        public void set(final Object obj) {
    882                setItem(DTypeUtils.toFloatArray(obj, isize)); // CLASS_TYPE
    883        }
    884
    885        @Override
    886        public void set(final Object obj, final int i) {
    887                setItem(DTypeUtils.toFloatArray(obj, isize), i); // CLASS_TYPE
    888        }
    889
    890        @Override
    891        public void set(final Object obj, final int i, final int j) {
    892                setItem(DTypeUtils.toFloatArray(obj, isize), i, j); // CLASS_TYPE
    893        }
    894
    895        @Override
    896        public void set(final Object obj, int... pos) {
    897                if (pos == null || (pos.length == 0 && shape.length > 0)) {
    898                        pos = new int[shape.length];
    899                }
    900
    901                setItem(DTypeUtils.toFloatArray(obj, isize), pos); // CLASS_TYPE
    902        }
    903
    904        /**
    905         * Set values at first position. The dataset must not be null
    906         *
    907         * @param d
    908         * @since 2.0
    909         */
    910        public void setItem(final float[] d) { // PRIM_TYPE
    911                if (d.length > isize) {
    912                        throw new IllegalArgumentException("Array is larger than number of elements in an item");
    913                }
    914                setAbs(getFirst1DIndex(), d);
    915        }
    916
    917        /**
    918         * Set values at given position. The dataset must be 1D
    919         *
    920         * @param d
    921         * @param i
    922         */
    923        public void setItem(final float[] d, final int i) { // PRIM_TYPE
    924                if (d.length > isize) {
    925                        throw new IllegalArgumentException("Array is larger than number of elements in an item");
    926                }
    927                setAbs(get1DIndex(i), d);
    928        }
    929
    930        /**
    931         * Set values at given position. The dataset must be 1D
    932         *
    933         * @param d
    934         * @param i
    935         * @param j
    936         */
    937        public void setItem(final float[] d, final int i, final int j) { // PRIM_TYPE
    938                if (d.length > isize) {
    939                        throw new IllegalArgumentException("Array is larger than number of elements in an item");
    940                }
    941                setAbs(get1DIndex(i, j), d);
    942        }
    943
    944        /**
    945         * Set values at given position
    946         *
    947         * @param d
    948         * @param pos
    949         */
    950        public void setItem(final float[] d, final int... pos) { // PRIM_TYPE
    951                if (d.length > isize) {
    952                        throw new IllegalArgumentException("Array is larger than number of elements in an item");
    953                }
    954                setAbs(get1DIndex(pos), d);
    955        }
    956
    957        private void setDoubleArrayAbs(final int index, final double[] d) {
    958                for (int i = 0; i < isize; i++)
    959                        data[index + i] = (float) d[i]; // ADD_CAST
    960        }
    961
    962        @Override
    963        public void resize(int... newShape) {
    964                setDirty();
    965                IndexIterator iter = getIterator();
    966                int nsize = ShapeUtils.calcSize(newShape);
    967                float[] ndata; // PRIM_TYPE
    968                try {
    969                        ndata = createArray(nsize);
    970                } catch (Throwable t) {
    971                        logger.error("Could not create a dataset of shape {}", Arrays.toString(shape), t);
    972                        throw new IllegalArgumentException(t);
    973                }
    974
    975                int i = 0;
    976                while (iter.hasNext() && i < nsize) {
    977                        for (int j = 0; j < isize; j++) {
    978                                ndata[i++] = data[iter.index + j];
    979                        }
    980                }
    981
    982                odata = data = ndata;
    983                size = nsize;
    984                shape = newShape;
    985                stride = null;
    986                offset = 0;
    987                base = null;
    988        }
    989
    990        @Override
    991        public CompoundFloatDataset getSlice(final SliceIterator siter) {
    992                CompoundFloatDataset result = new CompoundFloatDataset(isize, siter.getShape());
    993                float[] rdata = result.data; // PRIM_TYPE
    994                IndexIterator riter = result.getIterator();
    995
    996                while (siter.hasNext() && riter.hasNext()) {
    997                        for (int i = 0; i < isize; i++)
    998                                rdata[riter.index + i] = data[siter.index + i];
    999                }
    1000
    1001                result.setName(name + BLOCK_OPEN + Slice.createString(siter.shape, siter.start, siter.stop, siter.step) + BLOCK_CLOSE);
    1002                return result;
    1003        }
    1004
    1005        @Override
    1006        public FloatDataset getElementsView(int element) { // CLASS_TYPE
    1007                if (element < 0)
    1008                        element += isize;
    1009                if (element < 0 || element > isize) {
    1010                        throw new IllegalArgumentException(String.format("Invalid choice of element: %d/%d", element, isize));
    1011                }
    1012
    1013                FloatDataset view = new FloatDataset(shape); // CLASS_TYPE
    1014
    1015                copyToView(this, view, true, true);
    1016                view.setData();
    1017                if (view.stride == null) {
    1018                        int[] offset = new int[1];
    1019                        view.stride = createStrides(this, offset);
    1020                        view.offset = offset[0] + element;
    1021                        view.base = base == null ? this : base;
    1022                } else {
    1023                        view.offset += element;
    1024                }
    1025
    1026                return view;
    1027        }
    1028
    1029        @Override
    1030        public FloatDataset getElements(int element) { // CLASS_TYPE
    1031                final FloatDataset elements = new FloatDataset(shape); // CLASS_TYPE
    1032
    1033                copyElements(elements, element);
    1034                return elements;
    1035        }
    1036
    1037        @Override
    1038        public void copyElements(Dataset destination, int element) {
    1039                if (element < 0)
    1040                        element += isize;
    1041                if (element < 0 || element > isize) {
    1042                        throw new IllegalArgumentException(String.format("Invalid choice of element: %d/%d", element, isize));
    1043                }
    1044                if (getElementClass() != destination.getElementClass()) {
    1045                        throw new IllegalArgumentException("Element class of destination does not match this dataset");
    1046                }
    1047
    1048                final IndexIterator it = getIterator(element);
    1049                final float[] elements = ((FloatDataset) destination).data; // CLASS_TYPE // PRIM_TYPE
    1050                destination.setDirty();
    1051
    1052                int n = 0;
    1053                while (it.hasNext()) {
    1054                        elements[n] = data[it.index];
    1055                        n++;
    1056                }
    1057        }
    1058
    1059        @Override
    1060        public void setElements(Dataset source, int element) {
    1061                setDirty();
    1062                if (element < 0)
    1063                        element += isize;
    1064                if (element < 0 || element > isize) {
    1065                        throw new IllegalArgumentException(String.format("Invalid choice of element: %d/%d", element, isize));
    1066                }
    1067                if (getElementClass() != source.getElementClass()) {
    1068                        throw new IllegalArgumentException("Element class of destination does not match this dataset");
    1069                }
    1070
    1071                final IndexIterator it = getIterator(element);
    1072                final float[] elements = ((FloatDataset) source).data; // CLASS_TYPE // PRIM_TYPE
    1073
    1074                int n = 0;
    1075                while (it.hasNext()) {
    1076                        data[it.index] = elements[n];
    1077                        n++;
    1078                }
    1079        }
    1080
    1081        @Override
    1082        public void fillDataset(Dataset result, IndexIterator iter) {
    1083                IndexIterator riter = result.getIterator();
    1084                result.setDirty();
    1085
    1086                float[] rdata = ((CompoundFloatDataset) result).data; // PRIM_TYPE
    1087
    1088                while (riter.hasNext() && iter.hasNext()) {
    1089                        for (int i = 0; i < isize; i++) {
    1090                                rdata[riter.index + i] = data[iter.index + i];
    1091                        }
    1092                }
    1093        }
    1094
    1095        @Override
    1096        public CompoundFloatDataset setByBoolean(final Object o, Dataset selection) {
    1097                setDirty();
    1098                if (o instanceof Dataset) {
    1099                        Dataset ds = (Dataset) o;
    1100                        final int length = ((Number) selection.sum()).intValue();
    1101                        if (length != ds.getSize()) {
    1102                                throw new IllegalArgumentException(
    1103                                                "Number of true items in selection does not match number of items in dataset");
    1104                        }
    1105
    1106                        IndexIterator iter = ds.getIterator();
    1107                        BooleanIterator biter = getBooleanIterator(selection);
    1108
    1109                        if (ds instanceof AbstractCompoundDataset) {
    1110                                if (isize != ds.getElementsPerItem()) {
    1111                                        throw new IllegalArgumentException("Input dataset is not compatible with slice");
    1112                                }
    1113
    1114                                while (biter.hasNext() && iter.hasNext()) {
    1115                                        for (int i = 0; i < isize; i++) {
    1116                                                data[biter.index + i] = (float) ds.getElementDoubleAbs(iter.index + i); // GET_ELEMENT_WITH_CAST
    1117                                        }
    1118                                }
    1119                        } else {
    1120                                while (biter.hasNext() && iter.hasNext()) {
    1121                                        data[biter.index] = (float) ds.getElementDoubleAbs(iter.index); // GET_ELEMENT_WITH_CAST
    1122                                        for (int i = 1; i < isize; i++) {
    1123                                                data[biter.index + i] = 0;
    1124                                        }
    1125                                }
    1126                        }
    1127                } else {
    1128                        try {
    1129                                final float[] vr = DTypeUtils.toFloatArray(o, isize); // PRIM_TYPE // CLASS_TYPE
    1130
    1131                                final BooleanIterator biter = getBooleanIterator(selection);
    1132
    1133                                while (biter.hasNext()) {
    1134                                        for (int i = 0; i < isize; i++) {
    1135                                                data[biter.index + i] = vr[i];
    1136                                        }
    1137                                }
    1138                        } catch (IllegalArgumentException e) {
    1139                                throw new IllegalArgumentException("Object for setting is not a dataset or number");
    1140                        }
    1141                }
    1142                return this;
    1143        }
    1144
    1145        @Override
    1146        public CompoundFloatDataset setBy1DIndex(final Object o, Dataset index) {
    1147                setDirty();
    1148                if (o instanceof Dataset) {
    1149                        Dataset ds = (Dataset) o;
    1150                        if (index.getSize() != ds.getSize()) {
    1151                                throw new IllegalArgumentException(
    1152                                                "Number of items in selection does not match number of items in dataset");
    1153                        }
    1154
    1155                        IndexIterator oiter = ds.getIterator();
    1156                        final IntegerIterator iter = new IntegerIterator(index, size, isize);
    1157
    1158                        if (ds instanceof AbstractCompoundDataset) {
    1159                                if (isize != ds.getElementsPerItem()) {
    1160                                        throw new IllegalArgumentException("Input dataset is not compatible with slice");
    1161                                }
    1162
    1163                                double[] temp = new double[isize];
    1164                                while (iter.hasNext() && oiter.hasNext()) {
    1165                                        ((AbstractCompoundDataset) ds).getDoubleArrayAbs(oiter.index, temp);
    1166                                        setDoubleArrayAbs(iter.index, temp);
    1167                                }
    1168                                while (iter.hasNext() && oiter.hasNext()) {
    1169                                        for (int i = 0; i < isize; i++) {
    1170                                                data[iter.index + i] = (float) ds.getElementDoubleAbs(oiter.index + i); // GET_ELEMENT_WITH_CAST
    1171                                        }
    1172                                }
    1173                        } else {
    1174                                while (iter.hasNext() && oiter.hasNext()) {
    1175                                        data[iter.index] = (float) ds.getElementDoubleAbs(oiter.index); // GET_ELEMENT_WITH_CAST
    1176                                        for (int i = 1; i < isize; i++) {
    1177                                                data[iter.index + i] = 0;
    1178                                        }
    1179                                }
    1180                        }
    1181                } else {
    1182                        try {
    1183                                final float[] vr = DTypeUtils.toFloatArray(o, isize); // PRIM_TYPE // CLASS_TYPE
    1184
    1185                                final IntegerIterator iter = new IntegerIterator(index, size, isize);
    1186
    1187                                while (iter.hasNext()) {
    1188                                        setAbs(iter.index, vr);
    1189                                }
    1190                        } catch (IllegalArgumentException e) {
    1191                                throw new IllegalArgumentException("Object for setting is not a dataset or number");
    1192                        }
    1193                }
    1194                return this;
    1195        }
    1196
    1197        @Override
    1198        public CompoundFloatDataset setByIndexes(final Object o, final Object... indexes) {
    1199                setDirty();
    1200                final IntegersIterator iter = new IntegersIterator(shape, indexes);
    1201                final int[] pos = iter.getPos();
    1202
    1203                if (o instanceof Dataset) {
    1204                        Dataset ds = (Dataset) o;
    1205                        if (ShapeUtils.calcSize(iter.getShape()) != ds.getSize()) {
    1206                                throw new IllegalArgumentException(
    1207                                                "Number of items in selection does not match number of items in dataset");
    1208                        }
    1209
    1210                        IndexIterator oiter = ds.getIterator();
    1211
    1212                        if (ds instanceof AbstractCompoundDataset) {
    1213                                if (isize != ds.getElementsPerItem()) {
    1214                                        throw new IllegalArgumentException("Input dataset is not compatible with slice");
    1215                                }
    1216
    1217                                double[] temp = new double[isize];
    1218                                while (iter.hasNext() && oiter.hasNext()) {
    1219                                        ((AbstractCompoundDataset) ds).getDoubleArray(temp, pos);
    1220                                        setDoubleArrayAbs(get1DIndex(pos), temp);
    1221                                }
    1222                        } else {
    1223                                while (iter.hasNext() && oiter.hasNext()) {
    1224                                        int n = get1DIndex(pos);
    1225                                        data[n] = (float) ds.getElementDoubleAbs(oiter.index); // GET_ELEMENT_WITH_CAST
    1226                                        for (int i = 1; i < isize; i++) {
    1227                                                data[n + i] = 0;
    1228                                        }
    1229                                }
    1230                        }
    1231                } else {
    1232                        try {
    1233                                final float[] vr = DTypeUtils.toFloatArray(o, isize); // PRIM_TYPE // CLASS_TYPE
    1234
    1235                                while (iter.hasNext()) {
    1236                                        setAbs(get1DIndex(pos), vr);
    1237                                }
    1238                        } catch (IllegalArgumentException e) {
    1239                                throw new IllegalArgumentException("Object for setting is not a dataset or number");
    1240                        }
    1241                }
    1242                return this;
    1243        }
    1244
    1245        @Override
    1246        CompoundFloatDataset setSlicedView(Dataset view, Dataset d) {
    1247                setDirty();
    1248                final BroadcastSelfIterator it = BroadcastSelfIterator.createIterator(view, d);
    1249
    1250                final int is = view.getElementsPerItem();
    1251
    1252                if (is > 1) {
    1253                        if (d.getElementsPerItem() == 1) {
    1254                                while (it.hasNext()) {
    1255                                        final float bv = (float) it.bDouble; // PRIM_TYPE // BCAST_WITH_CAST d.getElementDoubleAbs(it.bIndex);
    1256                                        data[it.aIndex] = bv;
    1257                                        for (int j = 1; j < is; j++) {
    1258                                                data[it.aIndex + j] = bv;
    1259                                        }
    1260                                }
    1261                        } else {
    1262                                while (it.hasNext()) {
    1263                                        data[it.aIndex] = (float) it.bDouble; // BCAST_WITH_CAST d.getElementDoubleAbs(it.bIndex);
    1264                                        for (int j = 1; j < is; j++) {
    1265                                                data[it.aIndex + j] = (float) d.getElementDoubleAbs(it.bIndex + j); // GET_ELEMENT_WITH_CAST
    1266                                        }
    1267                                }
    1268                        }
    1269                } else {
    1270                        while (it.hasNext()) {
    1271                                data[it.aIndex] = (float) it.bDouble; // BCAST_WITH_CAST d.getElementDoubleAbs(it.bIndex);
    1272                        }
    1273                }
    1274                return this;
    1275        }
    1276
    1277        @Override
    1278        public CompoundFloatDataset setSlice(final Object o, final IndexIterator siter) {
    1279                setDirty();
    1280                if (o instanceof IDataset) {
    1281                        final IDataset ds = (IDataset) o;
    1282                        final int[] oshape = ds.getShape();
    1283
    1284                        if (!ShapeUtils.areShapesCompatible(siter.getShape(), oshape)) {
    1285                                throw new IllegalArgumentException(String.format(
    1286                                                "Input dataset is not compatible with slice: %s cf %s", Arrays.toString(oshape),
    1287                                                Arrays.toString(siter.getShape())));
    1288                        }
    1289
    1290                        if (ds instanceof Dataset) {
    1291                                final Dataset ads = (Dataset) ds;
    1292                                IndexIterator oiter = ads.getIterator();
    1293
    1294                                if (ds instanceof AbstractCompoundDataset) {
    1295                                        if (isize != ads.getElementsPerItem()) {
    1296                                                throw new IllegalArgumentException("Input dataset is not compatible with slice");
    1297                                        }
    1298
    1299                                        while (siter.hasNext() && oiter.hasNext()) {
    1300                                                for (int i = 0; i < isize; i++) {
    1301                                                        data[siter.index + i] = (float) ads.getElementDoubleAbs(oiter.index + i); // GET_ELEMENT_WITH_CAST
    1302                                                }
    1303                                        }
    1304                                } else {
    1305                                        while (siter.hasNext() && oiter.hasNext()) {
    1306                                                data[siter.index] = (float) ads.getElementDoubleAbs(oiter.index); // GET_ELEMENT_WITH_CAST
    1307                                                for (int i = 1; i < isize; i++) {
    1308                                                        data[siter.index + i] = 0;
    1309                                                }
    1310                                        }
    1311                                }
    1312                        } else {
    1313                                final IndexIterator oiter = new PositionIterator(oshape);
    1314                                final int[] pos = oiter.getPos();
    1315
    1316                                if (ds.getElementsPerItem() == 1) {
    1317                                        while (siter.hasNext() && oiter.hasNext()) {
    1318                                                data[siter.index] = ds.getFloat(pos); // PRIM_TYPE
    1319                                                for (int i = 1; i < isize; i++) {
    1320                                                        data[siter.index + i] = 0;
    1321                                                }
    1322                                        }
    1323                                } else {
    1324                                        while (siter.hasNext() && oiter.hasNext()) {
    1325                                                final float[] val = DTypeUtils.toFloatArray(ds.getObject(pos), isize); // PRIM_TYPE // CLASS_TYPE
    1326                                                for (int i = 0; i < isize; i++) {
    1327                                                        data[siter.index + i] = val[i];
    1328                                                }
    1329                                        }
    1330                                }
    1331                        }
    1332                } else {
    1333                        try {
    1334                                final float[] vr = DTypeUtils.toFloatArray(o, isize); // PRIM_TYPE // CLASS_TYPE
    1335
    1336                                while (siter.hasNext()) {
    1337                                        for (int i = 0; i < isize; i++) {
    1338                                                data[siter.index + i] = vr[i];
    1339                                        }
    1340                                }
    1341                        } catch (IllegalArgumentException e) {
    1342                                throw new IllegalArgumentException("Object for setting slice is not a dataset or number");
    1343                        }
    1344                }
    1345                return this;
    1346        }
    1347
    1348        @Override
    1349        public void copyItemsFromAxes(final int[] pos, final boolean[] axes, final Dataset dest) {
    1350                float[] ddata = (float[]) dest.getBuffer(); // PRIM_TYPE
    1351
    1352                if (dest.getElementsPerItem() != isize) {
    1353                        throw new IllegalArgumentException(String.format(
    1354                                        "Destination dataset is incompatible as it has %d elements per item not %d",
    1355                                        dest.getElementsPerItem(), isize));
    1356                }
    1357
    1358                SliceIterator siter = getSliceIteratorFromAxes(pos, axes);
    1359                int[] sshape = ShapeUtils.squeezeShape(siter.getShape(), false);
    1360
    1361                IndexIterator diter = dest.getSliceIterator(null, sshape, null);
    1362
    1363                if (ddata.length < ShapeUtils.calcSize(sshape)) {
    1364                        throw new IllegalArgumentException("destination array is not large enough");
    1365                }
    1366
    1367                dest.setDirty();
    1368                while (siter.hasNext() && diter.hasNext()) {
    1369                        for (int i = 0; i < isize; i++) {
    1370                                ddata[diter.index + i] = data[siter.index + i];
    1371                        }
    1372                }
    1373        }
    1374
    1375        @Override
    1376        public void setItemsOnAxes(final int[] pos, final boolean[] axes, final Object src) {
    1377                setDirty();
    1378                float[] sdata = (float[]) src; // PRIM_TYPE
    1379
    1380                SliceIterator siter = getSliceIteratorFromAxes(pos, axes);
    1381
    1382                if (sdata.length < ShapeUtils.calcSize(siter.getShape())) {
    1383                        throw new IllegalArgumentException("source array is not large enough");
    1384                }
    1385
    1386                for (int i = 0; siter.hasNext(); i++) {
    1387                        for (int j = 0; j < isize; j++) {
    1388                                data[siter.index + j] = sdata[isize * i + j];
    1389                        }
    1390                }
    1391        }
    1392
    1393        @Override
    1394        public boolean containsNans() {
    1395                final IndexIterator iter = getIterator(); // REAL_ONLY
    1396                while (iter.hasNext()) { // REAL_ONLY
    1397                        for (int i = 0; i < isize; i++) { // REAL_ONLY
    1398                                if (Float.isNaN(data[iter.index + i])) // CLASS_TYPE // REAL_ONLY
    1399                                        return true; // REAL_ONLY
    1400                        } // REAL_ONLY
    1401                } // REAL_ONLY
    1402                return false;
    1403        }
    1404
    1405        @Override
    1406        public boolean containsInfs() {
    1407                final IndexIterator iter = getIterator(); // REAL_ONLY
    1408                while (iter.hasNext()) { // REAL_ONLY
    1409                        for (int i = 0; i < isize; i++) { // REAL_ONLY
    1410                                if (Float.isInfinite(data[iter.index + i])) // CLASS_TYPE // REAL_ONLY
    1411                                        return true; // REAL_ONLY
    1412                        } // REAL_ONLY
    1413                } // REAL_ONLY
    1414                return false;
    1415        }
    1416
    1417        @Override
    1418        public boolean containsInvalidNumbers() {
    1419                IndexIterator iter = getIterator(); // REAL_ONLY
    1420                while (iter.hasNext()) { // REAL_ONLY
    1421                        for (int i = 0; i < isize; i++) { // REAL_ONLY
    1422                                float x = data[iter.index + i]; // PRIM_TYPE // REAL_ONLY
    1423                                if (Float.isNaN(x) || Float.isInfinite(x)) // CLASS_TYPE // REAL_ONLY
    1424                                        return true; // REAL_ONLY
    1425                        } // REAL_ONLY
    1426                } // REAL_ONLY
    1427                return false;
    1428        }
    1429
    1430        @Override
    1431        public CompoundFloatDataset iadd(final Object b) {
    1432                setDirty();
    1433                Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    1434                boolean useLong = bds.getElementClass().equals(Long.class);
    1435                int is = bds.getElementsPerItem();
    1436                if (bds.getSize() == 1) {
    1437                        final IndexIterator it = getIterator();
    1438                        final int bOffset = bds.getOffset();
    1439                        if (is == 1) {
    1440                                if (useLong) {
    1441                                        final long lb = bds.getElementLongAbs(bOffset);
    1442                                        while (it.hasNext()) {
    1443                                                for (int i = 0; i < isize; i++) {
    1444                                                        data[it.index + i] += lb;
    1445                                                }
    1446                                        }
    1447                                } else {
    1448                                        final double db = bds.getElementDoubleAbs(bOffset);
    1449                                        while (it.hasNext()) {
    1450                                                for (int i = 0; i < isize; i++) {
    1451                                                        data[it.index + i] += db;
    1452                                                }
    1453                                        }
    1454                                }
    1455                        } else if (is == isize) {
    1456                                if (useLong) {
    1457                                        while (it.hasNext()) {
    1458                                                for (int i = 0; i < isize; i++) {
    1459                                                        data[it.index + i] += bds.getElementLongAbs(i);
    1460                                                }
    1461                                        }
    1462                                } else {
    1463                                        while (it.hasNext()) {
    1464                                                for (int i = 0; i < isize; i++) {
    1465                                                        data[it.index + i] += bds.getElementDoubleAbs(i);
    1466                                                }
    1467                                        }
    1468                                }
    1469                        } else {
    1470                                throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1471                        }
    1472                } else {
    1473                        final BroadcastSelfIterator it = BroadcastSelfIterator.createIterator(this, bds);
    1474                        it.setOutputDouble(!useLong);
    1475                        if (is == 1) {
    1476                                if (useLong) {
    1477                                        while (it.hasNext()) {
    1478                                                final long lb = it.bLong;
    1479                                                data[it.aIndex] += lb;
    1480                                                for (int i = 1; i < isize; i++) {
    1481                                                        data[it.aIndex + i] += lb;
    1482                                                }
    1483                                        }
    1484                                } else {
    1485                                        while (it.hasNext()) {
    1486                                                final double db = it.bDouble;
    1487                                                data[it.aIndex] += db;
    1488                                                for (int i = 1; i < isize; i++) {
    1489                                                        data[it.aIndex + i] += db;
    1490                                                }
    1491                                        }
    1492                                }
    1493                        } else if (is == isize) {
    1494                                if (useLong) {
    1495                                        while (it.hasNext()) {
    1496                                                data[it.aIndex] += it.bLong;
    1497                                                for (int i = 1; i < isize; i++) {
    1498                                                        data[it.aIndex + i] += bds.getElementLongAbs(it.bIndex + i);
    1499                                                }
    1500                                        }
    1501                                } else {
    1502                                        while (it.hasNext()) {
    1503                                                data[it.aIndex] += it.bDouble;
    1504                                                for (int i = 1; i < isize; i++) {
    1505                                                        data[it.aIndex + i] += bds.getElementDoubleAbs(it.bIndex + i);
    1506                                                }
    1507                                        }
    1508                                }
    1509                        } else {
    1510                                throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1511                        }
    1512                }
    1513                return this;
    1514        }
    1515
    1516        @Override
    1517        public CompoundFloatDataset isubtract(final Object b) {
    1518                setDirty();
    1519                Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    1520                boolean useLong = bds.getElementClass().equals(Long.class);
    1521                int is = bds.getElementsPerItem();
    1522                if (bds.getSize() == 1) {
    1523                        final IndexIterator it = getIterator();
    1524                        final int bOffset = bds.getOffset();
    1525                        if (is == 1) {
    1526                                if (useLong) {
    1527                                        final long lb = bds.getElementLongAbs(bOffset);
    1528                                        while (it.hasNext()) {
    1529                                                for (int i = 0; i < isize; i++) {
    1530                                                        data[it.index + i] -= lb;
    1531                                                }
    1532                                        }
    1533                                } else {
    1534                                        final double db = bds.getElementDoubleAbs(bOffset);
    1535                                        while (it.hasNext()) {
    1536                                                for (int i = 0; i < isize; i++) {
    1537                                                        data[it.index + i] -= db;
    1538                                                }
    1539                                        }
    1540                                }
    1541                        } else if (is == isize) {
    1542                                if (useLong) {
    1543                                        while (it.hasNext()) {
    1544                                                for (int i = 0; i < isize; i++) {
    1545                                                        data[it.index + i] -= bds.getElementLongAbs(i);
    1546                                                }
    1547                                        }
    1548                                } else {
    1549                                        while (it.hasNext()) {
    1550                                                for (int i = 0; i < isize; i++) {
    1551                                                        data[it.index + i] -= bds.getElementDoubleAbs(i);
    1552                                                }
    1553                                        }
    1554                                }
    1555                        } else {
    1556                                throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1557                        }
    1558                } else {
    1559                        final BroadcastSelfIterator it = BroadcastSelfIterator.createIterator(this, bds);
    1560                        it.setOutputDouble(!useLong);
    1561                        if (is == 1) {
    1562                                if (useLong) {
    1563                                        while (it.hasNext()) {
    1564                                                final long lb = it.bLong;
    1565                                                data[it.aIndex] += lb;
    1566                                                for (int i = 1; i < isize; i++) {
    1567                                                        data[it.aIndex + i] -= lb;
    1568                                                }
    1569                                        }
    1570                                } else {
    1571                                        while (it.hasNext()) {
    1572                                                final double db = it.bDouble;
    1573                                                data[it.aIndex] += db;
    1574                                                for (int i = 1; i < isize; i++) {
    1575                                                        data[it.aIndex + i] -= db;
    1576                                                }
    1577                                        }
    1578                                }
    1579                        } else if (is == isize) {
    1580                                if (useLong) {
    1581                                        while (it.hasNext()) {
    1582                                                data[it.aIndex] += it.bLong;
    1583                                                for (int i = 1; i < isize; i++) {
    1584                                                        data[it.aIndex + i] -= bds.getElementLongAbs(it.bIndex + i);
    1585                                                }
    1586                                        }
    1587                                } else {
    1588                                        while (it.hasNext()) {
    1589                                                data[it.aIndex] += it.bDouble;
    1590                                                for (int i = 1; i < isize; i++) {
    1591                                                        data[it.aIndex + i] -= bds.getElementDoubleAbs(it.bIndex + i);
    1592                                                }
    1593                                        }
    1594                                }
    1595                        } else {
    1596                                throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1597                        }
    1598                }
    1599                return this;
    1600        }
    1601
    1602        @Override
    1603        public CompoundFloatDataset imultiply(final Object b) {
    1604                setDirty();
    1605                Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    1606                boolean useLong = bds.getElementClass().equals(Long.class);
    1607                int is = bds.getElementsPerItem();
    1608                if (bds.getSize() == 1) {
    1609                        final IndexIterator it = getIterator();
    1610                        final int bOffset = bds.getOffset();
    1611                        if (useLong) {
    1612                                if (is == 1) {
    1613                                        final long lb = bds.getElementLongAbs(bOffset);
    1614                                        while (it.hasNext()) {
    1615                                                for (int i = 0; i < isize; i++) {
    1616                                                        data[it.index + i] *= lb;
    1617                                                }
    1618                                        }
    1619                                } else if (is == isize) {
    1620                                        while (it.hasNext()) {
    1621                                                for (int i = 0; i < isize; i++) {
    1622                                                        data[it.index + i] *= bds.getElementLongAbs(i);
    1623                                                }
    1624                                        }
    1625                                } else {
    1626                                        throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1627                                }
    1628                        } else {
    1629                                if (is == 1) {
    1630                                        final double db = bds.getElementDoubleAbs(bOffset);
    1631                                        while (it.hasNext()) {
    1632                                                for (int i = 0; i < isize; i++) {
    1633                                                        data[it.index + i] *= db;
    1634                                                }
    1635                                        }
    1636                                } else if (is == isize) {
    1637                                        while (it.hasNext()) {
    1638                                                for (int i = 0; i < isize; i++) {
    1639                                                        data[it.index + i] *= bds.getElementDoubleAbs(i);
    1640                                                }
    1641                                        }
    1642                                } else {
    1643                                        throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1644                                }
    1645                        }
    1646                } else {
    1647                        final BroadcastSelfIterator it = BroadcastSelfIterator.createIterator(this, bds);
    1648                        it.setOutputDouble(!useLong);
    1649                        if (useLong) {
    1650                                if (is == 1) {
    1651                                        while (it.hasNext()) {
    1652                                                final double lb = it.bLong;
    1653                                                for (int i = 0; i < isize; i++) {
    1654                                                        data[it.aIndex + i] *= lb;
    1655                                                }
    1656                                        }
    1657                                } else if (is == isize) {
    1658                                        while (it.hasNext()) {
    1659                                                data[it.aIndex] *= it.bLong;
    1660                                                for (int i = 1; i < isize; i++) {
    1661                                                        data[it.aIndex + i] *= bds.getElementLongAbs(it.bIndex + i);
    1662                                                }
    1663                                        }
    1664                                } else {
    1665                                        throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1666                                }
    1667                        } else {
    1668                                if (is == 1) {
    1669                                        while (it.hasNext()) {
    1670                                                final double db = it.bDouble;
    1671                                                for (int i = 0; i < isize; i++) {
    1672                                                        data[it.aIndex + i] *= db;
    1673                                                }
    1674                                        }
    1675                                } else if (is == isize) {
    1676                                        while (it.hasNext()) {
    1677                                                data[it.aIndex] *= it.bDouble;
    1678                                                for (int i = 1; i < isize; i++) {
    1679                                                        data[it.aIndex + i] *= bds.getElementDoubleAbs(it.bIndex + i);
    1680                                                }
    1681                                        }
    1682                                } else {
    1683                                        throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1684                                }
    1685                        }
    1686                }
    1687                return this;
    1688        }
    1689
    1690        @Override
    1691        public CompoundFloatDataset idivide(final Object b) {
    1692                setDirty();
    1693                Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    1694                boolean useLong = bds.getElementClass().equals(Long.class);
    1695                int is = bds.getElementsPerItem();
    1696                if (bds.getSize() == 1) {
    1697                        final IndexIterator it = getIterator();
    1698                        final int bOffset = bds.getOffset();
    1699                        if (useLong) {
    1700                                if (is == 1) {
    1701                                        final long lb = bds.getElementLongAbs(bOffset);
    1702                                        // if (lb == 0) { // INT_USE
    1703                                        //      fill(0); // INT_USE
    1704                                        // } else { // INT_USE
    1705                                        while (it.hasNext()) {
    1706                                                for (int i = 0; i < isize; i++) {
    1707                                                        data[it.index + i] /= lb;
    1708                                                }
    1709                                        }
    1710                                        // } // INT_USE
    1711                                } else if (is == isize) {
    1712                                        while (it.hasNext()) {
    1713                                                for (int i = 0; i < isize; i++) {
    1714                                                        final long lb = bds.getElementLongAbs(i);
    1715                                                        data[it.index + i] /= lb; // INT_EXCEPTION
    1716                                                }
    1717                                        }
    1718                                } else {
    1719                                        throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1720                                }
    1721                        } else {
    1722                                if (is == 1) {
    1723                                        final double db = bds.getElementDoubleAbs(bOffset);
    1724                                        // if (db == 0) { // INT_USE
    1725                                        //      fill(0); // INT_USE
    1726                                        // } else { // INT_USE
    1727                                        while (it.hasNext()) {
    1728                                                for (int i = 0; i < isize; i++) {
    1729                                                        data[it.index + i] /= db;
    1730                                                }
    1731                                        }
    1732                                        // } // INT_USE
    1733                                } else if (is == isize) {
    1734                                        while (it.hasNext()) {
    1735                                                for (int i = 0; i < isize; i++) {
    1736                                                        final double db = bds.getElementDoubleAbs(i);
    1737                                                        data[it.index + i] /= db; // INT_EXCEPTION
    1738                                                }
    1739                                        }
    1740                                } else {
    1741                                        throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1742                                }
    1743                        }
    1744                } else {
    1745                        final BroadcastSelfIterator it = BroadcastSelfIterator.createIterator(this, bds);
    1746                        it.setOutputDouble(!useLong);
    1747                        if (useLong) {
    1748                                if (is == 1) {
    1749                                        while (it.hasNext()) {
    1750                                                final long lb = it.bLong;
    1751                                                // if (lb == 0) { // INT_USE
    1752                                                //      for (int i = 0; i < isize; i++) { // INT_USE
    1753                                                //              data[it.aIndex + i] = 0; // INT_USE
    1754                                                //      }// INT_USE
    1755                                                // } else { // INT_USE
    1756                                                for (int i = 0; i < isize; i++) {
    1757                                                        data[it.aIndex + i] /= lb;
    1758                                                }
    1759                                                // } // INT_USE
    1760                                        }
    1761                                } else if (is == isize) {
    1762                                        while (it.hasNext()) {
    1763                                                for (int i = 0; i < isize; i++) {
    1764                                                        final long lb = bds.getElementLongAbs(it.bIndex + i);
    1765                                                        data[it.aIndex + i] /= lb; // INT_EXCEPTION
    1766                                                }
    1767                                        }
    1768                                } else {
    1769                                        throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1770                                }
    1771                        } else {
    1772                                if (is == 1) {
    1773                                        while (it.hasNext()) {
    1774                                                final double db = it.bDouble;
    1775                                                // if (db == 0) { // INT_USE
    1776                                                //      for (int i = 0; i < isize; i++) { // INT_USE
    1777                                                //              data[it.aIndex + i] = 0; // INT_USE
    1778                                                //      }// INT_USE
    1779                                                // } else { // INT_USE
    1780                                                for (int i = 0; i < isize; i++) {
    1781                                                        data[it.aIndex + i] /= db;
    1782                                                }
    1783                                                // } // INT_USE
    1784                                        }
    1785                                } else if (is == isize) {
    1786                                        while (it.hasNext()) {
    1787                                                for (int i = 0; i < isize; i++) {
    1788                                                        final double db = bds.getElementDoubleAbs(it.bIndex + i);
    1789                                                        data[it.aIndex + i] /= db; // INT_EXCEPTION
    1790                                                }
    1791                                        }
    1792                                } else {
    1793                                        throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1794                                }
    1795                        }
    1796                }
    1797                return this;
    1798        }
    1799
    1800        @Override
    1801        public CompoundFloatDataset ifloor() {
    1802                setDirty(); // REAL_ONLY
    1803                final IndexIterator it = getIterator(); // REAL_ONLY
    1804                while (it.hasNext()) { // REAL_ONLY
    1805                        for (int i = 0; i < isize; i++) { // REAL_ONLY
    1806                                data[it.index + i] = (float) Math.floor(data[it.index] + i); // REAL_ONLY // ADD_CAST
    1807                        } // REAL_ONLY
    1808                } // REAL_ONLY
    1809                return this;
    1810        }
    1811
    1812        @Override
    1813        public CompoundFloatDataset iremainder(final Object b) {
    1814                setDirty();
    1815                Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    1816                boolean useLong = bds.getElementClass().equals(Long.class);
    1817                int is = bds.getElementsPerItem();
    1818                if (bds.getSize() == 1) {
    1819                        final IndexIterator it = getIterator();
    1820                        final int bOffset = bds.getOffset();
    1821                        if (useLong) {
    1822                                if (is == 1) {
    1823                                        final long lb = bds.getElementLongAbs(bOffset);
    1824                                        // if (lb == 0) { // INT_USE
    1825                                        //      fill(0); // INT_USE
    1826                                        // } else { // INT_USE
    1827                                        while (it.hasNext()) {
    1828                                                for (int i = 0; i < isize; i++) {
    1829                                                        data[it.index + i] %= lb;
    1830                                                }
    1831                                        }
    1832                                        // } // INT_USE
    1833                                } else if (is == isize) {
    1834                                        while (it.hasNext()) {
    1835                                                for (int i = 0; i < isize; i++) {
    1836                                                        data[it.index + i] %= bds.getElementLongAbs(i); // INT_EXCEPTION
    1837                                                }
    1838                                        }
    1839                                } else {
    1840                                        throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1841                                }
    1842                        } else {
    1843                                if (is == 1) {
    1844                                        final double db = bds.getElementDoubleAbs(bOffset);
    1845                                        // if (db == 0) { // INT_USE
    1846                                        //      fill(0); // INT_USE
    1847                                        // } else { // INT_USE
    1848                                        while (it.hasNext()) {
    1849                                                for (int i = 0; i < isize; i++) {
    1850                                                        data[it.index + i] %= db;
    1851                                                }
    1852                                        }
    1853                                        // } // INT_USE
    1854                                } else if (is == isize) {
    1855                                        while (it.hasNext()) {
    1856                                                for (int i = 0; i < isize; i++) {
    1857                                                        data[it.index + i] %= bds.getElementDoubleAbs(i); // INT_EXCEPTION
    1858                                                }
    1859                                        }
    1860                                } else {
    1861                                        throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1862                                }
    1863                        }
    1864                } else {
    1865                        final BroadcastSelfIterator it = BroadcastSelfIterator.createIterator(this, bds);
    1866                        it.setOutputDouble(!useLong);
    1867                        if (useLong) {
    1868                                if (is == 1) {
    1869                                        while (it.hasNext()) {
    1870                                                final long lb = it.bLong;
    1871                                                // if (lb == 0) { // INT_USE
    1872                                                //      for (int i = 0; i < isize; i++) // INT_USE
    1873                                                //              data[it.aIndex + i] = 0; // INT_USE
    1874                                                // } else { // INT_USE
    1875                                                for (int i = 0; i < isize; i++)
    1876                                                        data[it.aIndex + i] %= lb;
    1877                                                // } // INT_USE
    1878                                        }
    1879                                } else if (is == isize) {
    1880                                        while (it.hasNext()) {
    1881                                                for (int i = 0; i < isize; i++) {
    1882                                                        final long lb = bds.getElementLongAbs(it.bIndex + i);
    1883                                                        data[it.aIndex + i] %= lb; // INT_EXCEPTION
    1884                                                }
    1885                                        }
    1886                                } else {
    1887                                        throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1888                                }
    1889                        } else {
    1890                                if (is == 1) {
    1891                                        while (it.hasNext()) {
    1892                                                final double db = it.bDouble;
    1893                                                // if (db == 0) { // INT_USE
    1894                                                //      for (int i = 0; i < isize; i++) // INT_USE
    1895                                                //              data[it.aIndex + i] = 0; // INT_USE
    1896                                                // } else { // INT_USE
    1897                                                for (int i = 0; i < isize; i++) {
    1898                                                        data[it.aIndex + i] %= db;
    1899                                                }
    1900                                                // } // INT_USE
    1901                                        }
    1902                                } else if (is == isize) {
    1903                                        while (it.hasNext()) {
    1904                                                for (int i = 0; i < isize; i++) {
    1905                                                        final double db = bds.getElementDoubleAbs(it.bIndex + i);
    1906                                                        data[it.aIndex + i] %= db; // INT_EXCEPTION
    1907                                                }
    1908                                        }
    1909                                } else {
    1910                                        throw new IllegalArgumentException("Argument does not have same number of elements per item or is not a non-compound dataset");
    1911                                }
    1912                        }
    1913                }
    1914                return this;
    1915        }
    1916
    1917        @Override
    1918        public CompoundFloatDataset ipower(final Object b) {
    1919                setDirty();
    1920                Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    1921                final int is = bds.getElementsPerItem();
    1922                if (bds.getSize() == 1) {
    1923                        final int bOffset = bds.getOffset();
    1924                        final double vr = bds.getElementDoubleAbs(bOffset);
    1925                        final IndexIterator it = getIterator();
    1926                        if (bds.isComplex()) {
    1927                                final double vi = bds.getElementDoubleAbs(bOffset + 1);
    1928                                if (vi == 0) {
    1929                                        while (it.hasNext()) {
    1930                                                for (int i = 0; i < isize; i++) {
    1931                                                        final double v = Math.pow(data[it.index + i], vr);
    1932                                                        // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
    1933                                                        //      data[it.index + i] = 0; // INT_USE
    1934                                                        // } else { // INT_USE
    1935                                                        data[it.index + i] = (float) v; // PRIM_TYPE_LONG // ADD_CAST
    1936                                                        // } // INT_USE
    1937                                                }
    1938                                        }
    1939                                } else {
    1940                                        final Complex zv = new Complex(vr, vi);
    1941                                        while (it.hasNext()) {
    1942                                                for (int i = 0; i < isize; i++) {
    1943                                                        Complex zd = new Complex(data[it.index + i], 0);
    1944                                                        final double v = zd.pow(zv).getReal();
    1945                                                        // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
    1946                                                        //      data[it.index + i] = 0; // INT_USE
    1947                                                        // } else { // INT_USE
    1948                                                        data[it.index + i] = (float) v; // PRIM_TYPE_LONG // ADD_CAST
    1949                                                        // } // INT_USE
    1950                                                }
    1951                                        }
    1952                                }
    1953                        } else if (is == 1) {
    1954                                while (it.hasNext()) {
    1955                                        for (int i = 0; i < isize; i++) {
    1956                                                final double v = Math.pow(data[it.index + i], vr);
    1957                                                // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
    1958                                                //      data[it.index + i] = 0; // INT_USE
    1959                                                // } else { // INT_USE
    1960                                                data[it.index + i] = (float) v; // PRIM_TYPE_LONG // ADD_CAST
    1961                                                // } // INT_USE
    1962                                        }
    1963                                }
    1964                        } else if (is == isize) {
    1965                                while (it.hasNext()) {
    1966                                        for (int i = 0; i < isize; i++) {
    1967                                                final double v = Math.pow(data[it.index + i], bds.getElementDoubleAbs(i));
    1968                                                // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
    1969                                                //      data[it.index + i] = 0; // INT_USE
    1970                                                // } else { // INT_USE
    1971                                                data[it.index + i] = (float) v; // PRIM_TYPE_LONG // ADD_CAST
    1972                                                // } // INT_USE
    1973                                        }
    1974                                }
    1975                        }
    1976                } else {
    1977                        final BroadcastIterator it = BroadcastIterator.createIterator(this, bds);
    1978                        it.setOutputDouble(true);
    1979                        if (bds.isComplex()) {
    1980                                while (it.hasNext()) {
    1981                                        final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1));
    1982                                        double v = new Complex(it.aDouble, 0).pow(zv).getReal();
    1983                                        // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
    1984                                        //      data[it.aIndex] = 0; // INT_USE
    1985                                        // } else { // INT_USE
    1986                                        data[it.aIndex] = (float) v; // PRIM_TYPE_LONG // ADD_CAST
    1987                                        // } // INT_USE
    1988                                        for (int i = 1; i < isize; i++) {
    1989                                                v = new Complex(data[it.aIndex + i], 0).pow(zv).getReal();
    1990                                                // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
    1991                                                //      data[it.aIndex + i] = 0; // INT_USE
    1992                                                // } else { // INT_USE
    1993                                                data[it.aIndex + i] = (float) v; // PRIM_TYPE_LONG // ADD_CAST
    1994                                                // } // INT_USE
    1995                                        }
    1996                                }
    1997                        } else {
    1998                                while (it.hasNext()) {
    1999                                        double v = Math.pow(it.aDouble, it.bDouble);
    2000                                        // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
    2001                                        //      data[it.aIndex] = 0; // INT_USE
    2002                                        // } else { // INT_USE
    2003                                        data[it.aIndex] = (float) v; // PRIM_TYPE_LONG // ADD_CAST
    2004                                        // } // INT_USE
    2005                                        for (int i = 1; i < isize; i++) {
    2006                                                v = Math.pow(data[it.aIndex + i], bds.getElementDoubleAbs(it.bIndex + i));
    2007                                                // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
    2008                                                //      data[it.aIndex + i] = 0; // INT_USE
    2009                                                // } else { // INT_USE
    2010                                                data[it.aIndex + i] = (float) v; // PRIM_TYPE_LONG // ADD_CAST
    2011                                                // } // INT_USE
    2012                                        }
    2013                                }
    2014                        }
    2015                }
    2016                return this;
    2017        }
    2018
    2019        @Override
    2020        public double residual(final Object b, final Dataset w, boolean ignoreNaNs) {
    2021                Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    2022                final BroadcastIterator it = BroadcastIterator.createIterator(this, bds);
    2023                it.setOutputDouble(true);
    2024                double sum = 0;
    2025                double comp = 0;
    2026                final int bis = bds.getElementsPerItem();
    2027
    2028                if (bis == 1) {
    2029                        if (w == null) {
    2030                                while (it.hasNext()) {
    2031                                        final double db = it.bDouble;
    2032                                        double diff = it.aDouble - db;
    2033                                        if (ignoreNaNs) { // REAL_ONLY
    2034                                                if (Double.isNaN(diff)) // REAL_ONLY
    2035                                                        continue; // REAL_ONLY
    2036                                                boolean skip = false; // REAL_ONLY
    2037                                                for (int i = 1; i < isize; i++) { // REAL_ONLY
    2038                                                        if (Double.isNaN(data[it.aIndex + i])) { // REAL_ONLY
    2039                                                                skip = true; // REAL_ONLY
    2040                                                                break; // REAL_ONLY
    2041                                                        } // REAL_ONLY
    2042                                                } // REAL_ONLY
    2043                                                if (skip) { // REAL_ONLY
    2044                                                        continue; // REAL_ONLY
    2045                                                } // REAL_ONLY
    2046                                        } // REAL_ONLY
    2047                                        double err = diff * diff - comp;
    2048                                        double temp = sum + err;
    2049                                        comp = (temp - sum) - err;
    2050                                        sum = temp;
    2051                                        for (int i = 1; i < isize; i++) {
    2052                                                diff = data[it.aIndex + i] - db;
    2053                                                err = diff * diff - comp;
    2054                                                temp = sum + err;
    2055                                                comp = (temp - sum) - err;
    2056                                                sum = temp;
    2057                                        }
    2058                                }
    2059                        } else {
    2060                                IndexIterator itw = w.getIterator();
    2061                                while (it.hasNext() && itw.hasNext()) {
    2062                                        final double db = it.bDouble;
    2063                                        double diff = it.aDouble - db;
    2064                                        if (ignoreNaNs) { // REAL_ONLY
    2065                                                if (Double.isNaN(diff)) // REAL_ONLY
    2066                                                        continue; // REAL_ONLY
    2067                                                boolean skip = false; // REAL_ONLY
    2068                                                for (int i = 1; i < isize; i++) { // REAL_ONLY
    2069                                                        if (Double.isNaN(data[it.aIndex + i])) { // REAL_ONLY
    2070                                                                skip = true; // REAL_ONLY
    2071                                                                break; // REAL_ONLY
    2072                                                        } // REAL_ONLY
    2073                                                } // REAL_ONLY
    2074                                                if (skip) { // REAL_ONLY
    2075                                                        continue; // REAL_ONLY
    2076                                                } // REAL_ONLY
    2077                                        } // REAL_ONLY
    2078                                        final double dw = w.getElementDoubleAbs(itw.index);
    2079                                        double err = diff * diff * dw - comp;
    2080                                        double temp = sum + err;
    2081                                        comp = (temp - sum) - err;
    2082                                        sum = temp;
    2083                                        for (int i = 1; i < isize; i++) {
    2084                                                diff = data[it.aIndex + i] - db;
    2085                                                err = diff * diff * dw - comp;
    2086                                                temp = sum + err;
    2087                                                comp = (temp - sum) - err;
    2088                                                sum = temp;
    2089                                        }
    2090                                }
    2091                        }
    2092                } else {
    2093                        if (w == null) {
    2094                                while (it.hasNext()) {
    2095                                        double diff = it.aDouble - it.bDouble;
    2096                                        if (ignoreNaNs) { // REAL_ONLY
    2097                                                if (Double.isNaN(diff)) // REAL_ONLY
    2098                                                        continue; // REAL_ONLY
    2099                                                boolean skip = false; // REAL_ONLY
    2100                                                for (int i = 1; i < isize; i++) { // REAL_ONLY
    2101                                                        if (Double.isNaN(data[it.aIndex + i]) || Double.isNaN(bds.getElementDoubleAbs(it.bIndex + i))) { // REAL_ONLY
    2102                                                                skip = true; // REAL_ONLY
    2103                                                                break; // REAL_ONLY
    2104                                                        } // REAL_ONLY
    2105                                                } // REAL_ONLY
    2106                                                if (skip) { // REAL_ONLY
    2107                                                        continue; // REAL_ONLY
    2108                                                } // REAL_ONLY
    2109                                        } // REAL_ONLY
    2110                                        double err = diff * diff - comp;
    2111                                        double temp = sum + err;
    2112                                        comp = (temp - sum) - err;
    2113                                        sum = temp;
    2114                                        for (int i = 1; i < isize; i++) {
    2115                                                diff = data[it.aIndex + i] - bds.getElementDoubleAbs(it.bIndex + i);
    2116                                                err = diff * diff - comp;
    2117                                                temp = sum + err;
    2118                                                comp = (temp - sum) - err;
    2119                                                sum = temp;
    2120                                        }
    2121                                }
    2122                        } else {
    2123                                IndexIterator itw = w.getIterator();
    2124                                while (it.hasNext() && itw.hasNext()) {
    2125                                        double diff = it.aDouble - it.bDouble;
    2126                                        if (ignoreNaNs) { // REAL_ONLY
    2127                                                if (Double.isNaN(diff)) // REAL_ONLY
    2128                                                        continue; // REAL_ONLY
    2129                                                boolean skip = false; // REAL_ONLY
    2130                                                for (int i = 1; i < isize; i++) { // REAL_ONLY
    2131                                                        if (Double.isNaN(data[it.aIndex + i]) || Double.isNaN(bds.getElementDoubleAbs(it.bIndex + i))) { // REAL_ONLY
    2132                                                                skip = true; // REAL_ONLY
    2133                                                                break; // REAL_ONLY
    2134                                                        } // REAL_ONLY
    2135                                                } // REAL_ONLY
    2136                                                if (skip) { // REAL_ONLY
    2137                                                        continue; // REAL_ONLY
    2138                                                } // REAL_ONLY
    2139                                        } // REAL_ONLY
    2140                                        final double dw = w.getElementDoubleAbs(itw.index);
    2141                                        double err = diff * diff * dw - comp;
    2142                                        double temp = sum + err;
    2143                                        comp = (temp - sum) - err;
    2144                                        sum = temp;
    2145                                        for (int i = 1; i < isize; i++) {
    2146                                                diff = data[it.aIndex + i] - bds.getElementDoubleAbs(it.bIndex + i);
    2147                                                err = diff * diff * dw - comp;
    2148                                                temp = sum + err;
    2149                                                comp = (temp - sum) - err;
    2150                                                sum = temp;
    2151                                        }
    2152                                }
    2153                        }
    2154                }
    2155                return sum;
    2156        }
    2157}