Skip to content

Commit 3ddbcdf

Browse files
committedApr 18, 2018
actually use arma 8.500-rc2
1 parent 9c24cea commit 3ddbcdf

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed
 

‎_posts/2018-04-18-armadillo-sparse-matrix-performance.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ src: 2018-04-18-armadillo-sparse-matrix-performance.Rmd
1313

1414

1515

16-
The Armadillo library provides a great way to manipulate sparse matrices in C++. However, the
17-
performance characteristics of dealing with sparse matrices may be surprising if one is only
18-
familiar with dense matrices. This is a collection of observations on getting best performance with
19-
sparse matrices in Armadillo.
16+
Besides outstanding support for dense matrices, the Armadillo library also provides a great way to
17+
manipulate sparse matrices in C++. However, the performance characteristics of dealing with sparse
18+
matrices may be surprising if one is only familiar with dense matrices. This is a collection of
19+
observations on getting best performance with sparse matrices in Armadillo.
2020

2121
All the timings in this article were generated using Armadillo version 8.500. This version adds a
2222
number of substantial optimisations for sparse matrix operations, in some cases speeding things up
@@ -105,7 +105,7 @@ system.time(m0 <- a %*% b)
105105

106106
<pre class="output">
107107
user system elapsed
108-
0.221 0.089 0.310
108+
0.230 0.091 0.322
109109
</pre>
110110

111111

@@ -118,7 +118,7 @@ system.time(m1 <- mult_sp_sp_to_sp(a, b))
118118

119119
<pre class="output">
120120
user system elapsed
121-
0.368 0.063 0.431
121+
0.407 0.036 0.442
122122
</pre>
123123

124124

@@ -131,7 +131,7 @@ system.time(m2 <- mult_sp_den_to_sp(a, b_den))
131131

132132
<pre class="output">
133133
user system elapsed
134-
15.511 0.089 15.600
134+
1.081 0.100 1.181
135135
</pre>
136136

137137

@@ -144,7 +144,7 @@ system.time(m3 <- mult_den_sp_to_sp(a_den, b))
144144

145145
<pre class="output">
146146
user system elapsed
147-
0.910 0.092 1.002
147+
0.826 0.087 0.913
148148
</pre>
149149

150150

@@ -195,7 +195,7 @@ system.time(m4 <- mult_sp_den_to_sp2(a, b_den))
195195

196196
<pre class="output">
197197
user system elapsed
198-
0.442 0.040 0.483
198+
0.401 0.047 0.448
199199
</pre>
200200

201201

@@ -256,7 +256,7 @@ system.time({
256256

257257
<pre class="output">
258258
user system elapsed
259-
1.873 0.004 1.878
259+
1.708 0.000 1.707
260260
</pre>
261261

262262
For a large matrix, this takes a not-insignificant amount of time, even on a fast machine. To speed
@@ -304,7 +304,7 @@ system.time({
304304

305305
<pre class="output">
306306
user system elapsed
307-
0.818 0.000 0.817
307+
0.766 0.000 0.766
308308
</pre>
309309

310310
The time taken has come down by quite a substantial margin. This reflects the ease of obtaining
@@ -353,7 +353,7 @@ system.time(print(sum_by_row(a)))
353353

354354
<pre class="output">
355355
user system elapsed
356-
0.926 0.000 0.926
356+
0.933 0.000 0.935
357357
</pre>
358358

359359
This is again a large improvement. But what if we do the same with column slicing?
@@ -391,7 +391,7 @@ system.time(print(sum_by_col(a_t)))
391391

392392
<pre class="output">
393393
user system elapsed
394-
0.006 0.000 0.006
394+
0.005 0.000 0.006
395395
</pre>
396396

397397
Now the time is less than a tenth of a second, which is faster than the original code by roughly
@@ -445,7 +445,7 @@ system.time(print(sum_by_element(a)))
445445

446446
<pre class="output">
447447
user system elapsed
448-
0.388 0.000 0.388
448+
0.176 0.000 0.176
449449
</pre>
450450

451451
However, we can still do better. In Armadillo, the iterators for sparse matrix classes iterate only
@@ -502,9 +502,9 @@ microbenchmark(col=sum_by_col(a_t),
502502
<pre class="output">
503503
Unit: milliseconds
504504
expr min lq mean median uq max neval
505-
col 5.02286 5.17710 5.34210 5.33575 5.39444 6.02304 20
506-
elem 389.33550 393.98013 402.67589 403.13064 411.42497 420.33654 20
507-
iter 1.01472 1.07613 1.19713 1.18075 1.22931 1.74711 20
505+
col 4.78921 4.88444 5.05229 4.99184 5.18450 5.50579 20
506+
elem 172.84830 177.20431 179.87007 179.06447 182.08075 188.11256 20
507+
iter 1.02268 1.05447 1.12611 1.12627 1.16482 1.30800 20
508508
</pre>
509509

510510
Thus, using iterators represents a greater than three-order-of-magnitude speedup over the original

‎src/2018-04-18-armadillo-sparse-matrix-performance.Rmd

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ knitr::opts_chunk$set(collapse=TRUE)
1414
options(width=80)
1515
```
1616

17-
The Armadillo library provides a great way to manipulate sparse matrices in C++. However, the
18-
performance characteristics of dealing with sparse matrices may be surprising if one is only
19-
familiar with dense matrices. This is a collection of observations on getting best performance with
20-
sparse matrices in Armadillo.
17+
Besides outstanding support for dense matrices, the Armadillo library also provides a great way to
18+
manipulate sparse matrices in C++. However, the performance characteristics of dealing with sparse
19+
matrices may be surprising if one is only familiar with dense matrices. This is a collection of
20+
observations on getting best performance with sparse matrices in Armadillo.
2121

2222
All the timings in this article were generated using Armadillo version 8.500. This version adds a
2323
number of substantial optimisations for sparse matrix operations, in some cases speeding things up

0 commit comments

Comments
 (0)
Please sign in to comment.