[mlpack-svn] r14060 - mlpack/trunk/src/mlpack/core/arma_extend

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Jan 1 22:16:29 EST 2013


Author: rcurtin
Date: 2013-01-01 22:16:28 -0500 (Tue, 01 Jan 2013)
New Revision: 14060

Added:
   mlpack/trunk/src/mlpack/core/arma_extend/hdf5_misc.hpp
   mlpack/trunk/src/mlpack/core/arma_extend/restrictors.hpp
Modified:
   mlpack/trunk/src/mlpack/core/arma_extend/arma_extend.hpp
   mlpack/trunk/src/mlpack/core/arma_extend/traits.hpp
   mlpack/trunk/src/mlpack/core/arma_extend/typedef.hpp
Log:
Some tricks to get u64/s64 support on more recent versions of Armadillo.


Modified: mlpack/trunk/src/mlpack/core/arma_extend/arma_extend.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/arma_extend/arma_extend.hpp	2012-12-31 10:00:47 UTC (rev 14059)
+++ mlpack/trunk/src/mlpack/core/arma_extend/arma_extend.hpp	2013-01-02 03:16:28 UTC (rev 14060)
@@ -28,10 +28,12 @@
 #endif
 
 namespace arma {
-  // u64
+  // u64/s64
   #include "typedef.hpp"
   #include "traits.hpp"
   #include "promote_type.hpp"
+  #include "restrictors.hpp"
+  #include "hdf5_misc.hpp"
 
   // ccov()
   #include "op_ccov_proto.hpp"

Added: mlpack/trunk/src/mlpack/core/arma_extend/hdf5_misc.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/arma_extend/hdf5_misc.hpp	                        (rev 0)
+++ mlpack/trunk/src/mlpack/core/arma_extend/hdf5_misc.hpp	2013-01-02 03:16:28 UTC (rev 14060)
@@ -0,0 +1,21 @@
+// To hack in u64/s64 support to Armadillo when it is not compiled with
+// ARMA_64BIT_WORD.
+#ifdef ARMA_USE_HDF5
+
+template<>
+inline
+hid_t
+get_hdf5_type< long long >()
+  {
+  return H5Tcopy(H5T_NATIVE_LLONG);
+  }
+
+template<>
+inline
+hid_t
+get_hdf5_type< unsigned long long >()
+  {
+  return H5Tcopy(H5T_NATIVE_ULLONG);
+  }
+
+#endif

Added: mlpack/trunk/src/mlpack/core/arma_extend/restrictors.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/arma_extend/restrictors.hpp	                        (rev 0)
+++ mlpack/trunk/src/mlpack/core/arma_extend/restrictors.hpp	2013-01-02 03:16:28 UTC (rev 14060)
@@ -0,0 +1,17 @@
+// Modifications to allow u64/s64 in Armadillo when ARMA_64BIT_WORD is not
+// defined.
+#ifndef ARMA_64BIT_WORD
+
+template<> struct arma_scalar_only<u64>   { typedef u64   result; };
+template<> struct arma_scalar_only<s64>   { typedef s64   result; };
+
+template<> struct arma_integral_only<u64> { typedef u64   result; };
+template<> struct arma_integral_only<s64> { typedef s64   result; };
+
+template<> struct arma_unsigned_integral_only<u64> { typedef u64 result; };
+
+template<> struct arma_signed_integral_only<s64> { typedef s64 result; };
+
+template<> struct arma_signed_only<s64> { typedef s64 result; };
+
+#endif

Modified: mlpack/trunk/src/mlpack/core/arma_extend/traits.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/arma_extend/traits.hpp	2012-12-31 10:00:47 UTC (rev 14059)
+++ mlpack/trunk/src/mlpack/core/arma_extend/traits.hpp	2013-01-02 03:16:28 UTC (rev 14060)
@@ -1,31 +1,42 @@
 // Extra traits to support u64 and s64 until that patch is applied to the
 // Armadillo sources.
 
-#if ARMA_VERSION_MAJOR < 1 || \
-    (ARMA_VERSION_MAJOR == 1 && ARMA_VERSION_MINOR <= 2)
-// For old Armadillo versions ( <= 1.2.0 ), all we have to do is define these
-// two structs which say these element types are supported.
-template<> struct isnt_supported_elem_type< u64 >                  : public isnt_supported_elem_type_false {};
-template<> struct isnt_supported_elem_type< s64 >                  : public isnt_supported_elem_type_false {};
-
-#else
-// For new Armadillo versions ( > 1.2.0 ) we have to get a little bit more
-// tricky.  We will overload the values for the is_supported_elem_type
-// structure, allowing us to redefine it to report success for u64s and s64s.
-
 // This isn't necessary if Armadillo was compiled with 64-bit support.
 #ifndef ARMA_64BIT_WORD
-template<>
-struct is_supported_elem_type<u64>
-  {
-  static const bool value = true;
-  };
+  template<typename T1>
+  struct is_u64
+    { static const bool value = false; };
 
-template<>
-struct is_supported_elem_type<s64>
-  {
-  static const bool value = true;
-  };
-#endif
+  template<>
+  struct is_u64<u64>
+    { static const bool value = true; };
 
+
+  template<typename T1>
+  struct is_s64
+    { static const bool value = false; };
+
+  template<>
+  struct is_s64<s64>
+    { static const bool value = true; };
+
+  template<>
+  struct is_supported_elem_type<u64>
+    {
+    static const bool value = true;
+    };
+
+  template<>
+  struct is_supported_elem_type<s64>
+    {
+    static const bool value = true;
+    };
+
+
+  template<>
+  struct is_signed<u64>
+    {
+    static const bool value = false;
+    };
+
 #endif

Modified: mlpack/trunk/src/mlpack/core/arma_extend/typedef.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/arma_extend/typedef.hpp	2012-12-31 10:00:47 UTC (rev 14059)
+++ mlpack/trunk/src/mlpack/core/arma_extend/typedef.hpp	2013-01-02 03:16:28 UTC (rev 14060)
@@ -1,60 +1,7 @@
 // Extensions to typedef u64 and s64 until that support is added into
 // Armadillo.  We only need to typedef s64 on Armadillo > 1.2.0.
 
-#if   ((ARMA_VERSION_MAJOR > 1)) || \
-      ((ARMA_VERSION_MAJOR == 1) && (ARMA_VERSION_MINOR > 2)) || \
-      ((ARMA_VERSION_MAJOR == 1) && (ARMA_VERSION_MINOR == 2) && \
-       (ARMA_VERSION_PATCH > 0))
 #ifndef ARMA_64BIT_WORD
-  // An unincluded header file typedefs u64 for us.
-  template<const bool size_t_is_greater_or_equal_to_8_bytes>
-  struct deduce_u64
-    {
-    };
-
-  template<>
-  struct deduce_u64<true>
-    {
-    typedef std::size_t u64;
-
-    static const u64  max   = (sizeof(u64) >= 8) ? 0xFFFFFFFFFFFFFFFF : 0xFFFFFFFF;  // check required for silly compilers
-    static const bool trunc = false;
-    };
-
-  template<>
-  struct deduce_u64<false>
-    {
-    #if (ULONG_MAX >= 0xFFFFFFFFFFFFFFFF)
-      typedef unsigned long u64;
-      static const u64  max   = 0xFFFFFFFFFFFFFFFF;
-      static const bool trunc = false;
-    #elif defined(ULLONG_MAX)
-      typedef unsigned long long u64;
-      static const u64  max   = 0xFFFFFFFFFFFFFFFF;
-      static const bool trunc = false;
-    #elif (_MSC_VER >= 1200)
-    //#elif (_MSC_VER >= 1310) && defined(_MSC_EXTENSIONS)
-      typedef unsigned __int64 u64;
-      static const u64  max   = 0xFFFFFFFFFFFFFFFF;
-      static const bool trunc = false;
-    #else
-      #error "don't know how to typedef 'u64' on this system"
-    #endif
-    };
-
-  typedef deduce_u64<(sizeof(std::size_t) >= 8)>::u64 u64;
-#endif
-
-  // We only need to typedef s64.
-  #if   ULONG_MAX >= 0xffffffffffffffff
-    typedef          long s64;
-  #elif ULLONG_MAX >= 0xffffffffffffffff
-    typedef          long s64;
-  #else
-    #error "don't know how to typedef 's64' on this system"
-  #endif
-#else
-
   // We must typedef both u64 and s64.
   #if   ULONG_MAX >= 0xffffffffffffffff
     typedef unsigned long u64;
@@ -66,4 +13,13 @@
     #error "don't know how to typedef 'u64' on this system"
   #endif
 
+  namespace junk
+    {
+    struct arma_64_elem_size_test
+      {
+      arma_static_check( (sizeof(u64) != 8), ERROR___TYPE_U64_HAS_UNSUPPORTED_SIZE );
+      arma_static_check( (sizeof(s64) != 8), ERROR___TYPE_S64_HAS_UNSUPPORTED_SIZE );
+      };
+    }
+
 #endif




More information about the mlpack-svn mailing list