Commit e69e4317 authored by Roman Flury's avatar Roman Flury

spam2.2-1

parent b8a86ac9
Pipeline #1209 passed with stage
in 3 seconds
## General and platform dependent
SHELL := /bin/bash
LIBPATH = #export R_LIBS_USER=$(shell pwd)/lib:/usr/sepp1.5.1/drwho/pack-a/r-3.2.1-ro/amd64-linux-ubuntu14.04/lib/R/library:/home/furrer/R/x86_64-pc-linux-gnu-library/3.5 &&
#R := $(LIBPATH) R
#RSCRIPT := $(LIBPATH) Rscript
#LIBPATH = export R_LIBS_USER=$(shell pwd)/lib:/usr/sepp1.5.1/drwho/pack-a/r-devel-99-ro/amd64-linux-ubuntu14.04/lib/R/library:/home/furrer/R/x86_64-pc-linux-gnu-library/3.5:/usr/lib/R-devel/lib/R/library &&
R := $(LIBPATH) R ## On I-MATH servers: daily built devel version
RSCRIPT := $(LIBPATH) Rscript ## On I-MATH servers: daily built devel version
.SUFFIXES: .Rnw .R .Rout .tex .pdf .c .o .so .f
......@@ -81,7 +81,7 @@
<h1>Illustrations and Examples</h1>
<h4 class="author">Reinhard Furrer, Roman Flury</h4>
<h4 class="date">2018-10-11</h4>
<h4 class="date">2018-12-20</h4>
<div class="hidden name"><code>spam.Rmd</code></div>
......
......@@ -114,7 +114,7 @@
<div id="spam-2-2-1" class="section level1">
<h1 class="page-header">
<a href="#spam-2-2-1" class="anchor"></a>spam 2.2-1<small> Unreleased </small>
<a href="#spam-2-2-1" class="anchor"></a>spam 2.2-1<small> 2018-12-20 </small>
</h1>
<p>SIGNIFICANT USER-VISIBLE CHANGES</p>
<ul>
......@@ -128,7 +128,8 @@
</ul>
<p>INTERNAL CHANGES</p>
<ul>
<li>spam fit for pkgdown website.</li>
<li>Spam fit for pkgdown website.</li>
<li>Replacing some internal functions by their primitive equivalent.</li>
</ul>
</div>
<div id="spam-2-2-0" class="section level1">
......@@ -443,8 +444,7 @@
<p>INTERNAL CHANGES</p>
<ul>
<li>New much faster approach to extract rows. For not too sparse large matrices improvements over two orders of magnitudes are achieved.</li>
<li>Elininated ‘.Internal()’ calls that induce a ‘Note’ on CRAN checks. This also implied a minor rewrite of ‘image.spam’.<br>
</li>
<li>Elininated ‘.Internal()’ calls that induce a ‘Note’ on CRAN checks. This also implied a minor rewrite of ‘image.spam’.</li>
<li>Minor code improvements.</li>
<li>Eliminated non-API calls (29.1).</li>
<li>Rewritten .C(“bincode”,…) call as suggested by Brian Ripley (29.2).</li>
......@@ -469,8 +469,7 @@
<p>INTERNAL CHANGES</p>
<ul>
<li>Proper storage of data files.</li>
<li>Cleaning up argument names within spam functions.<br>
</li>
<li>Cleaning up argument names within spam functions.</li>
<li>Cleaning up old Fortran code, i.e., eliminating unnecessary subroutines and write calls.</li>
</ul>
<p>BUG FIXES</p>
......
......@@ -143,8 +143,7 @@ adjacency graph.<br /></p>
<h2 class="hasAnchor" id="source"><a class="anchor" href="#source"></a>Source</h2>
<p>The data is available from the package <span class="pkg">INLA</span>
distributed from <a href='www.r-inla.org'>www.r-inla.org</a> or from<br />
<a href='http://www.math.ntnu.no/~hrue/GMRF-book/oral.txt'>http://www.math.ntnu.no/~hrue/GMRF-book/oral.txt</a></p>
distributed from <a href='www.r-inla.org'>www.r-inla.org</a>.</p>
<h2 class="hasAnchor" id="references"><a class="anchor" href="#references"></a>References</h2>
......
......@@ -33,7 +33,7 @@
<meta property="og:title" content="Cholesky Factorization for Sparse Matrices — chol" />
<meta property="og:description" content="chol performs a Cholesky
decomposition of a symmetric positive definite sparse matrix x
decomposition of a symmetric positive definite sparse matrix x
of class spam." />
<meta name="twitter:card" content="summary" />
......@@ -121,7 +121,7 @@ of class spam." />
<div class="ref-description">
<p><code>chol</code> performs a Cholesky
decomposition of a symmetric positive definite sparse matrix <code>x</code>
decomposition of a symmetric positive definite sparse matrix <code>x</code>
of class <code>spam</code>.</p>
</div>
......@@ -212,7 +212,7 @@ structure can be obtained from a <code>summary</code> call, see &#8216;Examples&
<code>backsolve</code> to solve a system of linear equations.<br /></p>
<p>Notice that the Cholesky factorization of the package <code>SparseM</code> is also
based on the algorithm of Ng and Peyton (1993). Whereas the Cholesky
routine of the package <code>Matrix</code> are based on
routine of the package <code>Matrix</code> are based on
<code>CHOLMOD</code> by Timothy A. Davis (<code>C</code> code).</p>
<h2 class="hasAnchor" id="references"><a class="anchor" href="#references"></a>References</h2>
......@@ -242,7 +242,7 @@ tested for validity (defaults to <code>TRUE</code>).</p>
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
<div class='dont-index'><p><code><a href='det.html'>det.spam</a></code>, <code><a href='solve.html'>solve.spam</a></code>,
<div class='dont-index'><p><code><a href='det.html'>det.spam</a></code>, <code><a href='solve.html'>solve.spam</a></code>,
<code><a href='solve.html'>forwardsolve.spam</a></code>, <code><a href='solve.html'>backsolve.spam</a></code> and <code><a href='ordering.html'>ordering</a></code>.</p></div>
......@@ -261,7 +261,7 @@ tested for validity (defaults to <code>TRUE</code>).</p>
<span class='no'>R</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='spam.creation.html'>as.spam</a></span>(<span class='no'>cholS</span>)
<span class='no'>mvsample</span> <span class='kw'>&lt;-</span> ( <span class='fu'>array</span>(<span class='fu'>rnorm</span>(<span class='no'>N</span>*<span class='no'>n</span>),<span class='fu'>c</span>(<span class='no'>N</span>,<span class='no'>n</span>)) <span class='kw'>%*%</span> <span class='no'>R</span>)[,<span class='no'>iord</span>]
<span class='co'># It is often better to order the sample than the matrix</span>
<span class='co'># R itself. </span>
<span class='co'># R itself.</span>
<span class='co'># 'mvsample' is of class 'spam'. We need to transform it to a</span>
<span class='co'># regular matrix, as there is no method 'var' for 'spam' (should there?).</span>
......
......@@ -124,12 +124,12 @@
</div>
<pre class="usage"><span class='fu'>rmvnorm.const</span>(<span class='no'>n</span>, <span class='kw'>mu</span> <span class='kw'>=</span> <span class='fu'>rep</span>(<span class='fl'>0</span>, <span class='fu'>nrow</span>(<span class='no'>Sigma</span>)), <span class='no'>Sigma</span>, <span class='kw'>Rstruct</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>A</span> <span class='kw'>=</span> <span class='fu'>array</span>(<span class='fl'>1</span>, <span class='fu'>c</span>(<span class='fl'>1</span>,<span class='fu'>nrow</span>(<span class='no'>Sigma</span>))), <span class='kw'>a</span><span class='kw'>=</span><span class='fl'>0</span>, <span class='kw'>U</span><span class='kw'>=</span><span class='kw'>NULL</span>, <span class='no'>...</span>)
<span class='fu'>rmvnorm.prec.const</span>(<span class='no'>n</span>, <span class='kw'>mu</span> <span class='kw'>=</span> <span class='fu'>rep</span>(<span class='fl'>0</span>, <span class='fu'>nrow</span>(<span class='no'>Q</span>)), <span class='no'>Q</span>, <span class='kw'>Rstruct</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>A</span> <span class='kw'>=</span> <span class='fu'>array</span>(<span class='fl'>1</span>, <span class='fu'>c</span>(<span class='fl'>1</span>,<span class='fu'>nrow</span>(<span class='no'>Q</span>))), <span class='kw'>a</span><span class='kw'>=</span><span class='fl'>0</span>, <span class='kw'>U</span><span class='kw'>=</span><span class='kw'>NULL</span>, <span class='no'>...</span>)
<pre class="usage"><span class='fu'>rmvnorm.const</span>(<span class='no'>n</span>, <span class='kw'>mu</span> <span class='kw'>=</span> <span class='fu'>rep.int</span>(<span class='fl'>0</span>, <span class='fu'>dim</span>(<span class='no'>Sigma</span>)[<span class='fl'>1</span>]), <span class='no'>Sigma</span>, <span class='kw'>Rstruct</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>A</span> <span class='kw'>=</span> <span class='fu'>array</span>(<span class='fl'>1</span>, <span class='fu'>c</span>(<span class='fl'>1</span>,<span class='fu'>dim</span>(<span class='no'>Sigma</span>)[<span class='fl'>1</span>])), <span class='kw'>a</span><span class='kw'>=</span><span class='fl'>0</span>, <span class='kw'>U</span><span class='kw'>=</span><span class='kw'>NULL</span>, <span class='no'>...</span>)
<span class='fu'>rmvnorm.prec.const</span>(<span class='no'>n</span>, <span class='kw'>mu</span> <span class='kw'>=</span> <span class='fu'>rep.int</span>(<span class='fl'>0</span>, <span class='fu'>dim</span>(<span class='no'>Q</span>)[<span class='fl'>1</span>]), <span class='no'>Q</span>, <span class='kw'>Rstruct</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>A</span> <span class='kw'>=</span> <span class='fu'>array</span>(<span class='fl'>1</span>, <span class='fu'>c</span>(<span class='fl'>1</span>,<span class='fu'>dim</span>(<span class='no'>Q</span>)[<span class='fl'>1</span>])), <span class='kw'>a</span><span class='kw'>=</span><span class='fl'>0</span>, <span class='kw'>U</span><span class='kw'>=</span><span class='kw'>NULL</span>, <span class='no'>...</span>)
<span class='fu'>rmvnorm.canonical.const</span>(<span class='no'>n</span>, <span class='no'>b</span>, <span class='no'>Q</span>, <span class='kw'>Rstruct</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>A</span> <span class='kw'>=</span> <span class='fu'>array</span>(<span class='fl'>1</span>, <span class='fu'>c</span>(<span class='fl'>1</span>,<span class='fu'>nrow</span>(<span class='no'>Q</span>))), <span class='kw'>a</span><span class='kw'>=</span><span class='fl'>0</span>, <span class='kw'>U</span><span class='kw'>=</span><span class='kw'>NULL</span>, <span class='no'>...</span>)</pre>
<span class='kw'>A</span> <span class='kw'>=</span> <span class='fu'>array</span>(<span class='fl'>1</span>, <span class='fu'>c</span>(<span class='fl'>1</span>,<span class='fu'>dim</span>(<span class='no'>Q</span>)[<span class='fl'>1</span>])), <span class='kw'>a</span><span class='kw'>=</span><span class='fl'>0</span>, <span class='kw'>U</span><span class='kw'>=</span><span class='kw'>NULL</span>, <span class='no'>...</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
......@@ -179,7 +179,7 @@
<h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>
<p>The functions <code>rmvnorm.prec</code> and <code>rmvnorm.canonical</code>
do not requrie sparse precision matrices.
do not requrie sparse precision matrices.
For <code>rmvnorm.spam</code>, the differences between regular and sparse
covariance matrices are too significant to be implemented here. <br />
Often (e.g., in a Gibbs sampler setting), the sparsity structure of
......
......@@ -124,8 +124,8 @@
</div>
<pre class="usage"><span class='fu'>rmvnorm.spam</span>(<span class='no'>n</span>,<span class='kw'>mu</span><span class='kw'>=</span><span class='fu'>rep</span>(<span class='fl'>0</span>, <span class='fu'>nrow</span>(<span class='no'>Sigma</span>)), <span class='no'>Sigma</span>, <span class='kw'>Rstruct</span><span class='kw'>=</span><span class='kw'>NULL</span>, <span class='no'>...</span>)
<span class='fu'>rmvnorm.prec</span>(<span class='no'>n</span>,<span class='kw'>mu</span><span class='kw'>=</span><span class='fu'>rep</span>(<span class='fl'>0</span>, <span class='fu'>nrow</span>(<span class='no'>Q</span>)), <span class='no'>Q</span>, <span class='kw'>Rstruct</span><span class='kw'>=</span><span class='kw'>NULL</span>, <span class='no'>...</span>)
<pre class="usage"><span class='fu'>rmvnorm.spam</span>(<span class='no'>n</span>,<span class='kw'>mu</span><span class='kw'>=</span><span class='fu'>rep.int</span>(<span class='fl'>0</span>, <span class='fu'>dim</span>(<span class='no'>Sigma</span>)[<span class='fl'>1</span>]), <span class='no'>Sigma</span>, <span class='kw'>Rstruct</span><span class='kw'>=</span><span class='kw'>NULL</span>, <span class='no'>...</span>)
<span class='fu'>rmvnorm.prec</span>(<span class='no'>n</span>,<span class='kw'>mu</span><span class='kw'>=</span><span class='fu'>rep.int</span>(<span class='fl'>0</span>, <span class='fu'>dim</span>(<span class='no'>Q</span>)[<span class='fl'>1</span>]), <span class='no'>Q</span>, <span class='kw'>Rstruct</span><span class='kw'>=</span><span class='kw'>NULL</span>, <span class='no'>...</span>)
<span class='fu'>rmvnorm.canonical</span>(<span class='no'>n</span>, <span class='no'>b</span>, <span class='no'>Q</span>, <span class='kw'>Rstruct</span><span class='kw'>=</span><span class='kw'>NULL</span>, <span class='no'>...</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
......@@ -164,7 +164,7 @@
<h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>
<p>The functions <code>rmvnorm.prec</code> and <code>rmvnorm.canonical</code>
do not require sparse precision matrices.
do not require sparse precision matrices.
For <code>rmvnorm.spam</code>, the differences between regular and sparse
covariance matrices are too significant to be implemented here. <br />
Often (e.g., in a Gibbs sampler setting), the sparsity structure of
......@@ -192,14 +192,14 @@
<span class='no'>Sigmainv</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='spam.creation.html'>as.spam</a></span>( <span class='no'>Sigmainv</span>, <span class='kw'>eps</span><span class='kw'>=</span><span class='fl'>1e-4</span>)
<span class='no'>Sigma</span> <span class='kw'>&lt;-</span> <span class='fu'>solve</span>( <span class='no'>Sigmainv</span>) <span class='co'># for verification </span>
<span class='no'>Sigma</span> <span class='kw'>&lt;-</span> <span class='fu'>solve</span>( <span class='no'>Sigmainv</span>) <span class='co'># for verification</span>
<span class='no'>iidsample</span> <span class='kw'>&lt;-</span> <span class='fu'>array</span>(<span class='fu'>rnorm</span>(<span class='no'>N</span>*<span class='no'>n</span>),<span class='fu'>c</span>(<span class='no'>n</span>,<span class='no'>N</span>))
<span class='no'>mvsample</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='solve.html'>backsolve</a></span>( <span class='fu'>chol</span>(<span class='no'>Sigmainv</span>), <span class='no'>iidsample</span>)
<span class='fu'><a href='operations.html'>norm</a></span>( <span class='fu'>var</span>(<span class='fu'>t</span>(<span class='no'>mvsample</span>)) - <span class='no'>Sigma</span>, <span class='kw'>type</span><span class='kw'>=</span><span class='st'>"m"</span>)</div><div class='output co'>#&gt; [1] 0.1326448</div><div class='input'>
<span class='co'># compare with:</span>
<span class='no'>mvsample</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='solve.html'>backsolve</a></span>( <span class='fu'>chol</span>(<span class='fu'>as.matrix</span>( <span class='no'>Sigmainv</span>)), <span class='no'>iidsample</span>, <span class='no'>n</span>)
<span class='co'>#### ,n as patch </span>
<span class='co'>#### ,n as patch</span>
<span class='fu'><a href='operations.html'>norm</a></span>( <span class='fu'>var</span>(<span class='fu'>t</span>(<span class='no'>mvsample</span>)) - <span class='no'>Sigma</span>, <span class='kw'>type</span><span class='kw'>=</span><span class='st'>"m"</span>)</div><div class='output co'>#&gt; [1] 0.1326447</div><div class='input'>
......
......@@ -212,7 +212,7 @@ is.spam(x)</pre>
<span class='no'>is</span> <span class='kw'>&lt;-</span> <span class='fu'>sample</span>(<span class='no'>ln</span>,<span class='no'>nz</span>)
<span class='no'>js</span> <span class='kw'>&lt;-</span> <span class='fu'>sample</span>(<span class='no'>ln</span>,<span class='no'>nz</span>)
<span class='fu'>system.time</span>(<span class='kw'>for</span> (<span class='no'>i</span> <span class='kw'>in</span> <span class='fl'>1</span>:<span class='no'>nz</span>) <span class='no'>smat</span>[<span class='no'>is</span>[<span class='no'>i</span>], <span class='no'>js</span>[<span class='no'>i</span>]] <span class='kw'>&lt;-</span> <span class='no'>i</span>)</div><div class='output co'>#&gt; user system elapsed
#&gt; 0.088 0.000 0.089 </div><div class='input'><span class='fu'>system.time</span>(<span class='no'>smat</span>[<span class='fu'><a href='xybind.html'>cbind</a></span>(<span class='no'>is</span>,<span class='no'>js</span>)] <span class='kw'>&lt;-</span> <span class='fl'>1</span>:<span class='no'>nz</span>)</div><div class='output co'>#&gt; user system elapsed
#&gt; 0.108 0.000 0.121 </div><div class='input'><span class='fu'>system.time</span>(<span class='no'>smat</span>[<span class='fu'><a href='xybind.html'>cbind</a></span>(<span class='no'>is</span>,<span class='no'>js</span>)] <span class='kw'>&lt;-</span> <span class='fl'>1</span>:<span class='no'>nz</span>)</div><div class='output co'>#&gt; user system elapsed
#&gt; 0.004 0.000 0.001 </div><div class='input'>
<span class='fu'>getClass</span>(<span class='st'>"spam"</span>)</div><div class='output co'>#&gt; Class "spam" [package "spam"]
#&gt;
......
......@@ -160,7 +160,7 @@ spam.Version() provides detailed information about the version of spam
<h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
<pre class="examples"><div class='input'><span class='no'>spam.version</span>$<span class='no'>version.string</span></div><div class='output co'>#&gt; [1] "Spam version 2.2-1 (2018-10-11)"</div></pre>
<pre class="examples"><div class='input'><span class='no'>spam.version</span>$<span class='no'>version.string</span></div><div class='output co'>#&gt; [1] "Spam version 2.2-1 (2018-12-20)"</div></pre>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<h2>Contents</h2>
......
No preview for this file type
......@@ -2,7 +2,7 @@ Package: spam
Type: Package
Title: SPArse Matrix
Version: 2.2-1
Date: 2018-10-11
Date: 2018-12-20
Authors@R: c(person("Reinhard", "Furrer", role = c("aut", "cre"),
email = "reinhard.furrer@math.uzh.ch"),
person("Florian", "Gerber", role = c("ctb"),
......
......@@ -2,14 +2,12 @@
# can be used for spam-devel and spam
include ../Makefile.defs
all: pkgdown
pkgdown:
$(RSCRIPT) -e "pkgdown::build_site()"
Rscript -e "pkgdown::build_site()"
clean:
rm -rf docs/
rm -rf docs/
......@@ -11,7 +11,8 @@ BUG FIXES
INTERNAL CHANGES
* spam fit for pkgdown website.
* Spam fit for pkgdown website.
* Replacing some internal functions by their primitive equivalent.
# spam 2.2-0
......@@ -74,7 +75,7 @@ INTERNAL CHANGES
INTERNAL CHANGES
* Fortran modification to address more pedantic compilations.
* Fortran modification to address more pedantic compilations.
# spam 1.3-0
......@@ -170,7 +171,7 @@ NEW FEATURES
* Few new S3 functions for simplicity: 'var.spam', 'eigen.spam', ...
* New constructor functions 'colindices<-' etc.
Maybe additional tests may be required.
* Operators from 'Arith' obey now the structure based calculation.
* Operators from 'Arith' obey now the structure based calculation.
BUG FIXES
......@@ -289,7 +290,7 @@ INTERNAL CHANGES
SIGNIFICANT USER-VISIBLE CHANGES
* There is a generic conflict with 'backsolve' between spam and other packages (e.g., bdsmatrix).
To avoid the issue, we use the standard generic implemented in 'methods' which requires an additional argument for version 0.29-0 (see also PR#14883).
To avoid the issue, we use the standard generic implemented in 'methods' which requires an additional argument for version 0.29-0 (see also PR#14883).
However to maintain backwards compatibility with packages that depend on spam, this was reverted in 0.29-1.
Currently, this conflict is not properly solved.
I propose to load 'spam' first then the other packages, followed by manually calling:
......@@ -328,8 +329,8 @@ NEW FEATURES
INTERNAL CHANGES
* New much faster approach to extract rows. For not too sparse large matrices improvements over two orders of magnitudes are achieved.
* Elininated '.Internal()' calls that induce a 'Note' on CRAN checks. This also implied a minor rewrite of 'image.spam'.
* Minor code improvements.
* Elininated '.Internal()' calls that induce a 'Note' on CRAN checks. This also implied a minor rewrite of 'image.spam'.
* Minor code improvements.
* Eliminated non-API calls (29.1).
* Rewritten .C("bincode",...) call as suggested by Brian Ripley (29.2).
......@@ -351,7 +352,7 @@ NEW FEATURES
INTERNAL CHANGES
* Proper storage of data files.
* Cleaning up argument names within spam functions.
* Cleaning up argument names within spam functions.
* Cleaning up old Fortran code, i.e., eliminating unnecessary subroutines and write calls.
BUG FIXES
......@@ -369,7 +370,7 @@ NEW FEATURES
* Improvements in the mle.* functions.
* Method diff for sparse matrices (suggested by Paul Eilers).
* Improvement of help pages.
* Eliminated some help aliases to base functions (for which no 'usage' is given).
* Eliminated some help aliases to base functions (for which no 'usage' is given).
INTERNAL CHANGES
......
......@@ -14,14 +14,14 @@
"dim<-.spam" <- function(x, value) {
if (is.spam(x)) {
dimx <- x@dimension
pdim <- prod(dimx)
vlen <- prod(value)
if( !identical(pdim,vlen))
stop( sprintf("dims [product %d] do not match the length of object [%d]. Do you want `pad`",
pdim,vlen))
if (length(value)>2)
stop("dims should be of length 1 or 2")
if (identical(length(value),1L))
......@@ -29,18 +29,18 @@
if(any(dimx<1))
stop("the dims contain negative values")
tmp <- cbind(st=rep(1:dim(x)[1],diff(x@rowpointers)), nd=x@colindices)
ind <- tmp[,1]+(tmp[,2]-1)*dimx[1] - 1
slist <- list(i = ind%%value[1] +1,
j = ind%/%value[1] +1,
x@entries)
return( spam.list( slist, nrow=value[1], ncol=value[2],
eps = .Machine$double.eps))
} else {
dim(x) <- value
x
......@@ -60,10 +60,10 @@
stop("dims should be postive integers.")
if (!identical( length(value), 2L))
stop("dims should be of length 2.")
dimx <- x@dimension
last <- value[1]+1
# In three steps:
# 1) Address col truncation
# to safe time, we also take into account if we have fewer or equal rows
......@@ -71,7 +71,7 @@
# 3) if fewer rows and more columns, truncate
# In any case, dimensions are fixed at the end.
# If fewer cols required, we run reducedim
if (dimx[2]>value[2]){
......@@ -81,7 +81,7 @@
SS <- .format64()
else
SS <- .format32
z <- .C64("reducedim",
SIGNATURE=c("double", SS$signature, SS$signature,
"double", SS$signature, SS$signature, SS$signature,
......@@ -89,29 +89,29 @@
oldra = x@entries,
oldja = x@colindices,
oldia = x@rowpointers,
eps = getOption("spam.eps"),
min(value[1],dimx[1]),
value[2],
nz = 1,
entries=vector_dc("double",length(x@entries)),
colindices=vector_dc(SS$type,length(x@entries)),
rowpointers=vector_dc(SS$type,last),
INTENT=c("r", "r", "r",
"r", "r", "r", "w",
INTENT=c("r", "r", "r",
"r", "r", "r", "w",
"w", "w", "w"),
NAOK = getOption("spam.NAOK"),
PACKAGE = SS$package)
if (z$nz==1 ){ #was identical( z$nz,1L)
## print("2")
return(
.newSpam(
# entries=x@entries,
# colindices=x@colindices,
# rowpointers=c(1,rep_len64(2,value[1])),
# rowpointers=c(1,rep_len64(2,value[1])),
dimension=value,
force64=force64
)
......@@ -121,7 +121,7 @@
x <- .newSpam(
entries=z$entries[1:nz],
colindices=z$colindices[1:nz],
rowpointers=z$rowpointers[1:min(last,dimx[1]+1)],
rowpointers=z$rowpointers[1:min(last,dimx[1]+1)],
dimension=value, #actually here dim 2 = value 2 but dim1 maybe not yet
force64=force64
)
......@@ -140,7 +140,7 @@
}
# special case: fewer rows and more columns, truncate
if((dimx[1]>=value[1])&(dimx[2]<=value[2])) { ## added =, think about it again
if((dimx[1]>=value[1])&(dimx[2]<=value[2])) { ## added =, think about it again
## print("4")
lastelement <- (x@rowpointers[last]-1)
......@@ -168,8 +168,8 @@ setMethod("pad<-", "matrix",
function(x, value) {
if (!identical( length(value), 2L)) stop("dims should be of length 2.")
tmp <- matrix(0, value)
mr <- 1:min(value[1], nrow(x))
mc <- 1:min(value[2], ncol(x))
mr <- 1:min(value[1], dim(x)[1])
mc <- 1:min(value[2], dim(x)[2])
tmp[mr,mc] <- x[mr,mc]
return(tmp)
})
......@@ -9,7 +9,7 @@
# Kaspar Moesinger [ctb] #
# HEADER END ################################################
# `"Ops"":
# `"+"", `"-"", `"*"", `"/"", `"^"", `"%%"", `"%/%""
......@@ -40,13 +40,13 @@ setMethod("!",signature(x="spam"), function(x){
x
} else {
inefficiencywarning( gettextf("This %s operation may be inefficient",sQuote(.Generic)), prod(dim(x)))
spam(as.double( callGeneric(as.matrix(x))), nrow=nrow(x))
spam(as.double( callGeneric(as.matrix(x))), nrow=dim(x)[1])
}
})
setMethod("+",signature(e1="spam",e2="missing"), function(e1) e1 )
setMethod("-",signature(e1="spam",e2="missing"), function(e1) { e1@entries <- -e1@entries; e1} )
setMethod("+",signature(e1="spam",e2="missing"), function(e1) e1 )
setMethod("-",signature(e1="spam",e2="missing"), function(e1) { e1@entries <- -e1@entries; e1} )
# `Math2" :
setMethod("Math2",signature(x = "spam", digits = "ANY"),
......@@ -60,7 +60,7 @@ setMethod("Math","spam", function(x){
x
}else{
x@entries <- callGeneric(x@entries)
as.spam.spam( x)
as.spam.spam( x)
}
})
......@@ -80,7 +80,7 @@ setMethod("exp","spam", spam_Math )
setMethod("log10","spam", spam_Math )
setMethod("log2","spam", spam_Math )
# from ?log: Do not set S4 methods on `logb" itself.
# special case to set base...
# special case to set base...
setMethod("log","spam", function(x,...) {
if(getOption("spam.structurebased")) {
x@entries <- callGeneric(x@entries,...)
......@@ -92,7 +92,7 @@ setMethod("log","spam", function(x,...) {
)
setMethod("cos","spam", spam_Math )
#setMethod("cospi","spam", spam_Math )
setMethod("cosh","spam", spam_Math )
......@@ -113,29 +113,29 @@ setMethod("cumsum","spam", spam_Math )
# `Summary" :
setMethod("Summary","spam", function(x,...,na.rm=FALSE){
if(getOption("spam.structurebased")) {
callGeneric(x@entries,...,na.rm=na.rm)
callGeneric(x@entries,...,na.rm=na.rm)
}else{
if ( prod( x@dimension) == length( x@entries)) {
callGeneric(x@entries,...,na.rm=na.rm)
callGeneric(x@entries,...,na.rm=na.rm)
} else {
callGeneric(c(0,x@entries),...,na.rm=na.rm)
}
}
}
)
)
logical_Summary <- function( x,...,na.rm=FALSE){
if(getOption("spam.structurebased")) {
callGeneric(as.logical(x@entries),...,na.rm=na.rm)
callGeneric(as.logical(x@entries),...,na.rm=na.rm)
}else{
if ( prod( x@dimension) == length( x@entries)) {
callGeneric(as.logical(x@entries),...,na.rm=na.rm)
callGeneric(as.logical(x@entries),...,na.rm=na.rm)
} else {
callGeneric(as.logical(c(0,x@entries)),...,na.rm=na.rm)
}
}
}
setMethod("any","spam", logical_Summary)
setMethod("all","spam", logical_Summary)
......@@ -147,8 +147,8 @@ setMethod("all","spam", logical_Summary)
# `Logic" `"&"", `"|"".
"spam_Logic_vectorspam" <- function(e1, e2) {
if(getOption("spam.structurebased")) {
if(identical(length(e1),1L) | identical(length(e1), length(e2@entries))) {
......@@ -178,21 +178,21 @@ setMethod("all","spam", logical_Summary)
return( as.spam( callGeneric(as.matrix(e1), e2)) )
}
}
setMethod("|",signature(e1="spam",e2="spam"),
setMethod("|",signature(e1="spam",e2="spam"),
function(e1,e2){ z <- spam_add(e1,e2);z@entries <- rep(1,length(z@colindices));z})
setMethod("&",signature(e1="spam",e2="spam"),
setMethod("&",signature(e1="spam",e2="spam"),
function(e1,e2){ z <- spam_mult(e1,e2); z@entries <- rep(1,length(z@colindices));z})
setMethod("Logic",signature(e1="spam",e2="vector"), spam_Logic_spamvector)
setMethod("Logic",signature(e1="vector",e2="spam"), spam_Logic_vectorspam)
##################################################################################################
# `Compare" `"=="", `">"", `"<"", `"!="", `"<="", `">=""
# `Compare" `"=="", `">"", `"<"", `"!="", `"<="", `">=""
"spam_Compare" <- function(e1,e2) {
inefficiencywarning( gettextf("This %s operation may be inefficient",sQuote(.Generic)), max(prod(dim(e1)), prod(dim(e2))))
as.spam( callGeneric( as.matrix(e1), as.matrix(e2)) )
as.spam( callGeneric( as.matrix(e1), as.matrix(e2)) )
}
"spam_Compare_spamvector" <- function(e1, e2){
......@@ -231,7 +231,7 @@ setMethod("Compare",signature(e1="vector",e2="spam"), spam_Compare_vectorspam )
##################################################################################################
# `Arith": `"+"", `"-"", `"*"", `"^"", `"%%"", `"%/%"", `"/""
"spam_Arith_vectorspam" <- function(e1, e2){
"spam_Arith_vectorspam" <- function(e1, e2){
# cat("spam_Arith_vectorspam")
if(getOption("spam.structurebased")) {
if(identical(length(e1),1L) | identical(length(e1), length(e2@entries))) {
......@@ -265,8 +265,8 @@ spam_Arith <- function(e1,e2) {
inefficiencywarning( gettextf("This %s operation may be inefficient",sQuote(.Generic)), max(prod(dim(e1)), prod(dim(e2))))
as.spam( callGeneric( as.matrix(e1), as.matrix(e2)))
}
setMethod("Arith",signature(e1="spam",e2="spam"), spam_Arith )
setMethod("Arith",signature(e1="spam",e2="vector"), spam_Arith_spamvector)
......@@ -285,7 +285,7 @@ setMethod("^",signature(e1="spam",e2="spam"), function(e1,e2){ "^"(e1,as.matrix(
#######################################################################
"spam_add" <- function(A, B, s=1)
{
# cat("spam_add")
nrow <- A@dimension[1]
ncol <- A@dimension[2]
......@@ -298,19 +298,19 @@ setMethod("^",signature(e1="spam",e2="spam"), function(e1,e2){ "^"(e1,as.matrix(
SS <- .format32
nzmax <- .C64("aplbdg",
## subroutine aplbdg (nrow,ncol,ja,ia,jb,ib,ndegr,nnz,iw)
## subroutine aplbdg (nrow,ncol,ja,ia,jb,ib,ndegr,nnz,iw)
SIGNATURE = c(SS$signature, SS$signature,
SS$signature, SS$signature, SS$signature, SS$signature,
SS$signature, SS$signature, SS$signature),
nrow,
ncol,
A@colindices,
A@rowpointers,
B@colindices,
B@rowpointers,
vector_dc(SS$type, nrow),
nnz = vector_dc(SS$type, 1),
vector_dc(SS$type, ncol),
......@@ -329,24 +329,24 @@ setMethod("^",signature(e1="spam",e2="spam"), function(e1,e2){ "^"(e1,as.matrix(
"double", SS$signature, SS$signature,
"double", SS$signature, SS$signature,
SS$signature, SS$signature),
nrow,
ncol,
A@entries,
A@colindices,
A@rowpointers,
s,
B@entries,
B@colindices,
B@rowpointers,
entries = vector_dc("double", nzmax),
colindices = vector_dc(SS$type, nzmax),
rowpointers = vector_dc(SS$type, nrow+1),
nzmax+1,
ierr = vector_dc(SS$type, 1),
......@@ -409,7 +409,7 @@ setMethod("-",signature(e1="spam",e2="spam"), function(e1,e2){ spam_add(e1, e2,
# e2 <- as.spam(e2)
# if(!(is.spam(e1) && is.spam(e2)))
# stop("Arguments must be of class: vector, matrix or spam")
e1row <- e1@dimension[1]
e1col <- e1@dimension[2]
if(e1col != e2@dimension[2] | e1row != e2@dimension[1])
......@@ -430,18 +430,18 @@ setMethod("-",signature(e1="spam",e2="spam"), function(e1,e2){ spam_add(e1, e2,
"double", SS$signature, SS$signature,
"double", SS$signature, SS$signature,
SS$signature, SS$signature),
e1row,
e1col,
e1@entries, e1@colindices, e1@rowpointers,