Skip to contents

Generic function to extract the numeric data from a differentiable object. For value objects, returns the underlying matrix. For plain numeric inputs, converts to matrix representation.

Assignment function to update the data field of a value object without breaking the computational graph reference.

Usage

get_data(x, ...)

# S3 method for class 'value'
get_data(x, drop = TRUE, ...)

# Default S3 method
get_data(x, ...)

get_data(x) <- value

# S3 method for class 'value'
get_data(x) <- value

# Default S3 method
get_data(x) <- value

Arguments

x

A value object

...

additional arguments to pass

drop

If TRUE (default) and result is 1x1, return scalar. Set to FALSE to always return a matrix.

value

The new numeric value to assign (converted to matrix)

Value

The data as scalar (if 1x1 and drop=TRUE) or matrix

The modified value object (invisibly)

Examples

x <- val(5)
get_data(x)          # Returns 5 (scalar)
#> [1] 5
get_data(x, drop = FALSE)  # Returns 1x1 matrix
#>      [,1]
#> [1,]    5

if (FALSE) { # \dontrun{
x <- val(5)
get_data(x) <- 10
get_data(x)  # Returns 10
} # }