Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Determan authored and Determan committed Oct 16, 2017
0 parents commit 2eeda88
Show file tree
Hide file tree
Showing 13 changed files with 294 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
^.*\.Rproj$
^\.Rproj\.user$
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
src/*.o
src/*.so
src/*.dll
11 changes: 11 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Package: gpuRNN
Type: Package
Title: What the package does (short line)
Version: 1.0
Date: 2017-10-16
Author: Who wrote it
Maintainer: Who to complain to <[email protected]>
Description: More about what it does (maybe more than one line)
License: What license is it under?
Imports: Rcpp (>= 0.12.13), RcppEigen (>= 0.3.3.3.0)
LinkingTo: Rcpp, RcppEigen
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
useDynLib(gpuRNN)
import(RcppEigen)
importFrom(Rcpp, evalCpp)
exportPattern("^[[:alpha:]]+")
19 changes: 19 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

rcppeigen_hello_world <- function() {
.Call('_gpuRNN_rcppeigen_hello_world', PACKAGE = 'gpuRNN')
}

rcppeigen_outerproduct <- function(x) {
.Call('_gpuRNN_rcppeigen_outerproduct', PACKAGE = 'gpuRNN', x)
}

rcppeigen_innerproduct <- function(x) {
.Call('_gpuRNN_rcppeigen_innerproduct', PACKAGE = 'gpuRNN', x)
}

rcppeigen_bothproducts <- function(x) {
.Call('_gpuRNN_rcppeigen_bothproducts', PACKAGE = 'gpuRNN', x)
}

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# gpuRNN

Although there are many neural network implementations either directly
written in R, such as [nnet](https://CRAN.R-project.org/package=nnet) and
[neuralnet](https://CRAN.R-project.org/package=neuralnet), and linked to
other frameworks, such as [keras](https://CRAN.R-project.org/package=keras)
and [tensorflow](https://CRAN.R-project.org/package=tensorflow), there is
no package that readily allows much flexibility in developing new neural
network models without needing to go to other languages or interfaces.

This package is intended to provide R a neural network (or deep learning)
framework to allow R users a means to not only build and train networks but
to also allow users to more rapidly contribute novel methods and approaches
in the R language.

To make this package performant, it is based on the [gpuR](https://CRAN.R-project.org/package=gpuR) package to allow users
to leverage GPUs. However, it is my intent to not make this a strict
requirement.

18 changes: 18 additions & 0 deletions gpuRNN.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace,vignette
35 changes: 35 additions & 0 deletions man/gpuRNN-package.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
\name{gpuRNN-package}
\alias{gpuRNN-package}
\alias{gpuRNN}
\docType{package}
\title{
\packageTitle{gpuRNN}
}
\description{
\packageDescription{gpuRNN}
}
\details{

The DESCRIPTION file:
\packageDESCRIPTION{gpuRNN}
\packageIndices{gpuRNN}
~~ An overview of how to use the package, including the most important functions ~~
}
\author{
\packageAuthor{gpuRNN}

Maintainer: \packageMaintainer{gpuRNN}
}
\references{
~~ Literature or other references for background information ~~
}
~~ Optionally other standard keywords, one per line, from file KEYWORDS in the R ~~
~~ documentation directory ~~
\keyword{ package }
\seealso{
~~ Optional links to other man pages, e.g. ~~
~~ \code{\link[<pkg>:<pkg>-package]{<pkg>}} ~~
}
\examples{
~~ simple examples of the most important functions ~~
}
50 changes: 50 additions & 0 deletions man/rcppeigen_hello_world.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
\name{RcppEigen-Functions}
\alias{rcppeigen_hello_world}
\alias{rcppeigen_innerproduct}
\alias{rcppeigen_outerproduct}
\alias{rcppeigen_bothproducts}
\title{Set of functions in example RcppEigen package}
\description{
These four functions are created when
\code{RcppEigen.package.skeleton()} is invoked to create a
skeleton packages.
}
\usage{
rcppeigen_hello_world()
rcppeigen_outerproduct(x)
rcppeigen_innerproduct(x)
rcppeigen_bothproducts(x)
}
\arguments{
\item{x}{a numeric vector}
}
\value{
\code{rcppeigen_hello_world()} does not return a value, but displays a
message to the console.

\code{rcppeigen_outerproduct()} returns a numeric matrix computed as the
outer (vector) product of \code{x}.

\code{rcppeigen_innerproduct()} returns a double computer as the inner
(vector) product of \code{x}.

\code{rcppeigen_bothproducts()} returns a list with both the outer and
inner products.

}
\details{
These are example functions which should be largely
self-explanatory. Their main benefit is to demonstrate how to write a
function using the Eigen C++ classes, and to have to such a
function accessible from R.
}
\references{
See the documentation for Eigen, and RcppEigen, for more details.
}
\examples{
x <- sqrt(1:4)
rcppeigen_innerproduct(x)
rcppeigen_outerproduct(x)
}
\author{Dirk Eddelbuettel}

7 changes: 7 additions & 0 deletions src/Makevars
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## With Rcpp 0.11.0 and later, we no longer need to set PKG_LIBS as there is
## no user-facing library. The include path to headers is already set by R.
#PKG_LIBS =

## With R 3.1.0 or later, you can uncomment the following line to tell R to
## enable compilation with C++11 (or even C++14) where available
#CXX_STD = CXX11
7 changes: 7 additions & 0 deletions src/Makevars.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## With Rcpp 0.11.0 and later, we no longer need to set PKG_LIBS as there is
## no user-facing library. The include path to headers is already set by R.
#PKG_LIBS =

## With R 3.1.0 or later, you can uncomment the following line to tell R to
## enable compilation with C++11 (or even C++14) where available
#CXX_STD = CXX11
64 changes: 64 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#include <RcppEigen.h>
#include <Rcpp.h>

using namespace Rcpp;

// rcppeigen_hello_world
Eigen::MatrixXd rcppeigen_hello_world();
RcppExport SEXP _gpuRNN_rcppeigen_hello_world() {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = Rcpp::wrap(rcppeigen_hello_world());
return rcpp_result_gen;
END_RCPP
}
// rcppeigen_outerproduct
Eigen::MatrixXd rcppeigen_outerproduct(const Eigen::VectorXd& x);
RcppExport SEXP _gpuRNN_rcppeigen_outerproduct(SEXP xSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const Eigen::VectorXd& >::type x(xSEXP);
rcpp_result_gen = Rcpp::wrap(rcppeigen_outerproduct(x));
return rcpp_result_gen;
END_RCPP
}
// rcppeigen_innerproduct
double rcppeigen_innerproduct(const Eigen::VectorXd& x);
RcppExport SEXP _gpuRNN_rcppeigen_innerproduct(SEXP xSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const Eigen::VectorXd& >::type x(xSEXP);
rcpp_result_gen = Rcpp::wrap(rcppeigen_innerproduct(x));
return rcpp_result_gen;
END_RCPP
}
// rcppeigen_bothproducts
Rcpp::List rcppeigen_bothproducts(const Eigen::VectorXd& x);
RcppExport SEXP _gpuRNN_rcppeigen_bothproducts(SEXP xSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const Eigen::VectorXd& >::type x(xSEXP);
rcpp_result_gen = Rcpp::wrap(rcppeigen_bothproducts(x));
return rcpp_result_gen;
END_RCPP
}

static const R_CallMethodDef CallEntries[] = {
{"_gpuRNN_rcppeigen_hello_world", (DL_FUNC) &_gpuRNN_rcppeigen_hello_world, 0},
{"_gpuRNN_rcppeigen_outerproduct", (DL_FUNC) &_gpuRNN_rcppeigen_outerproduct, 1},
{"_gpuRNN_rcppeigen_innerproduct", (DL_FUNC) &_gpuRNN_rcppeigen_innerproduct, 1},
{"_gpuRNN_rcppeigen_bothproducts", (DL_FUNC) &_gpuRNN_rcppeigen_bothproducts, 1},
{NULL, NULL, 0}
};

RcppExport void R_init_gpuRNN(DllInfo *dll) {
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);
}
51 changes: 51 additions & 0 deletions src/rcppeigen_hello_world.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-

// we only include RcppEigen.h which pulls Rcpp.h in for us
#include <RcppEigen.h>

// via the depends attribute we tell Rcpp to create hooks for
// RcppEigen so that the build process will know what to do
//
// [[Rcpp::depends(RcppEigen)]]

// simple example of creating two matrices and
// returning the result of an operatioon on them
//
// via the exports attribute we tell Rcpp to make this function
// available from R
//
// [[Rcpp::export]]
Eigen::MatrixXd rcppeigen_hello_world() {
Eigen::MatrixXd m1 = Eigen::MatrixXd::Identity(3, 3);
Eigen::MatrixXd m2 = Eigen::MatrixXd::Random(3, 3);

return m1 + 3 * (m1 + m2);
}


// another simple example: outer product of a vector,
// returning a matrix
//
// [[Rcpp::export]]
Eigen::MatrixXd rcppeigen_outerproduct(const Eigen::VectorXd & x) {
Eigen::MatrixXd m = x * x.transpose();
return m;
}

// and the inner product returns a scalar
//
// [[Rcpp::export]]
double rcppeigen_innerproduct(const Eigen::VectorXd & x) {
double v = x.transpose() * x;
return v;
}

// and we can use Rcpp::List to return both at the same time
//
// [[Rcpp::export]]
Rcpp::List rcppeigen_bothproducts(const Eigen::VectorXd & x) {
Eigen::MatrixXd op = x * x.transpose();
double ip = x.transpose() * x;
return Rcpp::List::create(Rcpp::Named("outer")=op,
Rcpp::Named("inner")=ip);
}

0 comments on commit 2eeda88

Please sign in to comment.