Permalink
Browse files

Fix for no Eigen

  • Loading branch information...
costashatz committed Oct 23, 2016
1 parent c6fdd47 commit 614ec1a9f434e2c1fb0a81cd4e161d4200ba7fd2
Showing with 23 additions and 0 deletions.
  1. +21 −0 sferes/modif/novelty.hpp
  2. +2 −0 tests/wscript
View
@@ -35,7 +35,12 @@
#ifndef MODIFIER_NOVELTY_HPP
#define MODIFIER_NOVELTY_HPP
#ifdef EIGEN3_ENABLED
#include <Eigen/Core>
#else
#include <vector>
#endif
#include "sferes/parallel.hpp"
namespace sferes {
@@ -48,18 +53,30 @@ namespace sferes {
typedef std::vector<boost::shared_ptr<Phen> > pop_t;
const pop_t& _pop;
const pop_t& _archive;
#ifdef EIGEN3_ENABLED
Eigen::MatrixXf& distances;
#else
std::vector<std::vector<float> > distances;
#endif
~_distance_f() { }
#ifdef EIGEN3_ENABLED
_distance_f(const pop_t& pop, const pop_t& archive, Eigen::MatrixXf& d) :
#else
_distance_f(const pop_t& pop, const pop_t& archive, std::vector<std::vector<float> >& d) :
#endif
_pop(pop), _archive(archive), distances(d) {}
_distance_f(const _distance_f& ev) :
_pop(ev._pop), _archive(ev._archive), distances(ev.distances) {}
void operator() (const parallel::range_t& r) const {
for (size_t i = r.begin(); i != r.end(); ++i) {
for (size_t j = 0; j < _archive.size(); ++j)
#ifdef EIGEN3_ENABLED
distances(i, j) = _pop[i]->fit().dist(*_archive[j]);
#else
distances[i][j] = _pop[i]->fit().dist(*_archive[j]);
#endif
}
}
};
@@ -96,7 +113,11 @@ namespace sferes {
archive.insert(archive.end(), ea.pop().begin(), ea.pop().end());
// we compute all the distances from pop(i) to archive(j) and store them
#ifdef EIGEN3_ENABLED
Eigen::MatrixXf distances(ea.pop().size(), archive.size());
#else
std::vector<std::vector<float> > distances(ea.pop().size(), std::vector<float>(archive.size()));
#endif
novelty::_distance_f<Phen> f(ea.pop(), archive, distances);
parallel::init();
parallel::p_for(parallel::range_t(0, ea.pop().size()), f);
View
@@ -43,6 +43,8 @@ def build(bld):
for f in files:
fname = f.replace('/', '_')
fname = fname[0:-4]
if not bld.env['EIGEN_FOUND'] and (fname == 'tests_ea_cmaes' or fname == 'tests_modif_diversity' or fname == 'tests_modif_novelty'):
continue
bld.program(features = 'cxx test',
source = '../' + f,
includes = '../',

0 comments on commit 614ec1a

Please sign in to comment.