[mlpack-git] master: Backport operator-(sp_mat) for Armadillo <= 4.000. (dd5d265)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Fri Feb 6 16:19:08 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/5b8b88c95e161efd977709c303861b9c3b88feb2...dd5d265ac1897b96cc7e98778557a1361415d509

>---------------------------------------------------------------

commit dd5d265ac1897b96cc7e98778557a1361415d509
Author: Ryan Curtin <ryan at ratml.org>
Date:   Fri Feb 6 16:18:15 2015 -0500

    Backport operator-(sp_mat) for Armadillo <= 4.000.


>---------------------------------------------------------------

dd5d265ac1897b96cc7e98778557a1361415d509
 src/mlpack/core/arma_extend/CMakeLists.txt     |  1 +
 src/mlpack/core/arma_extend/arma_extend.hpp    |  3 +++
 src/mlpack/core/arma_extend/operator_minus.hpp | 25 +++++++++++++++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/src/mlpack/core/arma_extend/CMakeLists.txt b/src/mlpack/core/arma_extend/CMakeLists.txt
index 50b3cad..43f6ee1 100644
--- a/src/mlpack/core/arma_extend/CMakeLists.txt
+++ b/src/mlpack/core/arma_extend/CMakeLists.txt
@@ -8,6 +8,7 @@ set(SOURCES
   hdf5_misc.hpp
   op_ccov_meat.hpp
   op_ccov_proto.hpp
+  operator_minus.hpp
   promote_type.hpp
   restrictors.hpp
   traits.hpp
diff --git a/src/mlpack/core/arma_extend/arma_extend.hpp b/src/mlpack/core/arma_extend/arma_extend.hpp
index cfc9c05..ec50735 100644
--- a/src/mlpack/core/arma_extend/arma_extend.hpp
+++ b/src/mlpack/core/arma_extend/arma_extend.hpp
@@ -44,6 +44,9 @@ namespace arma {
 
   // inplace_reshape()
   #include "fn_inplace_reshape.hpp"
+
+  // unary minus for sparse matrices
+  #include "operator_minus.hpp"
 };
 
 #endif
diff --git a/src/mlpack/core/arma_extend/operator_minus.hpp b/src/mlpack/core/arma_extend/operator_minus.hpp
new file mode 100644
index 0000000..dc6a4f1
--- /dev/null
+++ b/src/mlpack/core/arma_extend/operator_minus.hpp
@@ -0,0 +1,25 @@
+// Backport unary minus operator for sparse matrices to Armadillo 4.000 and
+// older.
+
+#if (ARMA_VERSION_MAJOR < 4) || \
+    (ARMA_VERSION_MAJOR == 4 && ARMA_VERSION_MINOR <= 0)
+
+template<typename T1>
+inline
+typename
+enable_if2
+  <
+  is_arma_sparse_type<T1>::value && is_signed<typename T1::elem_type>::value,
+  SpOp<T1,spop_scalar_times>
+  >::result
+operator-
+(const T1& X)
+  {
+  arma_extra_debug_sigprint();
+
+  typedef typename T1::elem_type eT;
+
+  return SpOp<T1,spop_scalar_times>(X, eT(-1));
+  }
+
+#endif



More information about the mlpack-git mailing list