lphy.base.function.SumRows 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 SumRows extends DeterministicFunction {
public SumRows(@ParameterInfo(name = ParameterNames.ArrayParamName, description = "the 2d array to sum the elements of.")
Value x) {
setParam(ParameterNames.ArrayParamName, x);
}
@GeneratorInfo(name = "sumRows", description = "Sums over each row of the given array")
public Value apply() {
Number[][] v = (Number[][]) getParams().get(ParameterNames.ArrayParamName).value();
SumUtils utils = new SumUtils();
Number[] sum = utils.sumRows(v);
return new NumberArrayValue(null, sum, this);
}
}