lphy.base.function.SumCols Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lphy-base Show documentation
Show all versions of lphy-base Show documentation
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);
}
}