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