    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 DoubleDataset.java by fromdouble.py
    014
    015package org.eclipse.january.dataset;
    016
    017import java.util.ArrayList;
    018import java.util.Arrays;
    019import java.util.List;
    020import java.util.Set;
    021import java.util.TreeSet;
    022
    023import org.eclipse.january.metadata.StatisticsMetadata;
    024
    025
    026/**
    027 * Extend dataset for boolean values // PRIM_TYPE
    028 */
    029public class BooleanDatasetBase extends AbstractDataset {
    030        // pin UID to base class
    031        private static final long serialVersionUID = Dataset.serialVersionUID;
    032
    033        protected boolean[] data; // subclass alias // PRIM_TYPE
    034
    035        @Override
    036        protected void setData() {
    037                data = (boolean[]) odata; // PRIM_TYPE
    038        }
    039
    040        protected static boolean[] createArray(final int size) { // PRIM_TYPE
    041                boolean[] array = null; // PRIM_TYPE
    042
    043                try {
    044                        array = new boolean[size]; // PRIM_TYPE
    045                } catch (OutOfMemoryError e) {
    046                        logger.error("The size of the dataset ({}) that is being created is too large "
    047                                        + "and there is not enough memory to hold it.", size);
    048                        throw new OutOfMemoryError("The dimensions given are too large, and there is "
    049                                        + "not enough memory available in the Java Virtual Machine");
    050                }
    051                return array;
    052        }
    053
    054        @Override
    055        public int getDType() {
    056                return BOOL; // DATA_TYPE
    057        }
    058
    059        /**
    060         * Create a null dataset
    061         */
    062        BooleanDatasetBase() {
    063        }
    064
    065        /**
    066         * Create a zero-filled dataset of given shape
    067         * @param shape
    068         */
    069        BooleanDatasetBase(final int... shape) {
    070                if (shape != null) {
    071                        size = ShapeUtils.calcSize(shape);
    072                        this.shape = shape.clone();
    073
    074                        try {
    075                                odata = data = createArray(size);
    076                        } catch (Throwable t) {
    077                                logger.error("Could not create a dataset of shape {}", Arrays.toString(shape), t);
    078                                throw new IllegalArgumentException(t);
    079                        }
    080                }
    081        }
    082
    083        /**
    084         * Create a dataset using given data
    085         * @param data
    086         * @param shape
    087         *            (can be null to create 1D dataset)
    088         */
    089        BooleanDatasetBase(final boolean[] data, int... shape) { // PRIM_TYPE
    090                if (data == null) {
    091                        throw new IllegalArgumentException("Data must not be null");
    092                }
    093                if (shape == null || shape.length == 0) {
    094                        shape = new int[] { data.length };
    095                }
    096                size = ShapeUtils.calcSize(shape);
    097                if (size != data.length) {
    098                        throw new IllegalArgumentException(String.format("Shape %s is not compatible with size of data array, %d",
    099                                        Arrays.toString(shape), data.length));
    100                }
    101                this.shape = size == 0 ? null : shape.clone();
    102
    103                odata = this.data = data;
    104        }
    105
    106        /**
    107         * Copy a dataset
    108         * @param dataset
    109         */
    110        BooleanDatasetBase(final BooleanDatasetBase dataset) {
    111                copyToView(dataset, this, true, true);
    112
    113                try {
    114                        if (dataset.stride == null) {
    115                                odata = data = dataset.data.clone();
    116                        } else {
    117                                offset = 0;
    118                                stride = null;
    119                                base = null;
    120                                odata = data = createArray(size);
    121
    122                                IndexIterator iter = dataset.getIterator();
    123                                for (int i = 0; iter.hasNext(); i++) {
    124                                        data[i] = dataset.data[iter.index];
    125                                }
    126                        }
    127                } catch (Throwable t) {
    128                        logger.error("Could not create a dataset of shape {}", Arrays.toString(shape), t);
    129                        throw new IllegalArgumentException(t);
    130                }
    131        }
    132
    133        /**
    134         * Copy and cast a dataset to this class type
    135         * @param dataset
    136         */
    137        BooleanDatasetBase(final Dataset dataset) {
    138                copyToView(dataset, this, true, false);
    139                offset = 0;
    140                stride = null;
    141                base = null;
    142                try {
    143                        odata = data = createArray(size);
    144                } catch (Throwable t) {
    145                        logger.error("Could not create a dataset of shape {}", Arrays.toString(shape), t);
    146                        throw new IllegalArgumentException(t);
    147                }
    148                IndexIterator iter = dataset.getIterator();
    149                for (int i = 0; iter.hasNext(); i++) {
    150                        data[i] = dataset.getElementBooleanAbs(iter.index); // GET_ELEMENT_WITH_CAST
    151                }
    152        }
    153
    154        @Override
    155        public boolean equals(Object obj) {
    156                if (!super.equals(obj)) {
    157                        return false;
    158                }
    159
    160                if (getRank() == 0 && !getClass().equals(obj.getClass())) // already true for zero-rank dataset
    161                        return true;
    162
    163                BooleanDatasetBase other = (BooleanDatasetBase) obj;
    164//              if (size == 1) // for zero-rank datasets
    165//                      return getAbs(offset) == other.getAbs(other.offset);
    166
    167                IndexIterator iter = getIterator();
    168                IndexIterator oiter = other.getIterator();
    169                while (iter.hasNext() && oiter.hasNext()) {
    170                        if (data[iter.index] != other.data[oiter.index]) // OBJECT_UNEQUAL
    171                                return false;
    172                }
    173                return true;
    174        }
    175
    176        @Override
    177        public int hashCode() {
    178                return super.hashCode();
    179        }
    180
    181        @Override
    182        public BooleanDatasetBase clone() {
    183                return new BooleanDatasetBase(this);
    184        }
    185
    186        /**
    187         * Create a dataset from an object which could be a Java list, array (of arrays...) or Number. Ragged
    188         * sequences or arrays are padded with zeros.
    189         *
    190         * @param obj
    191         * @return dataset with contents given by input
    192         */
    193        static BooleanDatasetBase createFromObject(final Object obj) {
    194                BooleanDatasetBase result = new BooleanDatasetBase();
    195
    196                if (obj != null) {
    197                        result.shape = ShapeUtils.getShapeFromObject(obj);
    198                        result.size = ShapeUtils.calcSize(result.shape);
    199
    200                        try {
    201                                result.odata = result.data = createArray(result.size);
    202                        } catch (Throwable t) {
    203                                logger.error("Could not create a dataset of shape {}", Arrays.toString(result.shape), t);
    204                                throw new IllegalArgumentException(t);
    205                        }
    206
    207                        int[] pos = new int[result.shape.length];
    208                        result.fillData(obj, 0, pos);
    209                }
    210
    211                return result;
    212        }
    213
    214        /**
    215         * @param shape
    216         * @return a dataset filled with ones
    217         */
    218        static BooleanDatasetBase ones(final int... shape) {
    219                return new BooleanDatasetBase(shape).fill(1);
    220        }
    221
    222        @Override
    223        public BooleanDatasetBase fill(final Object obj) {
    224                setDirty();
    225                boolean dv = DTypeUtils.toBoolean(obj); // PRIM_TYPE // FROM_OBJECT
    226                IndexIterator iter = getIterator();
    227                while (iter.hasNext()) {
    228                        data[iter.index] = dv;
    229                }
    230
    231                return this;
    232        }
    233
    234        /**
    235         * This is a typed version of {@link #getBuffer()}
    236         * @return data buffer as linear array
    237         */
    238        public boolean[] getData() { // PRIM_TYPE
    239                return data;
    240        }
    241
    242        @Override
    243        protected int getBufferLength() {
    244                if (data == null)
    245                        return 0;
    246                return data.length;
    247        }
    248
    249        @Override
    250        public BooleanDatasetBase getView(boolean deepCopyMetadata) {
    251                BooleanDatasetBase view = new BooleanDatasetBase();
    252                copyToView(this, view, true, deepCopyMetadata);
    253                view.setData();
    254                return view;
    255        }
    256
    257        /**
    258         * Get a value from an absolute index of the internal array. This is an internal method with no checks so can be
    259         * dangerous. Use with care or ideally with an iterator.
    260         *
    261         * @param index
    262         *            absolute index
    263         * @return value
    264         */
    265        public boolean getAbs(final int index) { // PRIM_TYPE
    266                return data[index];
    267        }
    268
    269        @Override
    270        public boolean getElementBooleanAbs(final int index) {
    271                return false;
    272        }
    273
    274        @Override
    275        public double getElementDoubleAbs(final int index) {
    276                return 0;
    277        }
    278
    279        @Override
    280        public long getElementLongAbs(final int index) {
    281                return 0;
    282        }
    283
    284        @Override
    285        public Object getObjectAbs(final int index) {
    286                return data[index];
    287        }
    288
    289        @Override
    290        public String getStringAbs(final int index) {
    291                return stringFormat == null ? String.format("%b", data[index]) : // FORMAT_STRING
    292                        stringFormat.format(data[index]);
    293        }
    294
    295        /**
    296         * Set a value at absolute index in the internal array. This is an internal method with no checks so can be
    297         * dangerous. Use with care or ideally with an iterator.
    298         *
    299         * @param index
    300         *            absolute index
    301         * @param val
    302         *            new value
    303         */
    304        public void setAbs(final int index, final boolean val) { // PRIM_TYPE
    305                setDirty();
    306                data[index] = val;
    307        }
    308
    309        @Override
    310        protected void setItemDirect(final int dindex, final int sindex, final Object src) {
    311                setDirty();
    312                boolean[] dsrc = (boolean[]) src; // PRIM_TYPE
    313                data[dindex] = dsrc[sindex];
    314        }
    315
    316        @Override
    317        public void setObjectAbs(final int index, final Object obj) {
    318                if (index < 0 || index > data.length) {
    319                        throw new IndexOutOfBoundsException("Index given is outside dataset");
    320                }
    321
    322                setAbs(index, DTypeUtils.toBoolean(obj)); // FROM_OBJECT
    323        }
    324
    325        /**
    326         * @return item in first position
    327         * @since 2.0
    328         */
    329        public boolean get() { // PRIM_TYPE
    330                return data[getFirst1DIndex()];
    331        }
    332
    333        /**
    334         * @param i
    335         * @return item in given position
    336         */
    337        public boolean get(final int i) { // PRIM_TYPE
    338                return data[get1DIndex(i)];
    339        }
    340
    341        /**
    342         * @param i
    343         * @param j
    344         * @return item in given position
    345         */
    346        public boolean get(final int i, final int j) { // PRIM_TYPE
    347                return data[get1DIndex(i, j)];
    348        }
    349
    350        /**
    351         * @param pos
    352         * @return item in given position
    353         */
    354        public boolean get(final int... pos) { // PRIM_TYPE
    355                return data[get1DIndex(pos)];
    356        }
    357
    358        @Override
    359        public Object getObject() {
    360                return Boolean.valueOf(get()); // CLASS_TYPE
    361        }
    362
    363        @Override
    364        public Object getObject(final int i) {
    365                return Boolean.valueOf(get(i)); // CLASS_TYPE
    366        }
    367
    368        @Override
    369        public Object getObject(final int i, final int j) {
    370                return Boolean.valueOf(get(i, j)); // CLASS_TYPE
    371        }
    372
    373        @Override
    374        public Object getObject(final int... pos) {
    375                return Boolean.valueOf(get(pos)); // CLASS_TYPE
    376        }
    377
    378        @Override
    379        public String getString() {
    380                return getStringAbs(getFirst1DIndex());
    381        }
    382
    383        @Override
    384        public String getString(final int i) {
    385                return getStringAbs(get1DIndex(i));
    386        }
    387
    388        @Override
    389        public String getString(final int i, final int j) {
    390                return getStringAbs(get1DIndex(i, j));
    391        }
    392
    393        @Override
    394        public String getString(final int... pos) {
    395                return getStringAbs(get1DIndex(pos));
    396        }
    397
    398        @Override
    399        public double getDouble() {
    400                return 0;
    401        }
    402
    403        @Override
    404        public double getDouble(final int i) {
    405                return 0;
    406        }
    407
    408        @Override
    409        public double getDouble(final int i, final int j) {
    410                return 0;
    411        }
    412
    413        @Override
    414        public double getDouble(final int... pos) {
    415                return 0;
    416        }
    417
    418        @Override
    419        public float getFloat() {
    420                return 0;
    421        }
    422
    423        @Override
    424        public float getFloat(final int i) {
    425                return 0;
    426        }
    427
    428        @Override
    429        public float getFloat(final int i, final int j) {
    430                return 0;
    431        }
    432
    433        @Override
    434        public float getFloat(final int... pos) {
    435                return 0;
    436        }
    437
    438        @Override
    439        public long getLong() {
    440                return 0;
    441        }
    442
    443        @Override
    444        public long getLong(final int i) {
    445                return 0;
    446        }
    447
    448        @Override
    449        public long getLong(final int i, final int j) {
    450                return 0;
    451        }
    452
    453        @Override
    454        public long getLong(final int... pos) {
    455                return 0;
    456        }
    457
    458        @Override
    459        public int getInt() {
    460                return 0;
    461        }
    462
    463        @Override
    464        public int getInt(final int i) {
    465                return 0;
    466        }
    467
    468        @Override
    469        public int getInt(final int i, final int j) {
    470                return 0;
    471        }
    472
    473        @Override
    474        public int getInt(final int... pos) {
    475                return 0;
    476        }
    477
    478        @Override
    479        public short getShort() {
    480                return 0;
    481        }
    482
    483        @Override
    484        public short getShort(final int i) {
    485                return 0;
    486        }
    487
    488        @Override
    489        public short getShort(final int i, final int j) {
    490                return 0;
    491        }
    492
    493        @Override
    494        public short getShort(final int... pos) {
    495                return 0;
    496        }
    497
    498        @Override
    499        public byte getByte() {
    500                return 0;
    501        }
    502
    503        @Override
    504        public byte getByte(final int i) {
    505                return 0;
    506        }
    507
    508        @Override
    509        public byte getByte(final int i, final int j) {
    510                return 0;
    511        }
    512
    513        @Override
    514        public byte getByte(final int... pos) {
    515                return 0;
    516        }
    517
    518        @Override
    519        public boolean getBoolean() {
    520                return false;
    521        }
    522
    523        @Override
    524        public boolean getBoolean(final int i) {
    525                return false;
    526        }
    527
    528        @Override
    529        public boolean getBoolean(final int i, final int j) {
    530                return false;
    531        }
    532
    533        @Override
    534        public boolean getBoolean(final int... pos) {
    535                return false;
    536        }
    537
    538        /**
    539         * Sets the value at first point to the passed value. The dataset must not be null
    540         *
    541         * @param value
    542         * @since 2.0
    543         */
    544        public void setItem(final boolean value) { // PRIM_TYPE
    545                setAbs(getFirst1DIndex(), value);
    546        }
    547
    548        /**
    549         * Sets the value at a particular point to the passed value. The dataset must be 1D
    550         *
    551         * @param value
    552         * @param i
    553         */
    554        public void setItem(final boolean value, final int i) { // PRIM_TYPE
    555                setAbs(get1DIndex(i), value);
    556        }
    557
    558        /**
    559         * Sets the value at a particular point to the passed value. The dataset must be 2D
    560         *
    561         * @param value
    562         * @param i
    563         * @param j
    564         */
    565        public void setItem(final boolean value, final int i, final int j) { // PRIM_TYPE
    566                setAbs(get1DIndex(i, j), value);
    567        }
    568
    569        /**
    570         * Sets the value at a particular point to the passed value
    571         *
    572         * @param value
    573         * @param pos
    574         */
    575        public void setItem(final boolean value, final int... pos) { // PRIM_TYPE
    576                setAbs(get1DIndex(pos), value);
    577        }
    578
    579        @Override
    580        public void set(final Object obj) {
    581                setItem(DTypeUtils.toBoolean(obj)); // FROM_OBJECT
    582        }
    583
    584        @Override
    585        public void set(final Object obj, final int i) {
    586                setItem(DTypeUtils.toBoolean(obj), i); // FROM_OBJECT
    587        }
    588
    589        @Override
    590        public void set(final Object obj, final int i, final int j) {
    591                setItem(DTypeUtils.toBoolean(obj), i, j); // FROM_OBJECT
    592        }
    593
    594        @Override
    595        public void set(final Object obj, int... pos) {
    596                if (pos == null || (pos.length == 0 && shape.length > 0)) {
    597                        pos = new int[shape.length];
    598                }
    599
    600                setItem(DTypeUtils.toBoolean(obj), pos); // FROM_OBJECT
    601        }
    602
    603
    604        @Override
    605        public void resize(int... newShape) {
    606                setDirty();
    607                final IndexIterator iter = getIterator();
    608                final int nsize = ShapeUtils.calcSize(newShape);
    609                final boolean[] ndata; // PRIM_TYPE
    610                try {
    611                        ndata = createArray(nsize);
    612                } catch (Throwable t) {
    613                        logger.error("Could not create a dataset of shape {}", Arrays.toString(shape), t);
    614                        throw new IllegalArgumentException(t);
    615                }
    616                for (int i = 0; iter.hasNext() && i < nsize; i++) {
    617                        ndata[i] = data[iter.index];
    618                }
    619
    620                odata = data = ndata;
    621                size = nsize;
    622                shape = newShape;
    623                stride = null;
    624                offset = 0;
    625                base = null;
    626        }
    627
    628        @Override
    629        public BooleanDatasetBase sort(Integer axis) {
    630                throw new UnsupportedOperationException("Cannot sort dataset"); // BOOLEAN_USE
    631        }
    632
    633        @Override
    634        public BooleanDatasetBase getUniqueItems() {
    635                Set<Boolean> set = new TreeSet<Boolean>(); // CLASS_TYPE
    636                IndexIterator it = getIterator();
    637                while (it.hasNext()) {
    638                        set.add(data[it.index]);
    639                }
    640
    641                BooleanDataset u = new BooleanDataset(set.size()); // CLASS_TYPE
    642                int i = 0;
    643                boolean[] udata = u.getData(); // PRIM_TYPE
    644                for (Boolean v : set) { // CLASS_TYPE
    645                        udata[i++] = v;
    646                }
    647                return u;
    648        }
    649
    650        @Override
    651        public BooleanDatasetBase getSlice(final SliceIterator siter) {
    652                BooleanDatasetBase result = new BooleanDatasetBase(siter.getShape());
    653                boolean[] rdata = result.data; // PRIM_TYPE
    654
    655                for (int i = 0; siter.hasNext(); i++)
    656                        rdata[i] = data[siter.index];
    657
    658                result.setName(name + BLOCK_OPEN + Slice.createString(siter.shape, siter.start, siter.stop, siter.step) + BLOCK_CLOSE);
    659                return result;
    660        }
    661
    662        @Override
    663        public void fillDataset(Dataset result, IndexIterator iter) {
    664                setDirty();
    665                IndexIterator riter = result.getIterator();
    666
    667                boolean[] rdata = ((BooleanDatasetBase) result).data; // PRIM_TYPE
    668
    669                while (riter.hasNext() && iter.hasNext()) {
    670                        rdata[riter.index] = data[iter.index];
    671                }
    672        }
    673
    674        @Override
    675        public BooleanDatasetBase setByBoolean(final Object obj, Dataset selection) {
    676                setDirty();
    677                if (obj instanceof Dataset) {
    678                        final Dataset ds = (Dataset) obj;
    679                        final int length = ((Number) selection.sum()).intValue();
    680                        if (length != ds.getSize()) {
    681                                throw new IllegalArgumentException(
    682                                                "Number of true items in selection does not match number of items in dataset");
    683                        }
    684
    685                        final IndexIterator oiter = ds.getIterator();
    686                        final BooleanIterator biter = getBooleanIterator(selection);
    687
    688                        while (biter.hasNext() && oiter.hasNext()) {
    689                                data[biter.index] = ds.getElementBooleanAbs(oiter.index); // GET_ELEMENT_WITH_CAST
    690                        }
    691                } else {
    692                        final boolean dv = DTypeUtils.toBoolean(obj); // PRIM_TYPE // FROM_OBJECT
    693                        final BooleanIterator biter = getBooleanIterator(selection);
    694
    695                        while (biter.hasNext()) {
    696                                data[biter.index] = dv;
    697                        }
    698                }
    699                return this;
    700        }
    701
    702        @Override
    703        public BooleanDatasetBase setBy1DIndex(final Object obj, final Dataset index) {
    704                setDirty();
    705                if (obj instanceof Dataset) {
    706                        final Dataset ds = (Dataset) obj;
    707                        if (index.getSize() != ds.getSize()) {
    708                                throw new IllegalArgumentException(
    709                                                "Number of items in index dataset does not match number of items in dataset");
    710                        }
    711
    712                        final IndexIterator oiter = ds.getIterator();
    713                        final IntegerIterator iter = new IntegerIterator(index, size);
    714
    715                        while (iter.hasNext() && oiter.hasNext()) {
    716                                data[iter.index] = ds.getElementBooleanAbs(oiter.index); // GET_ELEMENT_WITH_CAST
    717                        }
    718                } else {
    719                        final boolean dv = DTypeUtils.toBoolean(obj); // PRIM_TYPE // FROM_OBJECT
    720                        IntegerIterator iter = new IntegerIterator(index, size);
    721
    722                        while (iter.hasNext()) {
    723                                data[iter.index] = dv;
    724                        }
    725                }
    726                return this;
    727        }
    728
    729        @Override
    730        public BooleanDatasetBase setByIndexes(final Object obj, final Object... indexes) {
    731                setDirty();
    732                final IntegersIterator iter = new IntegersIterator(shape, indexes);
    733                final int[] pos = iter.getPos();
    734
    735                if (obj instanceof Dataset) {
    736                        final Dataset ds = (Dataset) obj;
    737                        if (ShapeUtils.calcSize(iter.getShape()) != ds.getSize()) {
    738                                throw new IllegalArgumentException(
    739                                                "Number of items in index datasets does not match number of items in dataset");
    740                        }
    741
    742                        final IndexIterator oiter = ds.getIterator();
    743
    744                        while (iter.hasNext() && oiter.hasNext()) {
    745                                setItem(ds.getElementBooleanAbs(oiter.index), pos); // GET_ELEMENT_WITH_CAST
    746                        }
    747                } else {
    748                        final boolean dv = DTypeUtils.toBoolean(obj); // PRIM_TYPE // FROM_OBJECT
    749
    750                        while (iter.hasNext()) {
    751                                setItem(dv, pos);
    752                        }
    753                }
    754                return this;
    755        }
    756
    757        @Override
    758        BooleanDatasetBase setSlicedView(Dataset view, Dataset d) {
    759                setDirty();
    760                final BroadcastSelfIterator it = BroadcastSelfIterator.createIterator(view, d);
    761
    762                while (it.hasNext()) {
    763                        data[it.aIndex] = d.getElementBooleanAbs(it.bIndex);
    764                }
    765                return this;
    766        }
    767
    768        @Override
    769        public BooleanDatasetBase setSlice(final Object obj, final IndexIterator siter) {
    770                setDirty();
    771
    772                if (obj instanceof IDataset) {
    773                        final IDataset ds = (IDataset) obj;
    774                        final int[] oshape = ds.getShape();
    775
    776                        if (!ShapeUtils.areShapesCompatible(siter.getShape(), oshape)) {
    777                                throw new IllegalArgumentException(String.format(
    778                                                "Input dataset is not compatible with slice: %s cf %s", Arrays.toString(oshape),
    779                                                Arrays.toString(siter.getShape())));
    780                        }
    781
    782                        if (ds instanceof Dataset) {
    783                                final Dataset ads = (Dataset) ds;
    784                                final IndexIterator oiter = ads.getIterator();
    785
    786                                while (siter.hasNext() && oiter.hasNext())
    787                                        data[siter.index] = ads.getElementBooleanAbs(oiter.index); // GET_ELEMENT_WITH_CAST
    788                        } else {
    789                                final IndexIterator oiter = new PositionIterator(oshape);
    790                                final int[] pos = oiter.getPos();
    791
    792                                while (siter.hasNext() && oiter.hasNext())
    793                                        data[siter.index] = ds.getBoolean(pos); // PRIM_TYPE
    794                        }
    795                } else {
    796                        try {
    797                                boolean v = DTypeUtils.toBoolean(obj); // PRIM_TYPE // FROM_OBJECT
    798
    799                                while (siter.hasNext())
    800                                        data[siter.index] = v;
    801                        } catch (IllegalArgumentException e) {
    802                                throw new IllegalArgumentException("Object for setting slice is not a dataset or number");
    803                        }
    804                }
    805                return this;
    806        }
    807
    808        @Override
    809        public void copyItemsFromAxes(final int[] pos, final boolean[] axes, final Dataset dest) {
    810                boolean[] ddata = (boolean[]) dest.getBuffer(); // PRIM_TYPE
    811
    812                SliceIterator siter = getSliceIteratorFromAxes(pos, axes);
    813                int[] sshape = ShapeUtils.squeezeShape(siter.getShape(), false);
    814
    815                IndexIterator diter = dest.getSliceIterator(null, sshape, null);
    816
    817                if (ddata.length < ShapeUtils.calcSize(sshape)) {
    818                        throw new IllegalArgumentException("destination array is not large enough");
    819                }
    820
    821                dest.setDirty();
    822                while (siter.hasNext() && diter.hasNext()) {
    823                        ddata[diter.index] = data[siter.index];
    824                }
    825        }
    826
    827        @Override
    828        public void setItemsOnAxes(final int[] pos, final boolean[] axes, final Object src) {
    829                setDirty();
    830                boolean[] sdata = (boolean[]) src; // PRIM_TYPE
    831
    832                SliceIterator siter = getSliceIteratorFromAxes(pos, axes);
    833
    834                if (sdata.length < ShapeUtils.calcSize(siter.getShape())) {
    835                        throw new IllegalArgumentException("destination array is not large enough");
    836                }
    837
    838                for (int i = 0; siter.hasNext(); i++) {
    839                        data[siter.index] = sdata[i];
    840                }
    841        }
    842
    843        private List<int[]> findPositions(final boolean value) { // PRIM_TYPE
    844                IndexIterator iter = getIterator(true);
    845                List<int[]> posns = new ArrayList<int[]>();
    846                int[] pos = iter.getPos();
    847
    848                {
    849                        while (iter.hasNext()) {
    850                                if (data[iter.index] == value) {
    851                                        posns.add(pos.clone());
    852                                }
    853                        }
    854                }
    855                return posns;
    856        }
    857
    858        @Override
    859        public int[] maxPos(boolean... ignoreInvalids) {
    860                StatisticsMetadata<Number> md = getStats(); // BOOLEAN_USE
    861                // StatisticsMetadata<String> md = getStringStats(); // OBJECT_USE
    862                List<int[]> max = md.getMaximumPositions(ignoreInvalids);
    863
    864                if (max == null) {
    865                        max = findPositions(md.getMaximum(ignoreInvalids).intValue() != 0); // BOOLEAN_USE
    866                        // max = findPositions(md.getMaximum(ignoreInvalids).toString()); // OBJECT_USE
    867
    868                        md.setMaximumPositions(max);
    869                }
    870
    871                return max.get(0); // first maximum
    872        }
    873
    874        @Override
    875        public int[] minPos(boolean... ignoreInvalids) {
    876                StatisticsMetadata<Number> md = getStats(); // BOOLEAN_USE
    877                // StatisticsMetadata<String> md = getStringStats(); // OBJECT_USE
    878                List<int[]> min = md.getMinimumPositions(ignoreInvalids);
    879
    880                if (min == null) {
    881                        min = findPositions(md.getMinimum(ignoreInvalids).intValue() != 0); // BOOLEAN_USE
    882                        // min = findPositions(md.getMinimum(ignoreInvalids).toString()); // OBJECT_USE
    883
    884                        md.setMinimumPositions(min);
    885                }
    886
    887                return min.get(0); // first minimum
    888        }
    889
    890        @Override
    891        public boolean containsNans() {
    892                return false;
    893        }
    894
    895        @Override
    896        public boolean containsInfs() {
    897                return false;
    898        }
    899
    900        @Override
    901        public boolean containsInvalidNumbers() {
    902                return false;
    903        }
    904
    905        @Override
    906        public BooleanDatasetBase iadd(final Object b) {
    907                return this;
    908        }
    909
    910        @Override
    911        public BooleanDatasetBase isubtract(final Object b) {
    912                return this;
    913        }
    914
    915        @Override
    916        public BooleanDatasetBase imultiply(final Object b) {
    917                return this;
    918        }
    919
    920        @Override
    921        public BooleanDatasetBase idivide(final Object b) {
    922                return this;
    923        }
    924
    925        @Override
    926        public BooleanDatasetBase ifloor() {
    927                return this;
    928        }
    929
    930        @Override
    931        public BooleanDatasetBase iremainder(final Object b) {
    932                return this;
    933        }
    934
    935        @Override
    936        public BooleanDatasetBase ipower(final Object b) {
    937                return this;
    938        }
    939
    940        @Override
    941        public double residual(final Object b, final Dataset w, boolean ignoreNaNs) {
    942                double sum = 0;
    943                return sum;
    944        }
    945}