[Rcpp-commits] r3678 - in pkg/RcppCNPy: . inst vignettes
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jul 7 16:46:39 CEST 2012
Author: edd
Date: 2012-07-07 16:46:39 +0200 (Sat, 07 Jul 2012)
New Revision: 3678
Added:
pkg/RcppCNPy/vignettes/
pkg/RcppCNPy/vignettes/RcppCNPy-intro.Rnw
pkg/RcppCNPy/vignettes/RcppCNPy-intro.pdf
Modified:
pkg/RcppCNPy/cleanup
pkg/RcppCNPy/inst/NEWS.Rd
Log:
o added a simple vignette describing the package
o cleanup also removes temporary latex files
Modified: pkg/RcppCNPy/cleanup
===================================================================
--- pkg/RcppCNPy/cleanup 2012-07-07 13:55:47 UTC (rev 3677)
+++ pkg/RcppCNPy/cleanup 2012-07-07 14:46:39 UTC (rev 3678)
@@ -2,5 +2,7 @@
rm -f src/*.o src/*.so
+rm -rf vignettes/auto/ vignettes/*.log vignettes/*.aux vignettes/*.out vignettes/*.tex
+
find . -name \*~ -exec rm {} \;
Modified: pkg/RcppCNPy/inst/NEWS.Rd
===================================================================
--- pkg/RcppCNPy/inst/NEWS.Rd 2012-07-07 13:55:47 UTC (rev 3677)
+++ pkg/RcppCNPy/inst/NEWS.Rd 2012-07-07 14:46:39 UTC (rev 3678)
@@ -10,7 +10,8 @@
type which is available only when the \code{-std=c++0x} switch is
used at build-time (and CRAN still discourages use of it)
\item Added support for reading gzip'ed files ending in ".npy.gz"
- \item Added (simple) regression tests in directory \code{tests/}
+ \item Added regression tests in directory \code{tests/}
+ \item Added a vignette describing the package}
}
}
\section{Changes in version 0.0.1 (2012-07-04)}{
Added: pkg/RcppCNPy/vignettes/RcppCNPy-intro.Rnw
===================================================================
--- pkg/RcppCNPy/vignettes/RcppCNPy-intro.Rnw (rev 0)
+++ pkg/RcppCNPy/vignettes/RcppCNPy-intro.Rnw 2012-07-07 14:46:39 UTC (rev 3678)
@@ -0,0 +1,397 @@
+\documentclass[10pt,twocolumn]{article}
+%\VignetteIndexEntry{RcppCNPy-intro}
+%\VignetteKeywords{Python, NumPy, R, data transfer}
+%\VignettePackage{RcppCNPy}
+
+%\usepackage[sf,bf,compact,small]{titlesec}
+\usepackage[sf,bf,compact,small]{titlesec}
+
+\usepackage[USletter]{vmargin}
+\setmargrb{0.75in}{0.75in}{0.75in}{0.75in}
+
+\usepackage{utopia} % not bad
+%\usepackage{newcent} % not bad
+%\usepackage{palatino} % not bad
+%\usepackage[bitstream-charter]{mathdesign}
+%\usepackage[T1]{fontenc}
+
+
+\usepackage{color,alltt,url}
+\usepackage[authoryear,round,longnamesfirst]{natbib}
+\usepackage[colorlinks]{hyperref}
+\definecolor{link}{rgb}{0,0,0.3} %% next few lines courtesy of RJournal.sty
+\hypersetup{
+ colorlinks,%
+ citecolor=link,%
+ filecolor=link,%
+ linkcolor=link,%
+ urlcolor=link
+}
+
+\usepackage{listings} % code examples
+\definecolor{darkgray}{rgb}{0.975,0.975,0.975}
+\lstset{backgroundcolor=\color{darkgray}}
+\lstset{numbers=left, numberstyle=\tiny, stepnumber=2, numbersep=5pt}
+\lstset{keywordstyle=\color{black}\bfseries\tt}
+\lstset{ %
+ %language=Octave, % the language of the code
+ %basicstyle=\footnotesize, % the size of the fonts that are used for the code
+ basicstyle=\small, % the size of the fonts that are used for the code
+ numbers=left, % where to put the line-numbers
+ %numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers
+ stepnumber=2, % the step between two line-numbers. If it's 1, each line
+ % will be numbered
+ numbersep=5pt, % how far the line-numbers are from the code
+ %backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
+ showspaces=false, % show spaces adding particular underscores
+ showstringspaces=false, % underline spaces within strings
+ showtabs=false, % show tabs within strings adding particular underscores
+ %frame=single, % adds a frame around the code
+ tabsize=2, % sets default tabsize to 2 spaces
+ captionpos=b, % sets the caption-position to bottom
+ breaklines=true, % sets automatic line breaking
+ breakatwhitespace=false % sets if automatic breaks should only happen at whitespace
+ %title=\lstname, % show the filename of files included with \lstinputlisting;
+ % also try caption instead of title
+ %escapeinside={\%*}{*)}, % if you want to add a comment within your code
+ %morekeywords={*,...} % if you want to add more keywords to the set
+}
+
+
+\newcommand{\proglang}[1]{\textsf{#1}}
+\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}}
+\newcommand{\code}[1]{\texttt{#1}}
+
+\newcommand{\R}{\proglang{R}\ } % NB forces a space so not good before % fullstop etc.
+\newcommand{\Rns}{\proglang{R}} % without the space
+\newcommand{\Cpp}{\proglang{C++}\ }
+\newcommand{\Python}{\proglang{Python}\ }
+
+\newcommand{\CRAN}[1]{\url{http://CRAN.R-Project.org/package=#1}}
+
+%% highlights macros
+%% Style definition file generated by highlight 2.7, http://www.andre-simon.de/
+% Highlighting theme definition:
+\newcommand{\hlstd}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\newcommand{\hlnum}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\newcommand{\hlesc}[1]{\textcolor[rgb]{0.74,0.55,0.55}{#1}}
+%\newcommand{\hlstr}[1]{\textcolor[rgb]{0.74,0.55,0.55}{#1}}
+\newcommand{\hlstr}[1]{\textcolor[rgb]{0.90,0.15,0.15}{#1}}
+%green: \newcommand{\hlstr}[1]{\textcolor[rgb]{0.13,0.67,0.13}{#1}} % 0.74 -> % 0.90; 0.55 -> 0.25
+\newcommand{\hldstr}[1]{\textcolor[rgb]{0.74,0.55,0.55}{#1}}
+\newcommand{\hlslc}[1]{\textcolor[rgb]{0.67,0.13,0.13}{\it{#1}}}
+\newcommand{\hlcom}[1]{\textcolor[rgb]{0.67,0.13,0.13}{\it{#1}}}
+\newcommand{\hldir}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\newcommand{\hlsym}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\newcommand{\hlline}[1]{\textcolor[rgb]{0.33,0.33,0.33}{#1}}
+\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.61,0.13,0.93}{\bf{#1}}}
+\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.13,0.54,0.13}{#1}}
+\newcommand{\hlkwc}[1]{\textcolor[rgb]{0,0,1}{#1}}
+\newcommand{\hlkwd}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\definecolor{bgcolor}{rgb}{1,1,1}
+
+
+<<echo=FALSE,print=FALSE>>=
+prettyVersion <- packageDescription("RcppCNPy")[["Version"]]
+prettyDate <- format(Sys.Date(), "%B %e, %Y")
+@
+
+\author{Dirk Eddelbuettel}
+\title{\pkg{RcppCNPy}: Reading and writing \pkg{NumPy} binary files}
+\date{\pkg{RcppCNPy} version \Sexpr{prettyVersion} as of \Sexpr{prettyDate}}
+
+\begin{document}
+\maketitle
+
+\abstract{
+ \noindent This document introduces the \pkg{RcppCNPy} package for reading
+ and writing files created by or for the \pkg{NumPy} module for
+ \proglang{Python}.
+
+ \pkg{RcppCNPy} is based on \pkg{cnpy}, a \proglang{C++}
+ library written by Carl Rogers.
+}
+
+\section{Motivation}
+
+\proglang{Python}\footnote{\url{http://www.python.org}} is a widely-used
+programming language. It is deployed for use cases ranging from simple
+scripting to larger-scale application development. \Python is also popular
+for quantitative and scientific application due to the existenve of extension
+modules such as \pkg{NumPy}\footnote{\url{http://numpy.scipy.org/}} (which is
+shorthand for Numeric Python).
+
+\pkg{NumPy} can be used for $N$-dimenional arrays, and provides an efficient
+binary storage model for these files. In practice, $N$ is often equal to
+two, and matrices processed or generated in \Python can be stored in this
+form.
+
+\R has (as of mid-2012) no dedicated reading or writing functionality for
+these files. However, Carl Rogers has provided a small \Cpp library called
+\pkg{cnpy}\footnote{\url{https://github.com/rogersce/cnpy}} which is released
+under the MIT license. Using the `Rcpp modules' feature in
+\pkg{Rcpp}\footnote{Eddelbuettel and Fran\c{c}cois, 2011, JSS, 40(8),
+ \url{http://www.jstatsoft.org/v40/i08/}}\footnote{\CRAN{Rcpp}}, we provide
+(some) features of this library to \Rns.
+
+\section{Examples}
+
+\subsection{Data creation in \Python}
+
+The first code example simply creates two files in \proglang{Python}: a
+two-dimensional rectangular array as well as a vector.
+
+% #!/usr/bin/python
+
+% import numpy as np
+
+% # simple float array
+% mat = np.arange(12).reshape(3,4) * 1.1
+% mat
+% np.save("fmat.npy", mat)
+
+% # simple float vector
+% np.save("fvec.npy", np.arange(5) * 1.1)
+
+
+% >>> import numpy as np
+% >>>
+% >>> mat = np.arange(12).reshape(3,4) * 1.1
+% >>> mat
+% array([[ 0. , 1.1, 2.2, 3.3],
+% [ 4.4, 5.5, 6.6, 7.7],
+% [ 8.8, 9.9, 11. , 12.1]])
+% >>> np.save("/tmp/fmat.npy", mat)
+% >>>
+% >>> vec = np.arange(5) * 1.1
+% >>> vec
+% array([ 0. , 1.1, 2.2, 3.3, 4.4])
+% >>> np.save("/tmp/fvec.npy", vec)
+% >>>
+
+%% highlight --enclose-pre --no-doc --syntax=Python --style=edit-emacs --out-format=latex
+%\begin{figure}[!h]
+\begin{quote}
+ \small
+
+ \noindent
+ \ttfamily
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hlstd{}\hlkwa{import\ }\hlstd{numpy\ }\hlkwa{as\ }\hlstd{np}\hspace*{\fill}\\
+ \hlopt{$>$$>$$>$\ }\hspace*{\fill}\\
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hlstd{mat\ }\hlopt{=\ }\hlstd{np}\hlopt{.}\hlstd{}\hlkwd{arange}\hlstd{}\hlopt{(}\hlstd{}\hlnum{12}\hlstd{}\hlopt{).}\hlstd{}\hlkwd{reshape}\hlstd{}\hlopt{(}\hlstd{}\hlnum{3}\hlstd{}\hlopt{,}\hlstd{}\hlnum{4}\hlstd{}\hlopt{)\ {*}\ }\hlstd{}\hlnum{1.1}\hspace*{\fill}\\
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hlstd{mat}\hspace*{\fill}\\
+ \hlkwd{array}\hlstd{}\hlopt{({[}{[}}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{0}\hlstd{}\hlopt{.\ ,}\hlstd{\ \ \ }\hlopt{}\hlstd{}\hlnum{1.1}\hlstd{}\hlopt{,}\hlstd{\ \ \ }\hlopt{}\hlstd{}\hlnum{2.2}\hlstd{}\hlopt{,}\hlstd{\ \ \ }\hlopt{}\hlstd{}\hlnum{3.3}\hlstd{}\hlopt{{]},}\hspace*{\fill}\\
+ \hlstd{}\hlstd{\ \ \ \ \ \ \ }\hlstd{}\hlopt{{[}}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{4.4}\hlstd{}\hlopt{,}\hlstd{\ \ \ }\hlopt{}\hlstd{}\hlnum{5.5}\hlstd{}\hlopt{,}\hlstd{\ \ \ }\hlopt{}\hlstd{}\hlnum{6.6}\hlstd{}\hlopt{,}\hlstd{\ \ \ }\hlopt{}\hlstd{}\hlnum{7.7}\hlstd{}\hlopt{{]},}\hspace*{\fill}\\
+ \hlstd{}\hlstd{\ \ \ \ \ \ \ }\hlstd{}\hlopt{{[}}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{8.8}\hlstd{}\hlopt{,}\hlstd{\ \ \ }\hlopt{}\hlstd{}\hlnum{9.9}\hlstd{}\hlopt{,}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{11}\hlstd{}\hlopt{.\ ,}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{12.1}\hlstd{}\hlopt{{]}{]})}\hspace*{\fill}\\
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hlstd{np}\hlopt{.}\hlstd{}\hlkwd{save}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"fmat.npy"}\hlstd{}\hlopt{,\ }\hlstd{mat}\hlopt{)}\hspace*{\fill}\\
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hspace*{\fill}\\
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hlstd{vec\ }\hlopt{=\ }\hlstd{np}\hlopt{.}\hlstd{}\hlkwd{arange}\hlstd{}\hlopt{(}\hlstd{}\hlnum{5}\hlstd{}\hlopt{)\ {*}\ }\hlstd{}\hlnum{1.1}\hspace*{\fill}\\
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hlstd{vec}\hspace*{\fill}\\
+ \hlkwd{array}\hlstd{}\hlopt{({[}\ }\hlstd{}\hlnum{0}\hlstd{}\hlopt{.\ ,}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{1.1}\hlstd{}\hlopt{,}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{2.2}\hlstd{}\hlopt{,}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{3.3}\hlstd{}\hlopt{,}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{4.4}\hlstd{}\hlopt{{]})}\hspace*{\fill}\\
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hlstd{np}\hlopt{.}\hlstd{}\hlkwd{save}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"fvec.npy"}\hlstd{}\hlopt{,\ }\hlstd{vec}\hlopt{)}\hspace*{\fill}\\
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hlstd{}\hspace*{\fill}\\
+ \mbox{}
+ \normalfont
+ \normalsize
+
+\end{quote}
+% \end{figure}
+
+As illustrated, \Python uses the \proglang{Fortran} convention for storing
+matrices and higher-dimensional arrays: a matrix constructed from a single
+sequence has its first consecutive elements in its first row---whereas \Rns,
+following the \proglang{C} convention, has these first few values in its first
+column. This shows that to go back and forth we need to tranpose these
+matrices (which represented internally as two-dimensional arrays).
+
+\subsection{Data reading in \R}
+
+We can read the same data in \R using the \code{npyLoad()} function provided
+by the \pkg{RcppCNPy} package:
+
+% R> library(RcppCNPy)
+% Loading required package: Rcpp
+% R>
+% R> mat <- npyLoad("fmat.npy")
+% R> mat
+% [,1] [,2] [,3] [,4]
+% [1,] 0.0 1.1 2.2 3.3
+% [2,] 4.4 5.5 6.6 7.7
+% [3,] 8.8 9.9 11.0 12.1
+% R>
+% R> vec <- npyLoad("fvec.npy")
+% R> vec
+% [1] 0.0 1.1 2.2 3.3 4.4
+% R>
+
+\begin{quote}
+ \small
+
+ \noindent
+ \ttfamily
+ \hlstd{R}\hlopt{$>$\ }\hlstd{}\hlkwd{library}\hlstd{}\hlopt{(}\hlstd{RcppCNPy}\hlopt{)}\hspace*{\fill}\\
+ \hlstd{Loading\ required\ package}\hlopt{:\ }\hlstd{Rcpp\hspace*{\fill}\\
+ R}\hlopt{$>$\ }\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hlstd{mat\ }\hlopt{$<${-}\ }\hlstd{}\hlkwd{npyLoad}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"fmat.npy"}\hlstd{}\hlopt{)}\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hlstd{mat\hspace*{\fill}\\
+ }\hlstd{\ \ \ \ \ }\hlstd{}\hlopt{{[},}\hlstd{}\hlnum{1}\hlstd{}\hlopt{{]}\ {[},}\hlstd{}\hlnum{2}\hlstd{}\hlopt{{]}\ {[},}\hlstd{}\hlnum{3}\hlstd{}\hlopt{{]}\ {[},}\hlstd{}\hlnum{4}\hlstd{}\hlopt{{]}}\hspace*{\fill}\\
+ \hlstd{}\hlopt{{[}}\hlstd{}\hlnum{1}\hlstd{}\hlopt{,{]}}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{0.0}\hlstd{\ \ }\hlnum{1.1}\hlstd{\ \ }\hlnum{2.2}\hlstd{\ \ }\hlnum{3.3}\hspace*{\fill}\\
+ \hlstd{}\hlopt{{[}}\hlstd{}\hlnum{2}\hlstd{}\hlopt{,{]}}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{4.4}\hlstd{\ \ }\hlnum{5.5}\hlstd{\ \ }\hlnum{6.6}\hlstd{\ \ }\hlnum{7.7}\hspace*{\fill}\\
+ \hlstd{}\hlopt{{[}}\hlstd{}\hlnum{3}\hlstd{}\hlopt{,{]}}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{8.8}\hlstd{\ \ }\hlnum{9.9\ 11.0\ 12.1}\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hlstd{vec\ }\hlopt{$<${-}\ }\hlstd{}\hlkwd{npyLoad}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"fvec.npy"}\hlstd{}\hlopt{)}\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hlstd{vec}\hspace*{\fill}\\
+ \hlopt{{[}}\hlstd{}\hlnum{1}\hlstd{}\hlopt{{]}\ }\hlstd{}\hlnum{0.0\ 1.1\ 2.2\ 3.3\ 4.4}\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hlstd{}\hspace*{\fill}\\
+ \mbox{}
+ \normalfont
+ \normalsize
+\end{quote}
+
+The \proglang{Fortran}-order of the matrix is preserved; we obtain the exact
+same data as we stored.
+
+\subsection{Reading compressed data in \R}
+
+A useful extension to the \pkg{cnpy} is the support of \pkg{gzip}-compressed
+data.
+
+% R> mat2 <- npyLoad("fmat.npy.gz")
+% R> mat2
+% [,1] [,2] [,3] [,4]
+% [1,] 0.0 1.1 2.2 3.3
+% [2,] 4.4 5.5 6.6 7.7
+% [3,] 8.8 9.9 11.0 12.1
+% R>
+
+\begin{quote}
+ \small
+
+ \noindent
+ \ttfamily
+ \hlstd{R}\hlopt{$>$\ }\hlstd{mat2\ }\hlopt{$<${-}\ }\hlstd{}\hlkwd{npyLoad}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"fmat.npy.gz"}\hlstd{}\hlopt{)}\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hlstd{mat2\hspace*{\fill}\\
+ }\hlstd{\ \ \ \ \ }\hlstd{}\hlopt{{[},}\hlstd{}\hlnum{1}\hlstd{}\hlopt{{]}\ {[},}\hlstd{}\hlnum{2}\hlstd{}\hlopt{{]}\ {[},}\hlstd{}\hlnum{3}\hlstd{}\hlopt{{]}\ {[},}\hlstd{}\hlnum{4}\hlstd{}\hlopt{{]}}\hspace*{\fill}\\
+ \hlstd{}\hlopt{{[}}\hlstd{}\hlnum{1}\hlstd{}\hlopt{,{]}}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{0.0}\hlstd{\ \ }\hlnum{1.1}\hlstd{\ \ }\hlnum{2.2}\hlstd{\ \ }\hlnum{3.3}\hspace*{\fill}\\
+ \hlstd{}\hlopt{{[}}\hlstd{}\hlnum{2}\hlstd{}\hlopt{,{]}}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{4.4}\hlstd{\ \ }\hlnum{5.5}\hlstd{\ \ }\hlnum{6.6}\hlstd{\ \ }\hlnum{7.7}\hspace*{\fill}\\
+ \hlstd{}\hlopt{{[}}\hlstd{}\hlnum{3}\hlstd{}\hlopt{,{]}}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{8.8}\hlstd{\ \ }\hlnum{9.9\ 11.0\ 12.1}\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hlstd{}\hspace*{\fill}\\
+ \mbox{}
+ \normalfont
+ \normalsize
+
+\end{quote}
+
+Support for compressed file is currently limited to reading, but could be
+implemented for writing as well.
+
+
+\subsection{Data writing in \R}
+
+Matrices and vectors can be written to files using the \code{npySave()}
+function.
+
+% R>
+% R> set.seed(42)
+% R> m <- matrix(sort(rnorm(6)), 3, 2)
+% R> m
+% [,1] [,2]
+% [1,] -0.564698 0.404268
+% [2,] -0.106125 0.632863
+% [3,] 0.363128 1.370958
+% R> npySave("randmat.npy", m)
+% R>
+% R> v <- seq(10, 12)
+% R> v
+% [1] 10 11 12
+% R> npySave("simplevec.npy", v)
+% R>
+% R>
+
+\begin{quote}
+ \small
+
+ \noindent
+ \ttfamily
+ \hlstd{R}\hlopt{$>$\ }\hlstd{set}\hlopt{.}\hlstd{}\hlkwd{seed}\hlstd{}\hlopt{(}\hlstd{}\hlnum{42}\hlstd{}\hlopt{)}\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hlstd{m\ }\hlopt{$<${-}\ }\hlstd{}\hlkwd{matrix}\hlstd{}\hlopt{(}\hlstd{}\hlkwd{sort}\hlstd{}\hlopt{(}\hlstd{}\hlkwd{rnorm}\hlstd{}\hlopt{(}\hlstd{}\hlnum{6}\hlstd{}\hlopt{)),\ }\hlstd{}\hlnum{3}\hlstd{}\hlopt{,\ }\hlstd{}\hlnum{2}\hlstd{}\hlopt{)}\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hlstd{m\hspace*{\fill}\\
+ }\hlstd{\ \ \ \ \ \ \ \ \ \ }\hlstd{}\hlopt{{[},}\hlstd{}\hlnum{1}\hlstd{}\hlopt{{]}}\hlstd{\ \ \ \ \ }\hlopt{{[},}\hlstd{}\hlnum{2}\hlstd{}\hlopt{{]}}\hspace*{\fill}\\
+ \hlstd{}\hlopt{{[}}\hlstd{}\hlnum{1}\hlstd{}\hlopt{,{]}\ {-}}\hlstd{}\hlnum{0.564698\ 0.404268}\hspace*{\fill}\\
+ \hlstd{}\hlopt{{[}}\hlstd{}\hlnum{2}\hlstd{}\hlopt{,{]}\ {-}}\hlstd{}\hlnum{0.106125\ 0.632863}\hspace*{\fill}\\
+ \hlstd{}\hlopt{{[}}\hlstd{}\hlnum{3}\hlstd{}\hlopt{,{]}}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{0.363128\ 1.370958}\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hlstd{}\hlkwd{npySave}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"randmat.npy"}\hlstd{}\hlopt{,\ }\hlstd{m}\hlopt{)}\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hlstd{v\ }\hlopt{$<${-}\ }\hlstd{}\hlkwd{seq}\hlstd{}\hlopt{(}\hlstd{}\hlnum{10}\hlstd{}\hlopt{,\ }\hlstd{}\hlnum{12}\hlstd{}\hlopt{)}\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hlstd{v}\hspace*{\fill}\\
+ \hlopt{{[}}\hlstd{}\hlnum{1}\hlstd{}\hlopt{{]}\ }\hlstd{}\hlnum{10\ 11\ 12}\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hlstd{}\hlkwd{npySave}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"simplevec.npy"}\hlstd{}\hlopt{,\ }\hlstd{v}\hlopt{)}\hspace*{\fill}\\
+ \hlstd{R}\hlopt{$>$\ }\hlstd{}\hspace*{\fill}\\
+ \mbox{}
+ \normalfont
+ \normalsize
+
+\end{quote}
+
+
+% >>> m = np.load("randmat.npy")
+% >>> m
+% array([[-0.56469817, 0.40426832],
+% [-0.10612452, 0.6328626 ],
+% [ 0.36312841, 1.37095845]])
+% >>>
+% >>> v = np.load("simpleve.npy")
+% >>> v
+% array([ 10., 11., 12.])
+% >>>
+% >>>
+
+\subsection{Data reading in \Python}
+
+\begin{quote}
+ \small
+
+ \noindent
+ \ttfamily
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hlstd{m\ }\hlopt{=\ }\hlstd{np}\hlopt{.}\hlstd{}\hlkwd{load}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"randmat.npy"}\hlstd{}\hlopt{)}\hspace*{\fill}\\
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hlstd{m}\hspace*{\fill}\\
+ \hlkwd{array}\hlstd{}\hlopt{({[}{[}{-}}\hlstd{}\hlnum{0.56469817}\hlstd{}\hlopt{,}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{0.40426832}\hlstd{}\hlopt{{]},}\hspace*{\fill}\\
+ \hlstd{}\hlstd{\ \ \ \ \ \ \ }\hlstd{}\hlopt{{[}{-}}\hlstd{}\hlnum{0.10612452}\hlstd{}\hlopt{,}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{0.6328626\ }\hlstd{}\hlopt{{]},}\hspace*{\fill}\\
+ \hlstd{}\hlstd{\ \ \ \ \ \ \ }\hlstd{}\hlopt{{[}\ }\hlstd{}\hlnum{0.36312841}\hlstd{}\hlopt{,}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{1.37095845}\hlstd{}\hlopt{{]}{]})}\hspace*{\fill}\\
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hspace*{\fill}\\
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hlstd{v\ }\hlopt{=\ }\hlstd{np}\hlopt{.}\hlstd{}\hlkwd{load}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"simpleve.npy"}\hlstd{}\hlopt{)}\hspace*{\fill}\\
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hlstd{v}\hspace*{\fill}\\
+ \hlkwd{array}\hlstd{}\hlopt{({[}\ }\hlstd{}\hlnum{10}\hlstd{}\hlopt{.,}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{11}\hlstd{}\hlopt{.,}\hlstd{\ \ }\hlopt{}\hlstd{}\hlnum{12}\hlstd{}\hlopt{.{]})}\hspace*{\fill}\\
+ \hlstd{}\hlopt{$>$$>$$>$\ }\hlstd{}\hspace*{\fill}\\
+ \mbox{}
+ \normalfont
+ \normalsize
+\end{quote}
+
+\section{Limitations}
+
+\subsection{Integer support}
+
+Support for integer data types is available, but conditional on use of the
+\code{-std=c++11} compiler extension. Only the newer standard supports the
+\code{long long int} type needed to represent \code{int64} data on a 32-bit
+OS. So until \R switches to allowing \code{-std=c++11} on CRAN packages,
+users will need to rebuild both \pkg{Rcpp} and \pkg{RcppCNPy} with the switch
+enabled.
+
+As shown in the previous examples, integers also transparently convert to
+float types.
+
+\subsection{Higher-dimensional arrays}
+
+\pkg{Rcpp} supports three-dimensional arrays, this could be support in
+\pkg{RcppCNPy} as well.
+
+\section{Summary}
+
+The \pkg{RcppCNPy} package provides simple reading and writing of \pkg{NumPy}
+files, using the \pkg{cnpy} library. Reading of compressed files is also
+supported as an extension.
+
+\end{document}
Added: pkg/RcppCNPy/vignettes/RcppCNPy-intro.pdf
===================================================================
(Binary files differ)
Property changes on: pkg/RcppCNPy/vignettes/RcppCNPy-intro.pdf
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
More information about the Rcpp-commits
mailing list