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

lphy.base.function.SumCols Maven / Gradle / Ivy

Go to download

The standard library of LPhy, which contains the required generative distributions and basic functions.

The newest version!
package lphy.base.function;

import lphy.base.ParameterNames;
import lphy.core.model.DeterministicFunction;
import lphy.core.model.Value;
import lphy.core.model.annotation.GeneratorInfo;
import lphy.core.model.annotation.ParameterInfo;
import lphy.core.model.datatype.NumberArrayValue;

public class SumCols extends DeterministicFunction {

    public SumCols(@ParameterInfo(name = ParameterNames.ArrayParamName, description = "the 2d array to sum the elements of.")
                   Value x) {
        setParam(ParameterNames.ArrayParamName, x);
    }

    @GeneratorInfo(name = "sumCols", description = "Sums over each column of the given array")
    public Value apply() {
        Number[][] v = (Number[][]) getParams().get(ParameterNames.ArrayParamName).value();
        SumUtils utils = new SumUtils();
        Number[] sum = utils.sumCols(v);
        return new NumberArrayValue(null, sum, this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy