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:com.simiacryptus.mindseye.applications.ArtistryUtil.java

/**
 * Expand plasma tensor./*w  ww.  j  av a 2 s .c  om*/
 *
 * @param seed  the seed
 * @param noise the noise
 * @return the tensor
 */
public static Tensor expandPlasma(final Tensor seed, double noise) {
    int bands = seed.getDimensions()[2];
    int width = seed.getDimensions()[0] * 2;
    int height = seed.getDimensions()[1] * 2;
    Tensor returnValue = new Tensor(width, height, bands);
    DoubleUnaryOperator fn1 = x -> Math.max(Math.min(x + noise * (Math.random() - 0.5), 255), 0);
    DoubleUnaryOperator fn2 = x -> Math.max(Math.min(x + Math.sqrt(2) * noise * (Math.random() - 0.5), 255), 0);
    IntUnaryOperator addrX = x -> {
        while (x >= width)
            x -= width;
        while (x < 0)
            x += width;
        return x;
    };
    IntUnaryOperator addrY = x -> {
        while (x >= height)
            x -= height;
        while (x < 0)
            x += height;
        return x;
    };
    for (int band = 0; band < bands; band++) {
        for (int x = 0; x < width; x += 2) {
            for (int y = 0; y < height; y += 2) {
                double value = seed.get(x / 2, y / 2, band);
                returnValue.set(x, y, band, value);
            }
        }
        for (int x = 1; x < width; x += 2) {
            for (int y = 1; y < height; y += 2) {
                double value = (returnValue.get(addrX.applyAsInt(x - 1), addrY.applyAsInt(y - 1), band))
                        + (returnValue.get(addrX.applyAsInt(x - 1), addrY.applyAsInt(y + 1), band))
                        + (returnValue.get(addrX.applyAsInt(x + 1), addrY.applyAsInt(y - 1), band))
                        + (returnValue.get(addrX.applyAsInt(x + 1), addrY.applyAsInt(y + 1), band));
                value = fn2.applyAsDouble(value / 4);
                returnValue.set(x, y, band, value);
            }
        }
        for (int x = 0; x < width; x += 2) {
            for (int y = 1; y < height; y += 2) {
                double value = (returnValue.get(addrX.applyAsInt(x - 1), addrY.applyAsInt(y), band))
                        + (returnValue.get(addrX.applyAsInt(x + 1), addrY.applyAsInt(y), band))
                        + (returnValue.get(addrX.applyAsInt(x), addrY.applyAsInt(y - 1), band))
                        + (returnValue.get(addrX.applyAsInt(x), addrY.applyAsInt(y + 1), band));
                value = fn1.applyAsDouble(value / 4);
                returnValue.set(x, y, band, value);
            }
        }
        for (int x = 1; x < width; x += 2) {
            for (int y = 0; y < height; y += 2) {
                double value = (returnValue.get(addrX.applyAsInt(x - 1), addrY.applyAsInt(y), band))
                        + (returnValue.get(addrX.applyAsInt(x + 1), addrY.applyAsInt(y), band))
                        + (returnValue.get(addrX.applyAsInt(x), addrY.applyAsInt(y - 1), band))
                        + (returnValue.get(addrX.applyAsInt(x), addrY.applyAsInt(y + 1), band));
                value = fn1.applyAsDouble(value / 4);
                returnValue.set(x, y, band, value);
            }
        }
    }
    return returnValue;
}

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjDoubleToByteFunction.java

/**
 * Returns a composed {@link TriDoubleToByteFunction} that first applies the {@code before} functions to its input,
 * and then applies this function 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 function is executed.
 *
 * @param before1 The first function to apply before this function is applied
 * @param before2 The second function to apply before this function is applied
 * @param before3 The third operator to apply before this function is applied
 * @return A composed {@code TriDoubleToByteFunction} that first applies the {@code before} functions to its input,
 * and then applies this function 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}./*from w ww .  j a  v  a  2 s .  c  o  m*/
 */
@Nonnull
default TriDoubleToByteFunction 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) -> applyAsByte(before1.apply(value1), before2.apply(value2),
            before3.applyAsDouble(value3));
}

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjDoubleToCharFunction.java

/**
 * Returns a composed {@link TriDoubleToCharFunction} that first applies the {@code before} functions to its input,
 * and then applies this function 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 function is executed.
 *
 * @param before1 The first function to apply before this function is applied
 * @param before2 The second function to apply before this function is applied
 * @param before3 The third operator to apply before this function is applied
 * @return A composed {@code TriDoubleToCharFunction} that first applies the {@code before} functions to its input,
 * and then applies this function 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}./* www  .j ava  2  s. co  m*/
 */
@Nonnull
default TriDoubleToCharFunction 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) -> applyAsChar(before1.apply(value1), before2.apply(value2),
            before3.applyAsDouble(value3));
}

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjDoubleToFloatFunction.java

/**
 * Returns a composed {@link TriDoubleToFloatFunction} that first applies the {@code before} functions to its input,
 * and then applies this function 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 function is executed.
 *
 * @param before1 The first function to apply before this function is applied
 * @param before2 The second function to apply before this function is applied
 * @param before3 The third operator to apply before this function is applied
 * @return A composed {@code TriDoubleToFloatFunction} that first applies the {@code before} functions to its input,
 * and then applies this function 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}.//from ww w  . j  a v a  2 s.c  om
 */
@Nonnull
default TriDoubleToFloatFunction 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) -> applyAsFloat(before1.apply(value1), before2.apply(value2),
            before3.applyAsDouble(value3));
}

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjDoubleToIntFunction.java

/**
 * Returns a composed {@link TriDoubleToIntFunction} that first applies the {@code before} functions to its input,
 * and then applies this function 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 function is executed.
 *
 * @param before1 The first function to apply before this function is applied
 * @param before2 The second function to apply before this function is applied
 * @param before3 The third operator to apply before this function is applied
 * @return A composed {@code TriDoubleToIntFunction} that first applies the {@code before} functions to its input,
 * and then applies this function 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}.//from www . ja v a  2  s  .  c  o m
 */
@Nonnull
default TriDoubleToIntFunction 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) -> applyAsInt(before1.apply(value1), before2.apply(value2),
            before3.applyAsDouble(value3));
}

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjDoubleToShortFunction.java

/**
 * Returns a composed {@link TriDoubleToShortFunction} that first applies the {@code before} functions to its input,
 * and then applies this function 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 function is executed.
 *
 * @param before1 The first function to apply before this function is applied
 * @param before2 The second function to apply before this function is applied
 * @param before3 The third operator to apply before this function is applied
 * @return A composed {@code TriDoubleToShortFunction} that first applies the {@code before} functions to its input,
 * and then applies this function 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}.//from  ww w .j a  v a  2 s  .  co  m
 */
@Nonnull
default TriDoubleToShortFunction 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) -> applyAsShort(before1.apply(value1), before2.apply(value2),
            before3.applyAsDouble(value3));
}

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjDoubleToLongFunction.java

/**
 * Returns a composed {@link TriDoubleToLongFunction} that first applies the {@code before} functions to its input,
 * and then applies this function 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 function is executed.
 *
 * @param before1 The first function to apply before this function is applied
 * @param before2 The second function to apply before this function is applied
 * @param before3 The third operator to apply before this function is applied
 * @return A composed {@code TriDoubleToLongFunction} that first applies the {@code before} functions to its input,
 * and then applies this function 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}./*from w  ww  . j  ava2  s  .c  om*/
 */
@Nonnull
default TriDoubleToLongFunction 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) -> applyAsLong(before1.apply(value1), before2.apply(value2),
            before3.applyAsDouble(value3));
}

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjDoubleToDoubleFunction.java

/**
 * Returns a composed {@link DoubleTernaryOperator} that first applies the {@code before} functions to its input,
 * and then applies this function 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 function is executed.
 *
 * @param before1 The first function to apply before this function is applied
 * @param before2 The second function to apply before this function is applied
 * @param before3 The third operator to apply before this function is applied
 * @return A composed {@code DoubleTernaryOperator} that first applies the {@code before} functions to its input,
 * and then applies this function 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}.//from   w w w  .  j  a va  2  s.c o  m
 */
@Nonnull
default DoubleTernaryOperator 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) -> applyAsDouble(before1.apply(value1), before2.apply(value2),
            before3.applyAsDouble(value3));
}

From source file:at.gridtec.lambda4j.predicate.tri.TriDoublePredicate.java

/**
 * Returns a composed {@link TriDoublePredicate} that first applies the {@code before} operators 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 operator to apply before this predicate is applied
 * @param before2 The second operator 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} operators 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}./*from   w  w  w  . j  a  va 2s . c o m*/
 */
@Nonnull
default TriDoublePredicate composeFromDouble(@Nonnull final DoubleUnaryOperator before1,
        @Nonnull final DoubleUnaryOperator before2, @Nonnull final DoubleUnaryOperator before3) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    Objects.requireNonNull(before3);
    return (value1, value2, value3) -> test(before1.applyAsDouble(value1), before2.applyAsDouble(value2),
            before3.applyAsDouble(value3));
}

From source file:at.gridtec.lambda4j.predicate.tri.obj.ObjBiDoublePredicate.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 operator 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. co  m
 */
@Nonnull
default TriDoublePredicate composeFromDouble(@Nonnull final DoubleFunction<? extends T> before1,
        @Nonnull final DoubleUnaryOperator before2, @Nonnull final DoubleUnaryOperator before3) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    Objects.requireNonNull(before3);
    return (value1, value2, value3) -> test(before1.apply(value1), before2.applyAsDouble(value2),
            before3.applyAsDouble(value3));
}