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 016 * and it is also read into either bLong or bDouble fields.<p> 017 * For speed, there are public members. Note, index is not updated 018 */ 019public abstract class BroadcastSelfIterator extends BroadcastIteratorBase { 020 021 public static BroadcastSelfIterator createIterator(Dataset a, Dataset b) { 022 if (Arrays.equals(a.getShapeRef(), b.getShapeRef()) && a.getStrides() == null && b.getStrides() == null) { 023 return new ContiguousSingleIterator(a, b); 024 } 025 return new BroadcastSingleIterator(a, b); 026 } 027 028 protected BroadcastSelfIterator(Dataset a, Dataset b) { 029 super(a, b); 030 read = DTypeUtils.isDTypeNumerical(b.getDType()); 031 asDouble = aDataset.hasFloatingPointElements(); 032 BroadcastUtils.checkItemSize(a, b, null); 033 } 034 035 @Override 036 protected void storeCurrentValues() { 037 if (bIndex >= 0) { 038 if (asDouble) { 039 bDouble = bDataset.getElementDoubleAbs(bIndex); 040 } else { 041 bLong = bDataset.getElementLongAbs(bIndex); 042 } 043 } 044 } 045}