-
Notifications
You must be signed in to change notification settings - Fork 68
/
README.Rmd
73 lines (54 loc) · 2.11 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
torch::torch_manual_seed(1)
```
# torch <a href='https://torch.mlverse.org'><img src='man/figures/torch.png' align="right" height="139" /></a>
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![Test](https://github.com/mlverse/torch/actions/workflows/main.yaml/badge.svg)](https://github.com/mlverse/torch/actions/workflows/main.yaml)
[![CRAN status](https://www.r-pkg.org/badges/version/torch)](https://CRAN.R-project.org/package=torch)
[![](https://cranlogs.r-pkg.org/badges/torch)](https://cran.r-project.org/package=torch)
[![Discord](https://img.shields.io/discord/837019024499277855?logo=discord)](https://discord.com/invite/s3D5cKhBkx)
## Installation
torch can be installed from CRAN with:
```r
install.packages("torch")
```
You can also install the development version with:
```r
remotes::install_github("mlverse/torch")
```
At the first package load additional software will be
installed. See also the full [installation guide](https://torch.mlverse.org/docs/articles/installation.html) here.
## Examples
You can create torch tensors from R objects with the `torch_tensor` function and convert them back to R objects with `as_array`.
```{r}
library(torch)
x <- array(runif(8), dim = c(2, 2, 2))
y <- torch_tensor(x, dtype = torch_float64())
y
identical(x, as_array(y))
```
### Simple Autograd Example
In the following snippet we let torch, using the autograd feature, calculate the derivatives:
```{r}
x <- torch_tensor(1, requires_grad = TRUE)
w <- torch_tensor(2, requires_grad = TRUE)
b <- torch_tensor(3, requires_grad = TRUE)
y <- w * x + b
y$backward()
x$grad
w$grad
b$grad
```
## Contributing
No matter your current skills it's possible to contribute to `torch` development.
See the [contributing guide](https://torch.mlverse.org/docs/contributing) for more information.