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