Skip to content

Commit f0c0251

Browse files
committed
add sparse tag to two sparse matrix entries
1 parent cfce3f2 commit f0c0251

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

_posts/2012-12-25-armadillo-sparse-matrix.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Sparse matrix in Armadillo
33
author: Dirk Eddelbuettel
44
license: GPL (>= 2)
5-
tags: armadillo matrix featured
5+
tags: armadillo matrix featured sparse
66
summary: This example shows how to create a sparse matrix in Armadillo
77
layout: post
88
src: 2012-12-25-armadillo-sparse-matrix.cpp

_posts/2013-01-20-sparse-matrix-coercion.md

+17-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Coercion of matrix to sparse matrix (dgCMatrix) and maintaining dimnames.
33
author: Søren Højsgaard
44
license: GPL (>= 2)
5-
tags: eigen matrix
5+
tags: eigen matrix sparse
66
summary: We illustrate 1) a fast way of coercing a dense matrix to a sparse matrix and 2) how to copy the dimnames from the dense to the sparse matrix.
77
layout: post
88
src: 2013-01-20-sparse-matrix-coercion.Rmd
@@ -59,12 +59,6 @@ Loading required package: methods
5959

6060

6161

62-
<pre class="output">
63-
Loading required package: lattice
64-
</pre>
65-
66-
67-
6862
{% highlight r %}
6963
M1 <- as(m, "dgCMatrix")
7064
M1
@@ -73,7 +67,7 @@ M1
7367

7468

7569
<pre class="output">
76-
6 x 6 sparse Matrix of class "dgCMatrix"
70+
6 x 6 sparse Matrix of class &quot;dgCMatrix&quot;
7771
a b c d e f
7872
a . . . . . 1
7973
b . . . 1 . 1
@@ -92,13 +86,13 @@ str(M1)
9286

9387

9488
<pre class="output">
95-
Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
89+
Formal class 'dgCMatrix' [package &quot;Matrix&quot;] with 6 slots
9690
..@ i : int [1:6] 4 4 1 5 0 1
9791
..@ p : int [1:7] 0 1 2 2 4 4 6
9892
..@ Dim : int [1:2] 6 6
9993
..@ Dimnames:List of 2
100-
.. ..$ : chr [1:6] "a" "b" "c" "d" ...
101-
.. ..$ : chr [1:6] "a" "b" "c" "d" ...
94+
.. ..$ : chr [1:6] &quot;a&quot; &quot;b&quot; &quot;c&quot; &quot;d&quot; ...
95+
.. ..$ : chr [1:6] &quot;a&quot; &quot;b&quot; &quot;c&quot; &quot;d&quot; ...
10296
..@ x : num [1:6] 1 1 1 1 1 1
10397
..@ factors : list()
10498
</pre>
@@ -139,7 +133,7 @@ SEXP asdgCMatrix_( SEXP XX_ ){
139133

140134

141135
<pre class="output">
142-
6 x 6 sparse Matrix of class "dgCMatrix"
136+
6 x 6 sparse Matrix of class &quot;dgCMatrix&quot;
143137
a b c d e f
144138
a . . . . . 1
145139
b . . . 1 . 1
@@ -158,13 +152,13 @@ str(M2)
158152

159153

160154
<pre class="output">
161-
Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
155+
Formal class 'dgCMatrix' [package &quot;Matrix&quot;] with 6 slots
162156
..@ i : int [1:6] 4 4 1 5 0 1
163157
..@ p : int [1:7] 0 1 2 2 4 4 6
164158
..@ Dim : int [1:2] 6 6
165159
..@ Dimnames:List of 2
166-
.. ..$ : chr [1:6] "a" "b" "c" "d" ...
167-
.. ..$ : chr [1:6] "a" "b" "c" "d" ...
160+
.. ..$ : chr [1:6] &quot;a&quot; &quot;b&quot; &quot;c&quot; &quot;d&quot; ...
161+
.. ..$ : chr [1:6] &quot;a&quot; &quot;b&quot; &quot;c&quot; &quot;d&quot; ...
168162
..@ x : num [1:6] 1 1 1 1 1 1
169163
..@ factors : list()
170164
</pre>
@@ -197,8 +191,8 @@ rbenchmark::benchmark(asdgCMatrix_(m * 1.0), as(m, "dgCMatrix"),
197191

198192
<pre class="output">
199193
test replications elapsed relative user.self sys.self
200-
1 asdgCMatrix_(m * 1) 1000 0.025 1.00 0.024 0.000
201-
2 as(m, "dgCMatrix") 1000 0.246 9.84 0.240 0.004
194+
1 asdgCMatrix_(m * 1) 1000 0.028 1.00 0.028 0.000
195+
2 as(m, &quot;dgCMatrix&quot;) 1000 0.287 10.25 0.284 0.004
202196
</pre>
203197

204198

@@ -218,8 +212,8 @@ rbenchmark::benchmark(asdgCMatrix_(m * 1.0), as(m, "dgCMatrix"),
218212

219213
<pre class="output">
220214
test replications elapsed relative user.self sys.self
221-
1 asdgCMatrix_(m * 1) 1000 0.137 1.000 0.136 0.000
222-
2 as(m, "dgCMatrix") 1000 0.443 3.234 0.432 0.008
215+
1 asdgCMatrix_(m * 1) 1000 0.133 1.000 0.132 0.000
216+
2 as(m, &quot;dgCMatrix&quot;) 1000 0.359 2.699 0.356 0.004
223217
</pre>
224218

225219

@@ -238,8 +232,8 @@ rbenchmark::benchmark(asdgCMatrix_(m * 1.0), as(m, "dgCMatrix"),
238232

239233
<pre class="output">
240234
test replications elapsed relative user.self sys.self
241-
1 asdgCMatrix_(m * 1) 100 1.193 1.000 1.180 0.008
242-
2 as(m, "dgCMatrix") 100 2.201 1.845 2.064 0.128
235+
1 asdgCMatrix_(m * 1) 100 1.193 1.00 1.184 0.004
236+
2 as(m, &quot;dgCMatrix&quot;) 100 2.303 1.93 2.092 0.204
243237
</pre>
244238

245239

@@ -258,8 +252,8 @@ rbenchmark::benchmark(asdgCMatrix_(m * 1.0), as(m, "dgCMatrix"),
258252

259253
<pre class="output">
260254
test replications elapsed relative user.self sys.self
261-
1 asdgCMatrix_(m * 1) 100 8.911 1.000 6.024 2.828
262-
2 as(m, "dgCMatrix") 100 21.557 2.419 16.930 4.500
255+
1 asdgCMatrix_(m * 1) 100 8.868 1.000 5.82 3.004
256+
2 as(m, &quot;dgCMatrix&quot;) 100 23.441 2.643 18.70 4.636
263257
</pre>
264258

265259

0 commit comments

Comments
 (0)