Coder Social home page Coder Social logo

mtkerber / torch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mlverse/torch

0.0 0.0 0.0 57.66 MB

R Interface to Torch

Home Page: https://torch.mlverse.org

License: Other

R 26.89% C++ 69.52% C 0.01% Python 3.52% CMake 0.05% Shell 0.01% CSS 0.01%

torch's Introduction

torch

Lifecycle: experimental R build status CRAN status

Installation

torch can be installed from CRAN with:

install.packages("torch")

You can also install the development version with:

remotes::install_github("mlverse/torch")

At the first package load additional software will be installed.

Examples

You can create torch tensors from R objects with the torch_tensor function and convert them back to R objects with as_array.

library(torch)
x <- array(runif(8), dim = c(2, 2, 2))
y <- torch_tensor(x, dtype = torch_float64())
y
#> torch_tensor
#> (1,.,.) = 
#>   0.1512  0.8540
#>   0.3250  0.3191
#> 
#> (2,.,.) = 
#>   0.8256  0.1999
#>   0.1343  0.4721
#> [ CPUDoubleType{2,2,2} ]
identical(x, as_array(y))
#> [1] TRUE

Simple Autograd Example

In the following snippet we let torch, using the autograd feature, calculate the derivatives:

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
#> torch_tensor
#>  2
#> [ CPUFloatType{1} ]
w$grad
#> torch_tensor
#>  1
#> [ CPUFloatType{1} ]
b$grad
#> torch_tensor
#>  1
#> [ CPUFloatType{1} ]

Contributing

No matter your current skills it’s possible to contribute to torch development. See the contributing guide for more information.

torch's People

Contributors

ashudva avatar athospd avatar dfalbel avatar dirkschumacher avatar divinit7 avatar hbaniecki avatar javierluraschi avatar jwijffels avatar krzjoa avatar mattwarkentin avatar mtkerber avatar qykong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.