[mlpack-git] master, mlpack-1.0.x: Add some Armadillo traits for template metaprogramming. This abstraction may change as time goes on. (6322216)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:44:14 EST 2015


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

On branches: master,mlpack-1.0.x
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

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

commit 6322216a0f44d21b0c4494669831de47dfc48574
Author: Ryan Curtin <ryan at ratml.org>
Date:   Thu Feb 20 00:15:09 2014 +0000

    Add some Armadillo traits for template metaprogramming.  This abstraction may
    change as time goes on.


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

6322216a0f44d21b0c4494669831de47dfc48574
 src/mlpack/core/util/arma_traits.hpp | 86 ++++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)

diff --git a/src/mlpack/core/util/arma_traits.hpp b/src/mlpack/core/util/arma_traits.hpp
new file mode 100644
index 0000000..a9728fc
--- /dev/null
+++ b/src/mlpack/core/util/arma_traits.hpp
@@ -0,0 +1,86 @@
+/**
+ * @file arma_traits.hpp
+ * @author Ryan Curtin
+ *
+ * Some traits used for template metaprogramming (SFINAE) with Armadillo types.
+ */
+#ifndef __MLPACK_CORE_UTIL_ARMA_TRAITS_HPP
+#define __MLPACK_CORE_UTIL_ARMA_TRAITS_HPP
+
+// Structs have public members by default (that's why they are chosen over
+// classes).
+
+/**
+ * If value == true, then VecType is some sort of Armadillo vector or subview.
+ * You might use this struct like this:
+ *
+ * @code
+ * // Only accepts VecTypes that are actually Armadillo vector types.
+ * template<typename VecType>
+ * void Function(const VecType& argumentA,
+ *               typename boost::enable_if<IsVector<VecType> >* = 0);
+ * @endcode
+ *
+ * The use of the enable_if object allows the compiler to instantiate Function()
+ * only if VecType is one of the Armadillo vector types.  It has a default
+ * argument because it isn't meant to be used in either the function call or the
+ * function body.
+ */
+template<typename VecType>
+struct IsVector
+{
+  const static bool value = false;
+};
+
+template<>
+template<typename eT>
+struct IsVector<arma::Col<eT> >
+{
+  const static bool value = true;
+};
+
+template<>
+template<typename eT>
+struct IsVector<arma::SpCol<eT> >
+{
+  const static bool value = true;
+};
+
+template<>
+template<typename eT>
+struct IsVector<arma::Row<eT> >
+{
+  const static bool value = true;
+};
+
+template<>
+template<typename eT>
+struct IsVector<arma::SpRow<eT> >
+{
+  const static bool value = true;
+};
+
+template<>
+template<typename eT>
+struct IsVector<arma::subview_col<eT> >
+{
+  const static bool value = true;
+};
+
+template<>
+template<typename eT>
+struct IsVector<arma::subview_row<eT> >
+{
+  const static bool value = true;
+};
+
+// I'm not so sure about this one.  An SpSubview object can be a row or column,
+// but it can also be a matrix subview.
+template<>
+template<typename eT>
+struct IsVector<arma::SpSubview<eT> >
+{
+  const static bool value = true;
+};
+
+#endif



More information about the mlpack-git mailing list