R/zzz.R

Defines functions installTorch

Documented in installTorch

installTorch <- function(){
  installedTORCH <- requireNamespace("torch", quietly = TRUE)
  tryCatch({
    res <- FALSE
    if (installedTORCH){
      res <- torch::torch_is_installed()
      if(res & !isNamespaceLoaded("torch")) attachNamespace("torch")
    }
    return(res)
  })
}

# Function called when a package is attached
.onAttach <- function (libname, pkgname) {

  installedTORCH <- requireNamespace("torch", quietly = TRUE)

  # Check if Tensorflow is installed
  installTorch <- tryCatch({
    res <- FALSE
    if (installedTORCH){
      res <- torch::torch_is_installed()
      if(res & !isNamespaceLoaded("torch")) attachNamespace("torch")
    }
    res
  })


  installedTENSORFLOW <- requireNamespace("tensorflow", quietly = TRUE)

  # Attach Tensorflow namespace if it is installed
  if (installedTENSORFLOW & !isNamespaceLoaded("tensorflow")) attachNamespace("tensorflow")

  # Display startup message depending on the installed packages
  if(installTorch) packageStartupMessage("Torch tensors allowed")
  if (installedTENSORFLOW) packageStartupMessage("Tensorflow tensors allowed")
  if(installTorch == FALSE & installedTENSORFLOW == FALSE) packageStartupMessage("Not torch or tensorflow installed")
  if(installTorch){
    if(torch::cuda_is_available()) packageStartupMessage("Your Torch installation have CUDA tensors available.")
    if(!torch::cuda_is_available()) packageStartupMessage("Your Torch installation does not have CUDA tensors available. Please check the Torch requirements and installation if you want to use CUDA tensors.")
  }

  # Set typeTensor option to "torch"
  options(typeTensor = "torch")



}

Try the GPUmatrix package in your browser

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

GPUmatrix documentation built on May 29, 2024, 11:02 a.m.