## ----include = FALSE----------------------------------------------------------
# Code chunks are not evaluated: the package requires a Python runtime
# with u-stats / numpy / torch, which is not available (and should not
# be downloaded) on the machines that build this vignette.
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = FALSE
)

## -----------------------------------------------------------------------------
# install.packages("ustats")
# library(ustats)
# 
# H <- matrix(rnorm(100), 10, 10)
# ustat(list(H, H), "ab,bc->")

## -----------------------------------------------------------------------------
# library(ustats)
# ustat(list(matrix(rnorm(100), 10, 10)), "ab->")

## -----------------------------------------------------------------------------
# library(ustats)
# 
# setup_ustats()                # virtualenv/conda + CPU-only torch
# setup_ustats(gpu = TRUE)      # default PyPI torch (CUDA-enabled on Linux)
# setup_ustats(
#   method  = "virtualenv",     # or "conda"
#   envname = "r-ustats",
#   persist = TRUE              # print the RETICULATE_PYTHON line to add
# )                             # to your .Rprofile (no files are written)

## -----------------------------------------------------------------------------
# library(ustats)
# reticulate::use_condaenv("your_env_name", required = TRUE)
# # or: reticulate::use_virtualenv("~/.virtualenvs/your_env")

## -----------------------------------------------------------------------------
# check_ustats_setup()
# #> === ustats Environment Status ===
# #>
# #> [OK] Python: /path/to/python
# #>   Version: 3.12
# #> [OK] u_stats available
# #> [OK] NumPy available
# #> [OK] PyTorch available (version 2.5.1, CUDA available)
# #>
# #> ---------------------------------
# #>  Environment fully ready (Torch backend available)

## -----------------------------------------------------------------------------
# library(ustats)
# 
# set.seed(1)
# n <- 300
# 
# H1 <- rnorm(n)
# H2 <- matrix(rnorm(n * n), n, n)
# H3 <- rnorm(n)
# 
# result <- ustat(
#   tensors    = list(H1, H2, H2, H3),
#   expression = "a,ab,bc,c->",
#   backend    = "torch",  # falls back to numpy if torch is unavailable
#   average    = TRUE,     # divide by the number of index tuples
#   dtype      = NULL      # auto: float32 on GPU, float64 on CPU
# )
# print(result)

## -----------------------------------------------------------------------------
# ustat(list(H1, H2, H2, H3), list(1, c(1, 2), c(2, 3), 3))

## -----------------------------------------------------------------------------
# torch <- reticulate::import("torch")
# torch$cuda$is_available()

