com.meliorbis.numerics.generic.primitives.impl.DoubleMultiValuedNaryOpCallable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Numerics Show documentation
Show all versions of Numerics Show documentation
A library for working with large multi-dimensional arrays and the functions they represent
package com.meliorbis.numerics.generic.primitives.impl;
import com.meliorbis.numerics.generic.NaryOp;
import com.meliorbis.numerics.generic.SettableIterator;
import com.meliorbis.numerics.generic.impl.NaryOpCallable;
import com.meliorbis.numerics.generic.primitives.DoubleArraySettableIterator;
import com.meliorbis.numerics.generic.primitives.DoubleMultiValuedNaryOp;
import com.meliorbis.numerics.generic.primitives.DoubleSettableIterator;
/**
* Specialisation of NaryOpCallable for primitive double arrays
*/
public class DoubleMultiValuedNaryOpCallable extends NaryOpCallable
{
private final double[] _currentVals;
public DoubleMultiValuedNaryOpCallable(DoubleMultiValuedNaryOp op_, SettableIterator extends Double>[] inputs_, SettableIterator> result_,
boolean iterateResult_)
{
super((NaryOp)op_, inputs_, result_, iterateResult_);
_currentVals = new double[inputs_.length];
}
@SuppressWarnings("unchecked")
@Override
protected void computeNextStep() throws E
{
for (int i = 0; i < _iterators.length; i++) {
_currentVals[i] = ((DoubleSettableIterator)_iterators[i]).nextDouble();
}
// Only iterate the result if requested (because the result could be the same as one of the inputs and hence be
// already iterated
if(_iterateResult)
{
((DoubleArraySettableIterator)_resultIter).nextDoubles();
}
((DoubleArraySettableIterator)_resultIter).set(((DoubleMultiValuedNaryOp)_op).perform(_currentVals));
}
}