All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.meliorbis.numerics.generic.impl.GenericNaryOpCallable Maven / Gradle / Ivy

Go to download

A library for working with large multi-dimensional arrays and the functions they represent

There is a newer version: 1.2
Show newest version
package com.meliorbis.numerics.generic.impl;

import com.meliorbis.numerics.generic.MultiValuedNaryOp;
import com.meliorbis.numerics.generic.NaryOp;
import com.meliorbis.numerics.generic.SettableIterator;

/**
 */
public abstract class GenericNaryOpCallable extends NaryOpCallable
{
    private final T[] _currentVals;

    public GenericNaryOpCallable(NaryOp op_, SettableIterator[] inputs_,
                                 SettableIterator result_, boolean iterateResult_)
    {
        super(op_, inputs_, result_, iterateResult_);

        _currentVals = createTypedArray(inputs_.length);
    }

    abstract protected T[] createTypedArray(int length_);

    @SuppressWarnings("unchecked")
	@Override
    protected void computeNextStep() throws E
    {
        for (int i = 0; i < _iterators.length; i++) {
            _currentVals[i] = _iterators[i].next();
        }

        if(_iterateResult) 
        {
        	_resultIter.next();
        }
        
        if(_op instanceof MultiValuedNaryOp) 
        {
        	((SettableIterator)_resultIter).set((T[])_op.perform(_currentVals));
        }
        else
        {
        	((SettableIterator)_resultIter).set((T)_op.perform(_currentVals));	
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy