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 012/** 013 * Base class for all broadcast iterators. For speed, there are public members. Note, index is not updated 014 */ 015public abstract class BroadcastIteratorBase extends IndexIterator { 016 017 /** 018 * Index in first dataset 019 */ 020 public int aIndex; 021 /** 022 * Index in second dataset 023 */ 024 public int bIndex; 025 /** 026 * Current value in second dataset 027 */ 028 public double bDouble; 029 /** 030 * Current value in second dataset 031 */ 032 public long bLong; 033 034 protected boolean asDouble = true; 035 protected boolean read = true; 036 037 protected int[] maxShape; 038 039 /** 040 * position in dataset 041 */ 042 protected int[] pos; 043 044 protected Dataset aDataset; 045 protected Dataset bDataset; 046 047 /** 048 * @param a dataset to iterate over 049 * @param b dataset to iterate over 050 */ 051 public BroadcastIteratorBase(Dataset a, Dataset b) { 052 aDataset = a; 053 bDataset = b; 054 } 055 056 @Override 057 public int[] getShape() { 058 return maxShape; 059 } 060 061 @Override 062 public int[] getPos() { 063 return pos; 064 } 065 066 /** 067 * @return true if output from iterator is double 068 */ 069 public boolean isOutputDouble() { 070 return asDouble; 071 } 072 073 /** 074 * Set to output doubles 075 * @param asDouble if true, output is set as doubles 076 */ 077 public void setOutputDouble(boolean asDouble) { 078 if (this.asDouble != asDouble) { 079 this.asDouble = asDouble; 080 storeCurrentValues(); 081 } 082 } 083 084 /** 085 * Read and store current values 086 */ 087 abstract protected void storeCurrentValues(); 088 089}