Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
samiBendou committed Jan 13, 2019
2 parents 1ddb1dd + 44f0ee1 commit fc0c9c9
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 64 deletions.
60 changes: 38 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,56 @@
dist: trusty
language: cpp

branches:
only:
- master
env:
global:
os: linux
dist: trusty
sudo: true

matrix:
include:
compiler:
- gcc

- gcc
- clang
addons:
apt:
sources:
- ubuntu-toolchain-r-test

- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-5.0
packages:
- g++-8
- lcov
- ggcov
- doxygen
- g++-8
- clang-5.0
- lcov
- ggcov
- doxygen

before_install:
#Clone googletest to run unit tests and benchmarks
- git clone --depth 1 https://github.com/google/googletest ./TestsMathToolKitCPP/lib/
- pip install --upgrade --user git+https://github.com/samiBendou/cpp-coveralls
#Clone googletest to run unit tests and benchmarks
- git clone --depth 1 https://github.com/google/googletest ./TestsMathToolKitCPP/lib/
- pip install --upgrade --user git+https://github.com/samiBendou/cpp-coveralls
- # Combine global build options with OS/compiler-dependent options
- export CMAKE_OPTIONS= ${ENV_CMAKE_OPTIONS}
- export CXX_FLAGS= ${ENV_CXX_FLAGS}

install:
- if [ "$CXX" = "clang++" ] && [ "$TRAVIS_OS_NAME" = "linux" ]; then export CXX="clang++-5.0" CC="clang-5.0"; fi
- if [ "$CXX" = "g++" ] && [ "$TRAVIS_OS_NAME" = "linux" ]; then export CXX="g++-8" CC="gcc-8"; fi
- echo ${PATH}
- echo ${CXX}
- ${CXX} --version
- ${CXX} -v

script:
- CXX=/usr/bin/g++-8 CC=/usr/bin/gcc-8 cmake -DCOVERAGE=1
- cmake --build .
- ./TestsMathToolKitCPP/TestNAlgebra/TestNAlgebra
- doxygen -u Doxyfile
- doxygen Doxyfile

- cmake ${CMAKE_OPTIONS} -DCMAKE_CXX_FLAGS=${CXX_FLAGS} -DCOVERAGE=1
- cmake --build .
- ./TestsMathToolKitCPP/TestNAlgebra/TestNAlgebra
- doxygen -u Doxyfile
- doxygen Doxyfile

after_success:
- ls ./TestsMathToolKitCPP/TestNAlgebra/CMakeFiles/TestNAlgebra.dir
- sudo ln -sf /usr/bin/gcov-8 /usr/bin/gcov
- coveralls --root . --gcov-options '\-l' -E ".*CMakeFiles.*" -E ".*gtest.*" -E ".*google*"
- sudo ln -sf /usr/bin/gcov-8 /usr/bin/gcov
- coveralls --root . --gcov-options '\-l' -E ".*CMakeFiles.*" -E ".*gtest.*" -E ".*google*"

deploy:
provider: pages
Expand Down
15 changes: 10 additions & 5 deletions MathToolKit/NAlgebra/header/NPMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -804,11 +804,15 @@ class NPMatrix : public NVector<T> {

// LUP MANAGEMENT

void lupCopy() const;
void lupClear() const;

void lupUpdate() const;
void lupReset() const;

void lupClear() const;
void lupCopy(const NPMatrix &m) const;

inline void lupSelfCopy() const{ lupCopy(*this);};

void lupUpdate() const;

// MUTABLE VARIABLES MANAGEMENT

Expand Down Expand Up @@ -892,6 +896,7 @@ class NPMatrix : public NVector<T> {

size_t _p{};


// SUB MATRICES INDICES INDICES

mutable size_t _i1{};
Expand All @@ -908,13 +913,13 @@ class NPMatrix : public NVector<T> {
* @brief Matrix \f$ A = LU \f$ where \f$ PA = LU \f$ = this.
* @details `_a` points to the \f$ A \f$ NMatrix or to `nullptr` if the matrix don't have \f$ LU \f$ decomposition.
*/
mutable NPMatrix<T> *_a;
mutable unique_ptr<NPMatrix<T>> _a{};

/**
* @brief permutation vector \f$ P \f$ such as \f$ PA = LU \f$.
* @details Represented as `unsigned long` array.
*/
mutable vector<size_t> *_perm{};
mutable unique_ptr<vector<size_t>> _perm{};
};
/** @} */

Expand Down
9 changes: 9 additions & 0 deletions MathToolKit/NAlgebra/header/NVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,15 @@ class NVector : public std::vector<T> {
* @return \f$ \alpha u + \beta v + ... + \lambda x \f$.
*/
static NVector<T> sumProd(const std::vector<T> &scalars, const std::vector<NVector> &vectors);
/**
*
* @param x start value of the range
* @param y end value of the range
* @param h step between elements
* @brief Vector with regularly spaced components
* @return Returns \f$ ( x, x + h, x + 2h, ..., y) \f$
*/
// static NVector<T> linspace(T x, T y, T h) {return NVector<T>();}

protected:

Expand Down
1 change: 1 addition & 0 deletions MathToolKit/NAlgebra/header/thirdparty.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
#include <AESByte.h>
#include <Pixel.h>
#include <typedef.h>
#include <memory>

#endif //FACEDETECTION_THIRDPARTY_H
74 changes: 40 additions & 34 deletions MathToolKit/NAlgebra/source/NPMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,32 +557,53 @@ NVector<T> &NPMatrix<T>::solve(NVector<T> &u) const {

// LUP MANAGEMENT


template<typename T>
void NPMatrix<T>::lupUpdate() const {
//Returns PA such as PA = LU where P is a row p array and A = L * U;
size_t i, j, k, i_max;
void NPMatrix<T>::lupClear() const {
if(_a != nullptr){
_a.reset(nullptr);
_perm.reset(nullptr);
}
}

template<typename T>
void NPMatrix<T>::lupReset() const {
lupClear();
_a.reset(new NPMatrix<T>(subMatrix(_i1, _j1, _i2, _j2)));
_perm.reset(new vector<size_t>(_a->_n + 1, 0));
for (size_t i = 0; i <= _a->_n; ++i)
(*_perm)[i] = i; //Unit p permutation, p[i] initialized with i
}

_a = new NPMatrix<T>(subMatrix(_i1, _j1, _i2, _j2));
auto *p = new vector<size_t>();
template<typename T>
void NPMatrix<T>::lupCopy(const NPMatrix &m) const {
if(m._a > nullptr) {
_a.reset(new NPMatrix<T>(*(m._a)));
_perm.reset(new vector<size_t>(m._perm->begin(), m._perm->end()));
} else {
lupClear();
}

for (i = 0; i <= _a->_n; ++i)
p->push_back(i); //Unit p permutation, p[i] initialized with i
}

template<typename T>
void NPMatrix<T>::lupUpdate() const {
//Returns PA such as PA = LU where P is a row p array and A = L * U;
size_t i, j, k, i_max;

lupReset();
if (!_a->isUpper() || !_a->isLower()) {
for (i = 0; i < _a->_n; ++i) {
i_max = _a->col(i)(i, _a->_n - 1).maxAbsIndex() + i;
if (abs((*_a)(i_max, i)) > EPSILON) { //matrix is not de
// generate
if (abs((*_a)(i_max, i)) > EPSILON) { //matrix is not degenerate
if (i_max != i) {
j = (*p)[i];
(*p)[i] = (*p)[i_max];
(*p)[i_max] = j;
j = (*_perm)[i];
(*_perm)[i] = (*_perm)[i_max];
(*_perm)[i_max] = j;

_a->swapRow(i, i_max);

(*p)[_a->_n]++; //counting pivots starting from a->_n (for determinant)
(*_perm)[_a->_n]++; //counting pivots starting from a->_n (for determinant)
}
} else {
lupClear();
Expand All @@ -596,27 +617,8 @@ void NPMatrix<T>::lupUpdate() const {
}
}
}
_perm = p;
}

template<typename T>
void NPMatrix<T>::lupCopy() const {
if (_a != nullptr && _perm != nullptr) {
_a = new NPMatrix<T>(*(_a));
_perm = new vector<size_t>(_n);
std::copy(_perm, _perm + _n, _perm);
}
}

template<typename T>
void NPMatrix<T>::lupClear() const {
if (_a != nullptr) {
delete _a;
delete _perm;
_a = nullptr;
_perm = nullptr;
}
}

// CHARACTERIZATION

Expand Down Expand Up @@ -647,7 +649,7 @@ NPMatrix<T> &NPMatrix<T>::copy(const NPMatrix<T> &m) {
vector<T>::operator=(m);
_n = m._n;
_p = m._p;
lupCopy();
lupCopy(m);
} else if (hasDefaultBrowseIndices()) {
vector<T>::operator=(m.subMatrix(m._i1, m._j1, m._i2, m._j2));
_n = m._i2 - m._i1 + 1;
Expand All @@ -657,8 +659,9 @@ NPMatrix<T> &NPMatrix<T>::copy(const NPMatrix<T> &m) {
setSubMatrix(m);
lupClear();
}
cleanBoth(m);
}
setDefaultBrowseIndices();
m.setDefaultBrowseIndices();
return *this;
}

Expand Down Expand Up @@ -714,6 +717,9 @@ NPMatrix<T> &NPMatrix<T>::forEach(T s, const function<void(T &, T)> &binary_op)
return clean();
}




template
class NPMatrix<double_t>;

Expand Down
9 changes: 6 additions & 3 deletions TestsMathToolKitCPP/TestNAlgebra/TestNPMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,15 @@ TEST_F(NPMatrixTest, Inv) {
}

TEST_F(NPMatrixTest, Det) {
mat_t inv_b{_b ^ -1}, opp_a{-_a}, expect_eye{(_b * inv_b)};

ASSERT_DOUBLE_EQ((double) _a.det(), 1);
ASSERT_DOUBLE_EQ((double) (-_a).det(), -1);
ASSERT_DOUBLE_EQ((double) opp_a.det(), -1);

ASSERT_DOUBLE_EQ((double) _b.det(), 4);
ASSERT_DOUBLE_EQ((double) (_b ^ -1).det(), 0.25);
ASSERT_DOUBLE_EQ((double) (_b * (_b ^ -1)).det(), 1);

ASSERT_DOUBLE_EQ((double) inv_b.det(), 0.25);
ASSERT_DOUBLE_EQ((double) expect_eye.det(), 1);

ASSERT_DOUBLE_EQ((double) _c.det(), 0);
}
Expand Down

0 comments on commit fc0c9c9

Please sign in to comment.