    001/*-
    002 * Copyright 2016 Diamond Light Source Ltd.
    003 *
    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
    010package org.eclipse.january.dataset;
    011
    012import java.util.Arrays;
    013
    014/**
    015 * Base class for broadcast iterators where the second dataset could be broadcast to the first and it is also read into either bLong or bDouble fields.
    016 * For speed, there are public members. Note, index is not updated
    017 */
    018public abstract class BroadcastSelfIterator extends BroadcastIteratorBase {
    019
    020        public static BroadcastSelfIterator createIterator(Dataset a, Dataset b) {
    021                if (Arrays.equals(a.getShapeRef(), b.getShapeRef()) && a.getStrides() == null && b.getStrides() == null) {
    022                        return new ContiguousSingleIterator(a, b);
    023                }
    024                return new BroadcastSingleIterator(a, b);
    025        }
    026
    027        protected BroadcastSelfIterator(Dataset a, Dataset b) {
    028                super(a, b);
    029                read = DTypeUtils.isDTypeNumerical(b.getDType());
    030                asDouble = aDataset.hasFloatingPointElements();
    031                BroadcastUtils.checkItemSize(a, b, null);
    032        }
    033
    034        @Override
    035        protected void storeCurrentValues() {
    036                if (bIndex >= 0) {
    037                        if (asDouble) {
    038                                bDouble = bDataset.getElementDoubleAbs(bIndex);
    039                        } else {
    040                                bLong = bDataset.getElementLongAbs(bIndex);
    041                        }
    042                }
    043        }
    044}