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