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);
            if(Double.isNaN(start))
                throw new IllegalStateException("Something has gone horribly wrong. " +
                        "NaN found at index " + i + " " +
                        "the causing value was " + doNDArray.getDouble(i));
        }
        return start;
    }

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


}

@@ -653,253 +653,8 @@
     
-if(Double.isNaN(start))%0A                throw new IllegalStateException(%22Something has gone horribly wrong. %22 +%0A                        %22NaN found at index %22 + i + %22 %22 +%0A                        %22the causing value was %22 + doNDArray.getDouble(i));
 %0A   

remove nan exception: apparently 4e-324 returns nan