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

org.nd4j.linalg.ops.reduceops.scalarops.BaseScalarOp Maven / Gradle / Ivy

There is a newer version: 1.0.0-M2.1
Show newest version
package org.nd4j.linalg.ops.reduceops.scalarops;

import org.nd4j.linalg.api.ndarray.INDArray;

/**
 *
 * Abstract class for scalar operations
 * @author Adam Gibson
 */
public abstract class BaseScalarOp implements ScalarOp {

    protected double startingValue;


    public BaseScalarOp(double startingValue) {
        this.startingValue = startingValue;
    }



    @Override
    public Double apply(INDArray input) {
        INDArray doNDArray = input.isVector() ? input : input.linearView();
        double start = startingValue;
        for(int i = 0; i < doNDArray.length(); i++) {
            start = accumulate(doNDArray, i, start);
            
        }
        return start;
    }

    public abstract double accumulate(INDArray arr,int i,double soFar);


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy