Example usage for java.util.function DoubleUnaryOperator applyAsDouble

List of usage examples for java.util.function DoubleUnaryOperator applyAsDouble

Introduction

In this page you can find the example usage for java.util.function DoubleUnaryOperator applyAsDouble.

Prototype

double applyAsDouble(double operand);

Source Link

Document

Applies this operator to the given operand.

Usage

From source file:at.gridtec.lambda4j.predicate.tri.obj.BiObjDoublePredicate.java

/**
 * Returns a composed {@link TriDoublePredicate} that first applies the {@code before} functions to its input, and
 * then applies this predicate to the result. If evaluation of either operation throws an exception, it is relayed
 * to the caller of the composed operation. This method is just convenience, to provide the ability to execute an
 * operation which accepts {@code double} input, before this primitive predicate is executed.
 *
 * @param before1 The first function to apply before this predicate is applied
 * @param before2 The second function to apply before this predicate is applied
 * @param before3 The third operator to apply before this predicate is applied
 * @return A composed {@code TriDoublePredicate} that first applies the {@code before} functions to its input, and
 * then applies this predicate to the result.
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is a able to handle primitive values. In this case this is {@code
 * double}./*w w w.j  a v a2s  .  c  o  m*/
 */
@Nonnull
default TriDoublePredicate composeFromDouble(@Nonnull final DoubleFunction<? extends T> before1,
        @Nonnull final DoubleFunction<? extends U> before2, @Nonnull final DoubleUnaryOperator before3) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    Objects.requireNonNull(before3);
    return (value1, value2, value3) -> test(before1.apply(value1), before2.apply(value2),
            before3.applyAsDouble(value3));
}

From source file:com.simiacryptus.mindseye.lang.Tensor.java

/**
 * Map parallel tensor.//www.  j a  v a2  s . co m
 *
 * @param f the f
 * @return the tensor
 */
@Nullable
public Tensor mapParallel(@Nonnull final DoubleUnaryOperator f) {
    @Nullable
    final double[] data = getData();
    return new Tensor(Tensor.getDoubles(IntStream.range(0, length()).mapToDouble(i -> f.applyAsDouble(data[i])),
            length()), dimensions);
}

From source file:com.simiacryptus.mindseye.lang.Tensor.java

/**
 * Map tensor./* ww w.jav  a2 s .  com*/
 *
 * @param f the f
 * @return the tensor
 */
@Nullable
public Tensor map(@Nonnull final DoubleUnaryOperator f) {
    @Nullable
    final double[] data = getData();
    Tensor tensor = new Tensor(dimensions);
    @Nonnull
    final double[] cpy = tensor.getData();
    IntStream.range(0, data.length).parallel().forEach(i -> cpy[i] = f.applyAsDouble(data[i]));
    return tensor;
}

From source file:com.simiacryptus.mindseye.lang.Tensor.java

/**
 * Map and free tensor./*from  w w  w.  ja v  a  2 s .co  m*/
 *
 * @param f the f
 * @return the tensor
 */
@Nullable
public Tensor mapAndFree(@Nonnull final DoubleUnaryOperator f) {
    @Nullable
    final double[] data = getData();
    @Nonnull
    final double[] cpy = new double[data.length];
    for (int i = 0; i < data.length; i++) {
        final double x = data[i];
        // assert Double.isFinite(x);
        final double v = f.applyAsDouble(x);
        // assert Double.isFinite(v);
        cpy[i] = v;
    }
    Tensor tensor = new Tensor(cpy, dimensions);
    this.freeRef();
    return tensor;
}

From source file:org.briljantframework.array.AbstractDoubleArray.java

@Override
public void assign(DoubleArray array, DoubleUnaryOperator operator) {
    array = ShapeUtils.broadcastIfSensible(this, array);
    Check.size(this, array);
    for (int i = 0; i < size(); i++) {
        set(i, operator.applyAsDouble(array.get(i)));
    }/*from ww w . j  ava  2s .  c  o  m*/
}

From source file:org.briljantframework.array.AbstractDoubleArray.java

@Override
public DoubleArray map(DoubleUnaryOperator operator) {
    DoubleArray mat = newEmptyArray(getShape());
    for (int i = 0; i < size(); i++) {
        mat.set(i, operator.applyAsDouble(get(i)));
    }// ww w. j a v  a2  s  .  c o m
    return mat;
}

From source file:org.briljantframework.array.AbstractDoubleArray.java

@Override
public void apply(DoubleUnaryOperator operator) {
    for (int i = 0; i < size(); i++) {
        set(i, operator.applyAsDouble(get(i)));
    }/*  w  w w .  j a va 2  s.c o m*/
}

From source file:org.lenskit.util.math.Vectors.java

/**
 * Transform the values of a vector.//from   w w w . j  av a  2  s  . c  o m
 *
 * @param input The vector to transform.
 * @param function The transformation to apply.
 * @return A new vector that is the result of applying `function` to each value in `input`.
 */
public static Long2DoubleMap transform(Long2DoubleMap input, DoubleUnaryOperator function) {
    // FIXME Improve performance when input is also sorted
    SortedKeyIndex idx = SortedKeyIndex.fromCollection(input.keySet());
    int n = idx.size();
    double[] values = new double[n];
    for (int i = 0; i < n; i++) {
        values[i] = function.applyAsDouble(input.get(idx.getKey(i)));
    }

    return Long2DoubleSortedArrayMap.wrap(idx, values);
}