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

lphy.base.function.SumRows 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 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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy