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