diff options
Diffstat (limited to 'unsupported/Eigen/src/SparseExtra/RandomSetter.h')
-rw-r--r-- | unsupported/Eigen/src/SparseExtra/RandomSetter.h | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/unsupported/Eigen/src/SparseExtra/RandomSetter.h b/unsupported/Eigen/src/SparseExtra/RandomSetter.h index ee97299af..985702b5f 100644 --- a/unsupported/Eigen/src/SparseExtra/RandomSetter.h +++ b/unsupported/Eigen/src/SparseExtra/RandomSetter.h @@ -10,7 +10,13 @@ #ifndef EIGEN_RANDOMSETTER_H #define EIGEN_RANDOMSETTER_H -namespace Eigen { +#if defined(EIGEN_GOOGLEHASH_SUPPORT) +// Ensure the ::google namespace exists, required for checking existence of +// ::google::dense_hash_map and ::google::sparse_hash_map. +namespace google {} +#endif + +namespace Eigen { /** Represents a std::map * @@ -56,7 +62,26 @@ template<typename Scalar> struct StdUnorderedMapTraits }; #endif // EIGEN_UNORDERED_MAP_SUPPORT -#ifdef _DENSE_HASH_MAP_H_ +#if defined(EIGEN_GOOGLEHASH_SUPPORT) + +namespace google { + +// Namespace work-around, since sometimes dense_hash_map and sparse_hash_map +// are in the global namespace, and other times they are under ::google. +using namespace ::google; + +template<typename KeyType, typename Scalar> +struct DenseHashMap { + typedef dense_hash_map<KeyType, Scalar> type; +}; + +template<typename KeyType, typename Scalar> +struct SparseHashMap { + typedef sparse_hash_map<KeyType, Scalar> type; +}; + +} // namespace google + /** Represents a google::dense_hash_map * * \see RandomSetter @@ -64,7 +89,7 @@ template<typename Scalar> struct StdUnorderedMapTraits template<typename Scalar> struct GoogleDenseHashMapTraits { typedef int KeyType; - typedef google::dense_hash_map<KeyType,Scalar> Type; + typedef typename google::DenseHashMap<KeyType,Scalar>::type Type; enum { IsSorted = 0 }; @@ -72,9 +97,7 @@ template<typename Scalar> struct GoogleDenseHashMapTraits static void setInvalidKey(Type& map, const KeyType& k) { map.set_empty_key(k); } }; -#endif -#ifdef _SPARSE_HASH_MAP_H_ /** Represents a google::sparse_hash_map * * \see RandomSetter @@ -82,7 +105,7 @@ template<typename Scalar> struct GoogleDenseHashMapTraits template<typename Scalar> struct GoogleSparseHashMapTraits { typedef int KeyType; - typedef google::sparse_hash_map<KeyType,Scalar> Type; + typedef typename google::SparseHashMap<KeyType,Scalar>::type Type; enum { IsSorted = 0 }; @@ -134,18 +157,17 @@ template<typename Scalar> struct GoogleSparseHashMapTraits * GoogleSparseHashMapTraits, GnuHashMapTraits, and finally StdMapTraits. * * For performance and memory consumption reasons it is highly recommended to use one of - * the Google's hash_map implementation. To enable the support for them, you have two options: - * - \#include <google/dense_hash_map> yourself \b before Eigen/Sparse header - * - define EIGEN_GOOGLEHASH_SUPPORT - * In the later case the inclusion of <google/dense_hash_map> is made for you. + * Google's hash_map implementations. To enable the support for them, you must define + * EIGEN_GOOGLEHASH_SUPPORT. This will include both <google/dense_hash_map> and + * <google/sparse_hash_map> for you. * - * \see http://code.google.com/p/google-sparsehash/ + * \see https://github.com/sparsehash/sparsehash */ template<typename SparseMatrixType, template <typename T> class MapTraits = -#if defined _DENSE_HASH_MAP_H_ +#if defined(EIGEN_GOOGLEHASH_SUPPORT) GoogleDenseHashMapTraits -#elif defined _HASH_MAP +#elif defined(_HASH_MAP) GnuHashMapTraits #else StdMapTraits @@ -249,10 +271,10 @@ class RandomSetter } } // prefix sum - Index count = 0; + StorageIndex count = 0; for (Index j=0; j<mp_target->outerSize(); ++j) { - Index tmp = positions[j]; + StorageIndex tmp = positions[j]; mp_target->outerIndexPtr()[j] = count; positions[j] = count; count += tmp; @@ -281,7 +303,7 @@ class RandomSetter mp_target->innerIndexPtr()[i+1] = mp_target->innerIndexPtr()[i]; --i; } - mp_target->innerIndexPtr()[i+1] = inner; + mp_target->innerIndexPtr()[i+1] = internal::convert_index<StorageIndex>(inner); mp_target->valuePtr()[i+1] = it->second.value; } } |