as.matrix.ag_tensor: Extract the value of an ag_tensor as an R matrix

View source: R/autograd.R

as.matrix.ag_tensorR Documentation

Extract the value of an ag_tensor as an R matrix

Description

The value of an ag_tensor lives in $data only on the CPU. On the GPU it lives in a backend buffer and $data stays NULL until something materialises it, so reading $data directly works on one device and returns NULL on the other. This method downloads the value when it has to and returns the same matrix either way – use it rather than $data in code that may run on a GPU.

Usage

## S3 method for class 'ag_tensor'
as.matrix(x, ...)

Arguments

x

An ag_tensor

...

Ignored

Value

A numeric matrix holding the tensor's current value.

Examples

t <- ag_tensor(matrix(1:6, nrow = 2))
as.matrix(t)

ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.