R/layout.R

Defines functions is_torch_layout torch_sparse_coo torch_strided

Documented in is_torch_layout torch_sparse_coo torch_strided

torch_layout <- R7Class(
  classname = "torch_layout",
  public = list(
    ptr = NULL,
    initialize = function(ptr) {
      self$ptr <- ptr
    },
    print = function() {
      cat("torch_", cpp_layout_to_string(self$ptr), sep = "")
    }
  )
)

#' Creates the corresponding layout
#'
#' @name torch_layout
#' @rdname torch_layout
NULL

#' @rdname torch_layout
#' @export
torch_strided <- function() torch_layout$new(cpp_torch_strided())

#' @rdname torch_layout
#' @export
torch_sparse_coo <- function() torch_layout$new(cpp_torch_sparse())

#' Check if an object is a torch layout.
#'
#' @param x object to check
#'
#' @export
is_torch_layout <- function(x) {
  inherits(x, "torch_layout")
}

Try the torch package in your browser

Any scripts or data that you put into this service are public.

torch documentation built on May 29, 2024, 9:54 a.m.