* fix compilation with gcc 3.4

* add an option to disable Qt testing
This commit is contained in:
Gael Guennebaud 2009-01-23 09:50:16 +00:00
parent 291ee89684
commit d3dcb04f2d
6 changed files with 50 additions and 41 deletions

View File

@ -37,7 +37,7 @@ class CompressedStorage
: m_values(0), m_indices(0), m_size(0), m_allocatedSize(0) : m_values(0), m_indices(0), m_size(0), m_allocatedSize(0)
{} {}
CompressedStorage(int size) CompressedStorage(size_t size)
: m_values(0), m_indices(0), m_size(0), m_allocatedSize(0) : m_values(0), m_indices(0), m_size(0), m_allocatedSize(0)
{ {
resize(size); resize(size);
@ -71,9 +71,9 @@ class CompressedStorage
delete[] m_indices; delete[] m_indices;
} }
void reserve(int size) void reserve(size_t size)
{ {
int newAllocatedSize = m_size + size; size_t newAllocatedSize = m_size + size;
if (newAllocatedSize > m_allocatedSize) if (newAllocatedSize > m_allocatedSize)
reallocate(newAllocatedSize); reallocate(newAllocatedSize);
} }
@ -84,10 +84,10 @@ class CompressedStorage
reallocate(m_size); reallocate(m_size);
} }
void resize(int size, float reserveSizeFactor = 0) void resize(size_t size, float reserveSizeFactor = 0)
{ {
if (m_allocatedSize<size) if (m_allocatedSize<size)
reallocate(size + reserveSizeFactor*size); reallocate(size + size_t(reserveSizeFactor*size));
m_size = size; m_size = size;
} }
@ -99,17 +99,17 @@ class CompressedStorage
m_indices[id] = i; m_indices[id] = i;
} }
inline int size() const { return m_size; } inline size_t size() const { return m_size; }
inline int allocatedSize() const { return m_allocatedSize; } inline size_t allocatedSize() const { return m_allocatedSize; }
inline void clear() { m_size = 0; } inline void clear() { m_size = 0; }
inline Scalar& value(int i) { return m_values[i]; } inline Scalar& value(size_t i) { return m_values[i]; }
inline const Scalar& value(int i) const { return m_values[i]; } inline const Scalar& value(size_t i) const { return m_values[i]; }
inline int& index(int i) { return m_indices[i]; } inline int& index(size_t i) { return m_indices[i]; }
inline const int& index(int i) const { return m_indices[i]; } inline const int& index(size_t i) const { return m_indices[i]; }
static CompressedStorage Map(int* indices, Scalar* values, int size) static CompressedStorage Map(int* indices, Scalar* values, size_t size)
{ {
CompressedStorage res; CompressedStorage res;
res.m_indices = indices; res.m_indices = indices;
@ -125,11 +125,11 @@ class CompressedStorage
} }
/** \returns the largest \c k in [start,end) such that for all \c j in [start,k) index[\c j]\<\a key */ /** \returns the largest \c k in [start,end) such that for all \c j in [start,k) index[\c j]\<\a key */
inline int searchLowerIndex(int start, int end, int key) const inline int searchLowerIndex(size_t start, size_t end, int key) const
{ {
while(end>start) while(end>start)
{ {
int mid = (end+start)>>1; size_t mid = (end+start)>>1;
if (m_indices[mid]<key) if (m_indices[mid]<key)
start = mid+1; start = mid+1;
else else
@ -148,12 +148,12 @@ class CompressedStorage
return m_values[m_size-1]; return m_values[m_size-1];
// ^^ optimization: let's first check if it is the last coefficient // ^^ optimization: let's first check if it is the last coefficient
// (very common in high level algorithms) // (very common in high level algorithms)
const int id = searchLowerIndex(0,m_size-1,key); const size_t id = searchLowerIndex(0,m_size-1,key);
return ((id<m_size) && (m_indices[id]==key)) ? m_values[id] : defaultValue; return ((id<m_size) && (m_indices[id]==key)) ? m_values[id] : defaultValue;
} }
/** Like at(), but the search is performed in the range [start,end) */ /** Like at(), but the search is performed in the range [start,end) */
inline Scalar atInRange(int start, int end, int key, Scalar defaultValue = Scalar(0)) const inline Scalar atInRange(size_t start, size_t end, int key, Scalar defaultValue = Scalar(0)) const
{ {
if (start==end) if (start==end)
return Scalar(0); return Scalar(0);
@ -161,7 +161,7 @@ class CompressedStorage
return m_values[end-1]; return m_values[end-1];
// ^^ optimization: let's first check if it is the last coefficient // ^^ optimization: let's first check if it is the last coefficient
// (very common in high level algorithms) // (very common in high level algorithms)
const int id = searchLowerIndex(start,end-1,key); const size_t id = searchLowerIndex(start,end-1,key);
return ((id<end) && (m_indices[id]==key)) ? m_values[id] : defaultValue; return ((id<end) && (m_indices[id]==key)) ? m_values[id] : defaultValue;
} }
@ -170,11 +170,11 @@ class CompressedStorage
* such that the keys are sorted. */ * such that the keys are sorted. */
inline Scalar& atWithInsertion(int key, Scalar defaultValue = Scalar(0)) inline Scalar& atWithInsertion(int key, Scalar defaultValue = Scalar(0))
{ {
int id = searchLowerIndex(0,m_size,key); size_t id = searchLowerIndex(0,m_size,key);
if (id>=m_size || m_indices[id]!=key) if (id>=m_size || m_indices[id]!=key)
{ {
resize(m_size+1,1); resize(m_size+1,1);
for (int j=m_size-1; j>id; --j) for (size_t j=m_size-1; j>id; --j)
{ {
m_indices[j] = m_indices[j-1]; m_indices[j] = m_indices[j-1];
m_values[j] = m_values[j-1]; m_values[j] = m_values[j-1];
@ -187,9 +187,9 @@ class CompressedStorage
void prune(Scalar reference, RealScalar epsilon = precision<RealScalar>()) void prune(Scalar reference, RealScalar epsilon = precision<RealScalar>())
{ {
int k = 0; size_t k = 0;
int n = size(); size_t n = size();
for (int i=0; i<n; ++i) for (size_t i=0; i<n; ++i)
{ {
if (!ei_isMuchSmallerThan(value(i), reference, epsilon)) if (!ei_isMuchSmallerThan(value(i), reference, epsilon))
{ {
@ -203,11 +203,11 @@ class CompressedStorage
protected: protected:
inline void reallocate(int size) inline void reallocate(size_t size)
{ {
Scalar* newValues = new Scalar[size]; Scalar* newValues = new Scalar[size];
int* newIndices = new int[size]; int* newIndices = new int[size];
int copySize = std::min(size, m_size); size_t copySize = std::min(size, m_size);
// copy // copy
memcpy(newValues, m_values, copySize * sizeof(Scalar)); memcpy(newValues, m_values, copySize * sizeof(Scalar));
memcpy(newIndices, m_indices, copySize * sizeof(int)); memcpy(newIndices, m_indices, copySize * sizeof(int));
@ -222,8 +222,8 @@ class CompressedStorage
protected: protected:
Scalar* m_values; Scalar* m_values;
int* m_indices; int* m_indices;
int m_size; size_t m_size;
int m_allocatedSize; size_t m_allocatedSize;
}; };

View File

@ -231,7 +231,7 @@ class DynamicSparseMatrix
} }
inline DynamicSparseMatrix(const DynamicSparseMatrix& other) inline DynamicSparseMatrix(const DynamicSparseMatrix& other)
: m_innerSize(0) : Base(), m_innerSize(0)
{ {
*this = other.derived(); *this = other.derived();
} }

View File

@ -155,7 +155,7 @@ class SparseMatrix
} }
m_outerIndex[outer+1] = m_outerIndex[outer]; m_outerIndex[outer+1] = m_outerIndex[outer];
} }
assert(m_outerIndex[outer+1] == m_data.size()); assert(size_t(m_outerIndex[outer+1]) == m_data.size());
int id = m_outerIndex[outer+1]; int id = m_outerIndex[outer+1];
++m_outerIndex[outer+1]; ++m_outerIndex[outer+1];
@ -183,9 +183,9 @@ class SparseMatrix
m_outerIndex[outer+1] = m_outerIndex[outer]; m_outerIndex[outer+1] = m_outerIndex[outer];
} }
// std::cerr << this << " " << outer << " " << inner << " - " << m_outerIndex[outer] << " " << m_outerIndex[outer+1] << "\n"; // std::cerr << this << " " << outer << " " << inner << " - " << m_outerIndex[outer] << " " << m_outerIndex[outer+1] << "\n";
assert(m_outerIndex[outer+1] == m_data.size() && "invalid outer index"); assert(size_t(m_outerIndex[outer+1]) == m_data.size() && "invalid outer index");
int startId = m_outerIndex[outer]; size_t startId = m_outerIndex[outer];
int id = m_outerIndex[outer+1]-1; size_t id = m_outerIndex[outer+1]-1;
++m_outerIndex[outer+1]; ++m_outerIndex[outer+1];
float reallocRatio = 1; float reallocRatio = 1;
@ -292,7 +292,7 @@ class SparseMatrix
} }
inline SparseMatrix(const SparseMatrix& other) inline SparseMatrix(const SparseMatrix& other)
: m_outerSize(0), m_innerSize(0), m_outerIndex(0) : Base(), m_outerSize(0), m_innerSize(0), m_outerIndex(0)
{ {
*this = other.derived(); *this = other.derived();
} }

View File

@ -64,13 +64,16 @@ else(GOOGLEHASH_FOUND)
set(EIGEN_MISSING_BACKENDS ${EIGEN_MISSING_BACKENDS} GoogleHash) set(EIGEN_MISSING_BACKENDS ${EIGEN_MISSING_BACKENDS} GoogleHash)
endif(GOOGLEHASH_FOUND) endif(GOOGLEHASH_FOUND)
find_package(Qt4) option(EIGEN_TEST_NOQT "Disable Qt support in unit tests" OFF)
if(QT4_FOUND) if(NOT EIGEN_TEST_NOQT)
include(${QT_USE_FILE}) find_package(Qt4)
set(EIGEN_TESTED_BACKENDS ${EIGEN_TESTED_BACKENDS} "Qt4 support") if(QT4_FOUND)
else(QT4_FOUND) include(${QT_USE_FILE})
set(EIGEN_MISSING_BACKENDS ${EIGEN_MISSING_BACKENDS} "Qt4 support") set(EIGEN_TESTED_BACKENDS ${EIGEN_TESTED_BACKENDS} "Qt4 support")
endif(QT4_FOUND) else(QT4_FOUND)
set(EIGEN_MISSING_BACKENDS ${EIGEN_MISSING_BACKENDS} "Qt4 support")
endif(QT4_FOUND)
endif(NOT EIGEN_TEST_NOQT)
if(CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_COMPILER_IS_GNUCXX)
if(CMAKE_SYSTEM_NAME MATCHES Linux) if(CMAKE_SYSTEM_NAME MATCHES Linux)

View File

@ -24,9 +24,10 @@
#include "sparse.h" #include "sparse.h"
template<typename SetterType,typename DenseType, typename SparseType> template<typename SetterType,typename DenseType, typename Scalar, int Options>
bool test_random_setter(SparseType& sm, const DenseType& ref, const std::vector<Vector2i>& nonzeroCoords) bool test_random_setter(SparseMatrix<Scalar,Options>& sm, const DenseType& ref, const std::vector<Vector2i>& nonzeroCoords)
{ {
typedef SparseMatrix<Scalar,Options> SparseType;
{ {
sm.setZero(); sm.setZero();
SetterType w(sm); SetterType w(sm);

View File

@ -26,6 +26,7 @@
# default: Nightly # default: Nightly
# - EIGEN_WORK_DIR: directory used to download the source files and make the builds # - EIGEN_WORK_DIR: directory used to download the source files and make the builds
# default: folder which contains this script # default: folder which contains this script
# - EIGEN_CMAKE_ARGS: additional arguments passed to cmake
# - CTEST_SOURCE_DIRECTORY: path to eigen's src (use a new and empty folder, not the one you are working on) # - CTEST_SOURCE_DIRECTORY: path to eigen's src (use a new and empty folder, not the one you are working on)
# default: <EIGEN_WORK_DIR>/src # default: <EIGEN_WORK_DIR>/src
# - CTEST_BINARY_DIRECTORY: build directory # - CTEST_BINARY_DIRECTORY: build directory
@ -189,3 +190,7 @@ if(DEFINED EIGEN_EXPLICIT_VECTORIZATION)
message(FATAL_ERROR "Invalid value for EIGEN_EXPLICIT_VECTORIZATION (${EIGEN_EXPLICIT_VECTORIZATION}), must be: novec, SSE2, SSE3, Altivec") message(FATAL_ERROR "Invalid value for EIGEN_EXPLICIT_VECTORIZATION (${EIGEN_EXPLICIT_VECTORIZATION}), must be: novec, SSE2, SSE3, Altivec")
endif(EIGEN_EXPLICIT_VECTORIZATION MATCHES SSE2) endif(EIGEN_EXPLICIT_VECTORIZATION MATCHES SSE2)
endif(DEFINED EIGEN_EXPLICIT_VECTORIZATION) endif(DEFINED EIGEN_EXPLICIT_VECTORIZATION)
if(DEFINED EIGEN_CMAKE_ARGS)
set(CTEST_CMAKE_COMMAND "${CTEST_CMAKE_COMMAND} ${EIGEN_CMAKE_ARGS}")
endif(DEFINED EIGEN_CMAKE_ARGS)