tAdded C++ Eigen3 and Armadillo implementations, verified - numeric - C++ libra… | |
git clone git://src.adamsgaard.dk/numeric | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit 2f91c02ec1ef61628279942caaba7acf18bf6041 | |
parent 64d8741235c18b77a31c21f83ac473297f678c72 | |
Author: Anders Damsgaard Christensen <[email protected]> | |
Date: Sat, 16 Feb 2013 23:02:17 +0100 | |
Added C++ Eigen3 and Armadillo implementations, verified | |
Diffstat: | |
M matrixmul/Makefile | 23 ++++++++++++++++++++++- | |
A matrixmul/cpp-armadillo.cpp | 32 +++++++++++++++++++++++++++++… | |
A matrixmul/cpp-eigen.cpp | 33 +++++++++++++++++++++++++++++… | |
M matrixmul/plot.gp | 2 ++ | |
4 files changed, 89 insertions(+), 1 deletion(-) | |
--- | |
diff --git a/matrixmul/Makefile b/matrixmul/Makefile | |
t@@ -18,7 +18,7 @@ CXX=g++ | |
CFLAGS=-Wall -O3 -march=native | |
CXXFLAGS=-Wall -O3 -march=native | |
-performance.png: plot.gp lua-arrofarrs.dat lua-linarr.dat luajit-arrofarrs.dat… | |
+performance.png: plot.gp lua-arrofarrs.dat lua-linarr.dat luajit-arrofarrs.dat… | |
gnuplot -e "platform='$(shell uname -norm)'; threads='$(shell ./cputhr… | |
# Lua: Matrices as arrays of arrays | |
t@@ -138,6 +138,27 @@ cpp-linvectors.dat: cpp-linvectors | |
echo $$dims; \ | |
done | |
+# C++: Eigen | |
+cpp-eigen.dat: cpp-eigen | |
+ # cpp-eigen | |
+ @rm -f $@ | |
+ @for dims in $(MATRIXDIMS_FAST); do \ | |
+ $(PREFIXCMD) $@ -f "$$dims %e" ./$< $$dims; \ | |
+ echo $$dims; \ | |
+ done | |
+ | |
+# C++: Armadillo | |
+cpp-armadillo.dat: cpp-armadillo | |
+ # cpp-armadillo | |
+ @rm -f $@ | |
+ @for dims in $(MATRIXDIMS_FAST); do \ | |
+ $(PREFIXCMD) $@ -f "$$dims %e" ./$< $$dims; \ | |
+ echo $$dims; \ | |
+ done | |
+ | |
+cpp-armadillo: cpp-armadillo.cpp | |
+ $(CXX) $(CXXFLAGS) -larmadillo $< -o $@ | |
+ | |
# Python: Numpy module | |
python-numpy.dat: python-numpy.py | |
# python-numpy.py | |
diff --git a/matrixmul/cpp-armadillo.cpp b/matrixmul/cpp-armadillo.cpp | |
t@@ -0,0 +1,32 @@ | |
+#include <iostream> | |
+#include <cstdlib> | |
+#include <armadillo> | |
+ | |
+int main(int argc, char* argv[]) | |
+{ | |
+ using std::cout; | |
+ | |
+ unsigned int N, i, j; | |
+ | |
+ if (argc == 2) { | |
+ N = atoi(argv[1]); | |
+ } else { | |
+ std::cerr << "Sorry, I need matrix width as command line argument\n"; | |
+ return 1; | |
+ } | |
+ | |
+ arma::mat A(N,N); | |
+ arma::mat B(N,N); | |
+ arma::mat C(N,N); | |
+ | |
+ for (i = 0; i<N; ++i) { | |
+ for (j = 0; j<N; ++j) { | |
+ A(i,j) = 2.0; | |
+ B(i,j) = (double) N*j + i; | |
+ } | |
+ } | |
+ | |
+ C = A*B; | |
+ | |
+ return 0; | |
+} | |
diff --git a/matrixmul/cpp-eigen.cpp b/matrixmul/cpp-eigen.cpp | |
t@@ -0,0 +1,33 @@ | |
+#include <iostream> | |
+#include <cstdlib> | |
+#include <Eigen/Dense> | |
+ | |
+int main(int argc, char* argv[]) | |
+{ | |
+ using std::cout; | |
+ using Eigen::MatrixXd; | |
+ | |
+ unsigned int N, i, j; | |
+ | |
+ if (argc == 2) { | |
+ N = atoi(argv[1]); | |
+ } else { | |
+ std::cerr << "Sorry, I need matrix width as command line argument\n"; | |
+ return 1; | |
+ } | |
+ | |
+ MatrixXd A(N,N); | |
+ MatrixXd B(N,N); | |
+ MatrixXd C(N,N); | |
+ | |
+ for (i = 0; i<N; ++i) { | |
+ for (j = 0; j<N; ++j) { | |
+ A(i,j) = 2.0; | |
+ B(i,j) = (double) N*j + i; | |
+ } | |
+ } | |
+ | |
+ C = A*B; | |
+ | |
+ return 0; | |
+} | |
diff --git a/matrixmul/plot.gp b/matrixmul/plot.gp | |
t@@ -21,4 +21,6 @@ plot \ | |
"julia.dat" title "Julia" w lp, \ | |
"c-gsl-cblas.dat" title "C: GSL CBLAS" w lp, \ | |
"octave.dat" title "Octave" w lp | |
+ "cpp-armadillo.dat" title "C++: Armadillo" w lp, \ | |
+ "cpp-eigen.dat" title "C++: Eigen3" w lp, \ | |