Skip to contents

Symbolic element-wise clamp function (ternary operation) for LazyTensor objects.

Usage

clamp(x, a, b)

Arguments

x, a, b

A LazyTensor, a vector of numeric values, or a scalar value.

Value

An object of class LazyTensor.

Details

clamp(x, a, b) returns a LazyTensor that encodes, symbolically, the element-wise clamping of x in (a, b), i.e. a if x < a, x if a <= x <= b, and b if b < x. Broadcasting rules apply.

Note: If a and b are not scalar values, these should have the same inner dimension as x.

Author

Chloe Serre-Combe, Amelie Vernay

Examples

if (FALSE) {
# basic example
D <- 3
M <- 100
N <- 150
P <- 200
x <- matrix(runif(M * D), M, D)
y <- matrix(runif(N * D), N, D)
z <- matrix(runif(P * D), P, D)
x_i <- LazyTensor(x, index = 'i')
y_j <- LazyTensor(y, index = 'j')
z_i <- LazyTensor(z, index = 'i')

# call clamp function
clp <- clamp(x_i, y_j, z_i)
}