mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
Modify googlehash use to account for namespace issues.
The namespace declaration for googlehash is a configurable macro that can be disabled. In particular, it is disabled within google, causing compile errors since `dense_hash_map`/`sparse_hash_map` are then in the global namespace instead of in `::google`. Here we play a bit of gynastics to allow for both `google::*_hash_map` and `*_hash_map`, while limiting namespace polution. Symbols within the `::google` namespace are imported into `Eigen::google`. We also remove checks based on `_SPARSE_HASH_MAP_H_`, as this is fragile, and instead require `EIGEN_GOOGLEHASH_SUPPORT` to be defined.
This commit is contained in:
parent
9357feedc7
commit
69adf26aa3
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#define NOGMM
|
#define NOGMM
|
||||||
#define NOMTL
|
#define NOMTL
|
||||||
|
#define EIGEN_GOOGLEHASH_SUPPORT 1
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <ext/hash_map>
|
#include <ext/hash_map>
|
||||||
|
@ -29,10 +29,6 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EIGEN_GOOGLEHASH_SUPPORT
|
|
||||||
#include <google/sparse_hash_map>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <Eigen/Cholesky>
|
#include <Eigen/Cholesky>
|
||||||
#include <Eigen/LU>
|
#include <Eigen/LU>
|
||||||
#include <Eigen/Sparse>
|
#include <Eigen/Sparse>
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#ifdef EIGEN_GOOGLEHASH_SUPPORT
|
#ifdef EIGEN_GOOGLEHASH_SUPPORT
|
||||||
#include <google/dense_hash_map>
|
#include <google/dense_hash_map>
|
||||||
|
#include <google/sparse_hash_map>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,7 +10,13 @@
|
|||||||
#ifndef EIGEN_RANDOMSETTER_H
|
#ifndef EIGEN_RANDOMSETTER_H
|
||||||
#define 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
|
/** Represents a std::map
|
||||||
*
|
*
|
||||||
@ -56,7 +62,26 @@ template<typename Scalar> struct StdUnorderedMapTraits
|
|||||||
};
|
};
|
||||||
#endif // EIGEN_UNORDERED_MAP_SUPPORT
|
#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
|
/** Represents a google::dense_hash_map
|
||||||
*
|
*
|
||||||
* \see RandomSetter
|
* \see RandomSetter
|
||||||
@ -64,7 +89,7 @@ template<typename Scalar> struct StdUnorderedMapTraits
|
|||||||
template<typename Scalar> struct GoogleDenseHashMapTraits
|
template<typename Scalar> struct GoogleDenseHashMapTraits
|
||||||
{
|
{
|
||||||
typedef int KeyType;
|
typedef int KeyType;
|
||||||
typedef google::dense_hash_map<KeyType,Scalar> Type;
|
typedef typename google::DenseHashMap<KeyType,Scalar>::type Type;
|
||||||
enum {
|
enum {
|
||||||
IsSorted = 0
|
IsSorted = 0
|
||||||
};
|
};
|
||||||
@ -72,9 +97,7 @@ template<typename Scalar> struct GoogleDenseHashMapTraits
|
|||||||
static void setInvalidKey(Type& map, const KeyType& k)
|
static void setInvalidKey(Type& map, const KeyType& k)
|
||||||
{ map.set_empty_key(k); }
|
{ map.set_empty_key(k); }
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _SPARSE_HASH_MAP_H_
|
|
||||||
/** Represents a google::sparse_hash_map
|
/** Represents a google::sparse_hash_map
|
||||||
*
|
*
|
||||||
* \see RandomSetter
|
* \see RandomSetter
|
||||||
@ -82,7 +105,7 @@ template<typename Scalar> struct GoogleDenseHashMapTraits
|
|||||||
template<typename Scalar> struct GoogleSparseHashMapTraits
|
template<typename Scalar> struct GoogleSparseHashMapTraits
|
||||||
{
|
{
|
||||||
typedef int KeyType;
|
typedef int KeyType;
|
||||||
typedef google::sparse_hash_map<KeyType,Scalar> Type;
|
typedef typename google::SparseHashMap<KeyType,Scalar>::type Type;
|
||||||
enum {
|
enum {
|
||||||
IsSorted = 0
|
IsSorted = 0
|
||||||
};
|
};
|
||||||
@ -134,18 +157,17 @@ template<typename Scalar> struct GoogleSparseHashMapTraits
|
|||||||
* GoogleSparseHashMapTraits, GnuHashMapTraits, and finally StdMapTraits.
|
* GoogleSparseHashMapTraits, GnuHashMapTraits, and finally StdMapTraits.
|
||||||
*
|
*
|
||||||
* For performance and memory consumption reasons it is highly recommended to use one of
|
* 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:
|
* Google's hash_map implementations. To enable the support for them, you must define
|
||||||
* - \#include <google/dense_hash_map> yourself \b before Eigen/Sparse header
|
* EIGEN_GOOGLEHASH_SUPPORT. This will include both <google/dense_hash_map> and
|
||||||
* - define EIGEN_GOOGLEHASH_SUPPORT
|
* <google/sparse_hash_map> for you.
|
||||||
* In the later case the inclusion of <google/dense_hash_map> is made for you.
|
|
||||||
*
|
*
|
||||||
* \see http://code.google.com/p/google-sparsehash/
|
* \see https://github.com/sparsehash/sparsehash
|
||||||
*/
|
*/
|
||||||
template<typename SparseMatrixType,
|
template<typename SparseMatrixType,
|
||||||
template <typename T> class MapTraits =
|
template <typename T> class MapTraits =
|
||||||
#if defined _DENSE_HASH_MAP_H_
|
#if defined(EIGEN_GOOGLEHASH_SUPPORT)
|
||||||
GoogleDenseHashMapTraits
|
GoogleDenseHashMapTraits
|
||||||
#elif defined _HASH_MAP
|
#elif defined(_HASH_MAP)
|
||||||
GnuHashMapTraits
|
GnuHashMapTraits
|
||||||
#else
|
#else
|
||||||
StdMapTraits
|
StdMapTraits
|
||||||
|
@ -123,10 +123,8 @@ template<typename SparseMatrixType> void sparse_extra(const SparseMatrixType& re
|
|||||||
#ifdef EIGEN_UNORDERED_MAP_SUPPORT
|
#ifdef EIGEN_UNORDERED_MAP_SUPPORT
|
||||||
VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, StdUnorderedMapTraits> >(m,refMat,nonzeroCoords) ));
|
VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, StdUnorderedMapTraits> >(m,refMat,nonzeroCoords) ));
|
||||||
#endif
|
#endif
|
||||||
#ifdef _DENSE_HASH_MAP_H_
|
#ifdef EIGEN_GOOGLEHASH_SUPPORT
|
||||||
VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, GoogleDenseHashMapTraits> >(m,refMat,nonzeroCoords) ));
|
VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, GoogleDenseHashMapTraits> >(m,refMat,nonzeroCoords) ));
|
||||||
#endif
|
|
||||||
#ifdef _SPARSE_HASH_MAP_H_
|
|
||||||
VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, GoogleSparseHashMapTraits> >(m,refMat,nonzeroCoords) ));
|
VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, GoogleSparseHashMapTraits> >(m,refMat,nonzeroCoords) ));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user