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