Commit 18c9e684 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Merge branch 'development/fix-vs2019' into 'dev'

Compilation fixes for VS 2019

See merge request !83
parents 7954fdac a2e32f52
Pipeline #14837 passed with stages
in 4 minutes and 29 seconds
......@@ -58,11 +58,16 @@ endif()
#### MSVC Compiler Configuration
if (MSVC)
## This hack is for Ninja generator from VS CODE
string(REGEX REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
##
add_compile_options("/wd4458" # masque le membre de classe
"/wd4456" # masque la déclaration locale précédente
"/wd5030" # l'attribut 'noinline' n'est pas reconnu
"/wd4457" # la déclaration de '?' masque le paramètre de fonction
)
add_compile_options("/WX" "/W4" "/wd4244" "/wd4127" "/permissive-")
add_compile_definitions(_SCL_SECURE_NO_WARNINGS)
add_compile_definitions(_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
......
link_libraries(${FreeImage_LIBRARIES})
add_definitions(-DMLN_IMG_PATH="$(CMAKE_SOURCE_DIR)/img/")
add_compile_definitions(MLN_IMG_PATH="${CMAKE_SOURCE_DIR}/img/")
add_executable(meaningfullness meaningfullness.cpp)
add_test(meaningfullness meaningfullness)
\ No newline at end of file
link_libraries(${FreeImage_LIBRARIES})
add_definitions(-DMLN_IMG_PATH="$(CMAKE_SOURCE_DIR)/img/")
add_compile_definitions(MLN_IMG_PATH="${CMAKE_SOURCE_DIR}/img/")
add_executable(mumford_shah mumford_shah.cpp)
add_test(mumford_shah mumford_shah)
\ No newline at end of file
find_package(benchmark)
add_definitions(-DMLN_IMG_PATH="${CMAKE_SOURCE_DIR}/img/")
add_compile_definitions(MLN_IMG_PATH="${CMAKE_SOURCE_DIR}/img/")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
......
......@@ -10,56 +10,47 @@
*
*/
#define MLN_VEC_PROMOTE_FUN(T, dim, tag, fun) internal::vec_base<decltype(fun(std::declval<T>())), dim, tag>
#define MLN_PROMOTE(T1, T2) decltype(std::declval<T1>() + std::declval<T2>())
#define MLN_PROMOTE_FUN(T, fun) decltype(fun(std::declval<T>()))
#define MLN_PROMOTE_FUNCOMP(T, f, g) decltype(f(g(std::declval<T>())))
namespace mln
{
namespace details
{
template <class U, class V = U>
using _promote_t = decltype(std::declval<U>() + std::declval<V>());
}
/* Element wise operators */
template <class U, class V, unsigned dim, class tag>
internal::vec_base<decltype(pow(std::declval<U>(), std::declval<V>())), dim, tag>
pow(const internal::vec_base<U, dim, tag>& x, V exp);
pow(const internal::vec_base<U, dim, tag>& x, V exp);
template <class T, unsigned dim, class tag>
MLN_VEC_PROMOTE_FUN(T, dim, tag, sqr)
sqr(const internal::vec_base<T, dim, tag>& x);
auto sqr(const internal::vec_base<T, dim, tag>& x);
template <class T, unsigned dim, class tag>
MLN_VEC_PROMOTE_FUN(T, dim, tag, abs)
abs(const internal::vec_base<T, dim, tag>& x);
auto abs(const internal::vec_base<T, dim, tag>& x);
template <class T, unsigned dim, class tag>
MLN_VEC_PROMOTE_FUN(T, dim, tag, sqrt)
sqrt(const internal::vec_base<T, dim, tag>& x);
auto sqrt(const internal::vec_base<T, dim, tag>& x);
template <class T, unsigned dim, class tag>
MLN_VEC_PROMOTE_FUN(T, dim, tag, cqrt)
cbrt(const internal::vec_base<T, dim, tag>& x);
auto cbrt(const internal::vec_base<T, dim, tag>& x);
/* algebraic operators */
template <class U, class V, unsigned dim, class tag>
MLN_PROMOTE(U, V)
dot(const internal::vec_base<U, dim, tag>& x, const internal::vec_base<V, dim, tag>& y);
auto dot(const internal::vec_base<U, dim, tag>& x, const internal::vec_base<V, dim, tag>& y)
-> details::_promote_t<U, V>;
template <class U, class V, class tag>
internal::vec_base<MLN_PROMOTE(U, V), 3, tag> cross(const internal::vec_base<U, 3, tag>& x,
const internal::vec_base<V, 3, tag>& y);
auto cross(const internal::vec_base<U, 3, tag>& x, const internal::vec_base<V, 3, tag>& y)
-> internal::vec_base<details::_promote_t<U, V>, 3, tag>;
/* Reduction operators */
template <typename T, unsigned dim, class tag>
MLN_PROMOTE(T, T)
sum(const internal::vec_base<T, dim, tag>& x);
auto sum(const internal::vec_base<T, dim, tag>& x) -> details::_promote_t<T>;
template <typename T, unsigned dim, class tag>
MLN_PROMOTE(T, T)
prod(const internal::vec_base<T, dim, tag>& x);
auto prod(const internal::vec_base<T, dim, tag>& x) -> details::_promote_t<T>;
template <typename T, unsigned dim, class tag>
T maximum(const internal::vec_base<T, dim, tag>& x);
......@@ -68,39 +59,31 @@ namespace mln
T minimum(const internal::vec_base<T, dim, tag>& x);
template <typename T, unsigned dim, class tag>
MLN_PROMOTE_FUN(T, abs)
l0norm(const internal::vec_base<T, dim, tag>& x);
auto l0norm(const internal::vec_base<T, dim, tag>& x);
template <typename T, unsigned dim, class tag>
MLN_PROMOTE_FUN(T, abs)
linfnorm(const internal::vec_base<T, dim, tag>& x);
auto linfnorm(const internal::vec_base<T, dim, tag>& x);
template <typename T, unsigned dim, class tag>
MLN_PROMOTE_FUN(T, abs)
l1norm(const internal::vec_base<T, dim, tag>& x);
auto l1norm(const internal::vec_base<T, dim, tag>& x);
template <typename T, unsigned dim, class tag>
MLN_PROMOTE_FUNCOMP(T, sqrt, sqr)
l2norm(const internal::vec_base<T, dim, tag>& x);
auto l2norm(const internal::vec_base<T, dim, tag>& x);
template <typename T, unsigned dim, class tag>
inline MLN_PROMOTE_FUN(T, sqr) l2norm_sqr(const internal::vec_base<T, dim, tag>& x);
auto l2norm_sqr(const internal::vec_base<T, dim, tag>& x);
template <unsigned p, typename T, unsigned dim, class tag>
MLN_PROMOTE_FUNCOMP(T, pow, abs)
lpnorm(const internal::vec_base<T, dim, tag>& x);
auto lpnorm(const internal::vec_base<T, dim, tag>& x);
template <typename T, unsigned dim, class tag>
inline auto l1dist(const internal::vec_base<T, dim, tag>& x, const internal::vec_base<T, dim, tag>& y)
-> decltype(l1norm(x - y));
auto l1dist(const internal::vec_base<T, dim, tag>& x, const internal::vec_base<T, dim, tag>& y);
template <typename T, unsigned dim, class tag>
inline auto l2dist(const internal::vec_base<T, dim, tag>& x, const internal::vec_base<T, dim, tag>& y)
-> decltype(l2norm(x - y));
auto l2dist(const internal::vec_base<T, dim, tag>& x, const internal::vec_base<T, dim, tag>& y);
template <typename T, unsigned dim, class tag>
inline auto l2dist_sqr(const internal::vec_base<T, dim, tag>& x, const internal::vec_base<T, dim, tag>& y)
-> decltype(l2norm_sqr(x - y));
auto l2dist_sqr(const internal::vec_base<T, dim, tag>& x, const internal::vec_base<T, dim, tag>& y);
/*****************************/
/** Implementation ***/
......@@ -108,9 +91,10 @@ namespace mln
#define MLN_GEN_CODE(FUN) \
template <class T, unsigned dim, class tag> \
inline MLN_VEC_PROMOTE_FUN(T, dim, tag, FUN) FUN(const internal::vec_base<T, dim, tag>& x) \
auto FUN(const internal::vec_base<T, dim, tag>& x) \
{ \
MLN_VEC_PROMOTE_FUN(T, dim, tag, FUN) res; \
using R = decltype(FUN(std::declval<T>())); \
internal::vec_base<R, dim, tag> res; \
for (unsigned i = 0; i < dim; ++i) \
res[i] = FUN(x[i]); \
return res; \
......@@ -118,8 +102,7 @@ namespace mln
#define MLN_GEN_BINARY_CODE(FUN, FUNBASE, EXPR) \
template <class T, unsigned dim, class tag> \
inline auto FUN(const internal::vec_base<T, dim, tag>& x, const internal::vec_base<T, dim, tag>& y) \
->decltype(FUNBASE(EXPR)) \
auto FUN(const internal::vec_base<T, dim, tag>& x, const internal::vec_base<T, dim, tag>& y) \
{ \
return FUNBASE(EXPR); \
}
......@@ -145,42 +128,42 @@ namespace mln
}
template <class U, class V, unsigned dim, class tag>
MLN_PROMOTE(U, V)
dot(const internal::vec_base<U, dim, tag>& x, const internal::vec_base<V, dim, tag>& y)
auto dot(const internal::vec_base<U, dim, tag>& x, const internal::vec_base<V, dim, tag>& y)
-> details::_promote_t<U, V>
{
MLN_PROMOTE(U, V) res = 0;
details::_promote_t<U, V> res = 0;
for (int i = 0; i < dim; ++i)
res += x[i] * y[i];
return res;
}
template <class U, class V, class tag>
internal::vec_base<MLN_PROMOTE(U, V), 3, tag> cross(const internal::vec_base<U, 3, tag>& u,
const internal::vec_base<V, 3, tag>& v)
auto cross(const internal::vec_base<U, 3, tag>& u, const internal::vec_base<V, 3, tag>& v)
-> internal::vec_base<details::_promote_t<U, V>, 3, tag>
{
return {u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]};
}
template <typename T, unsigned dim, class tag>
inline MLN_PROMOTE(T, T) sum(const internal::vec_base<T, dim, tag>& x)
auto sum(const internal::vec_base<T, dim, tag>& x) -> details::_promote_t<T>
{
MLN_PROMOTE(T, T) res = x[0];
details::_promote_t<T> res = x[0];
for (unsigned i = 1; i < dim; ++i)
res += x[i];
return res;
}
template <typename T, unsigned dim, class tag>
inline MLN_PROMOTE(T, T) prod(const internal::vec_base<T, dim, tag>& x)
auto prod(const internal::vec_base<T, dim, tag>& x) -> details::_promote_t<T>
{
MLN_PROMOTE(T, T) res = x[0];
details::_promote_t<T> res = x[0];
for (unsigned i = 1; i < dim; ++i)
res *= x[i];
return res;
}
template <typename T, unsigned dim, class tag>
inline T maximum(const internal::vec_base<T, dim, tag>& x)
T maximum(const internal::vec_base<T, dim, tag>& x)
{
T res = x[0];
for (unsigned i = 1; i < dim; ++i)
......@@ -190,7 +173,7 @@ namespace mln
}
template <typename T, unsigned dim, class tag>
inline T minimum(const internal::vec_base<T, dim, tag>& x)
T minimum(const internal::vec_base<T, dim, tag>& x)
{
T res = x[0];
for (unsigned i = 1; i < dim; ++i)
......@@ -200,13 +183,12 @@ namespace mln
}
template <typename T, unsigned dim, class tag>
inline MLN_PROMOTE_FUN(T, abs) l0norm(const internal::vec_base<T, dim, tag>& x)
auto l0norm(const internal::vec_base<T, dim, tag>& x)
{
typedef MLN_PROMOTE_FUN(T, abs) U;
U res = abs(x[0]);
auto res = abs(x[0]);
for (unsigned i = 1; i < dim; ++i)
{
U v = abs(x[i]);
auto v = abs(x[i]);
if (v < res)
res = v;
}
......@@ -214,13 +196,12 @@ namespace mln
}
template <typename T, unsigned dim, class tag>
inline MLN_PROMOTE_FUN(T, abs) linfnorm(const internal::vec_base<T, dim, tag>& x)
auto linfnorm(const internal::vec_base<T, dim, tag>& x)
{
typedef MLN_PROMOTE_FUN(T, abs) U;
U res = abs(x[0]);
auto res = abs(x[0]);
for (unsigned i = 1; i < dim; ++i)
{
U v = abs(x[i]);
auto v = abs(x[i]);
if (res < v)
res = v;
}
......@@ -228,41 +209,36 @@ namespace mln
}
template <typename T, unsigned dim, class tag>
inline MLN_PROMOTE_FUN(T, abs) l1norm(const internal::vec_base<T, dim, tag>& x)
auto l1norm(const internal::vec_base<T, dim, tag>& x)
{
typedef MLN_PROMOTE_FUN(T, abs) U;
U res = abs(x[0]);
auto res = abs(x[0]);
for (unsigned i = 1; i < dim; ++i)
res += abs(x[i]);
return res;
}
template <typename T, unsigned dim, class tag>
inline MLN_PROMOTE_FUNCOMP(T, sqrt, sqr) l2norm(const internal::vec_base<T, dim, tag>& x)
auto l2norm(const internal::vec_base<T, dim, tag>& x)
{
typedef MLN_PROMOTE_FUNCOMP(T, sqrt, sqr) U;
U res = sqr(x[0]);
auto res = sqr(x[0]);
for (unsigned i = 1; i < dim; ++i)
res += sqr(x[i]);
return sqrt(res);
}
template <typename T, unsigned dim, class tag>
inline MLN_PROMOTE_FUN(T, sqr) l2norm_sqr(const internal::vec_base<T, dim, tag>& x)
auto l2norm_sqr(const internal::vec_base<T, dim, tag>& x)
{
typedef MLN_PROMOTE_FUNCOMP(T, sqrt, sqr) U;
U res = sqr(x[0]);
auto res = sqr(x[0]);
for (unsigned i = 1; i < dim; ++i)
res += sqr(x[i]);
return res;
}
template <unsigned p, typename T, unsigned dim, class tag>
MLN_PROMOTE_FUNCOMP(T, pow, abs)
lpnorm(const internal::vec_base<T, dim, tag>& x)
auto lpnorm(const internal::vec_base<T, dim, tag>& x)
{
typedef MLN_PROMOTE_FUNCOMP(T, pow, abs) U;
U res = pow(abs(x[0]), p);
auto res = pow(abs(x[0]), p);
for (unsigned i = 1; i < dim; ++i)
res += pow(abs(x[i]), p);
return pow(res, 1 / p);
......@@ -271,8 +247,5 @@ namespace mln
#undef MLN_GEN_CODE
#undef MLN_GEN_BINARY_CODE
#undef MLN_VEC_PROMOTE_FUN
#undef MLN_VEC_PROMOTE
#undef MLN_PROMOTE_FUNCOMP
#endif // ! MLN_CORE_VEC_VEC_MATH_OPS_HPP
......@@ -18,7 +18,7 @@ namespace mln
struct winc4_t : dyn_neighborhood_base<constant_neighborhood_tag, winc4_t>
{
constexpr const std::array<point2d, 5>& offsets() { return dpoints; }
constexpr const std::array<point2d, 5>& offsets() const { return dpoints; }
static const int static_size = 5;
static const std::array<point2d, 5> dpoints;
};
......@@ -29,7 +29,7 @@ namespace mln
struct winc8_t : dyn_neighborhood_base<constant_neighborhood_tag, winc8_t>
{
constexpr const std::array<point2d, 9>& offsets() { return dpoints; }
constexpr const std::array<point2d, 9>& offsets() const { return dpoints; }
static const int static_size = 9;
static const std::array<point2d, 9> dpoints;
};
......@@ -41,7 +41,7 @@ namespace mln
struct winc2_v_t : dyn_neighborhood_base<constant_neighborhood_tag, winc2_v_t>
{
constexpr const std::array<point2d, 3>& offsets() { return dpoints; }
constexpr const std::array<point2d, 3>& offsets() const { return dpoints; }
static const int static_size = 3;
static const std::array<point2d, 3> dpoints;
};
......@@ -52,7 +52,7 @@ namespace mln
struct winc2_h_t : dyn_neighborhood_base<constant_neighborhood_tag, winc2_h_t>
{
constexpr const std::array<point2d, 3>& offsets() { return dpoints; }
constexpr const std::array<point2d, 3>& offsets() const { return dpoints; }
static const int static_size = 3;
static const std::array<point2d, 3> dpoints;
};
......
......@@ -135,14 +135,9 @@ namespace mln
{
// VISUAL STUDIO does not support constexpr pointer to function
// static constexpr void (*ptr) (void*,void*,std::size_t) = &value_convert<VIN, VOUT>;
static void (*const ptr)(void*, void*, std::size_t);
static constexpr void (*const ptr)(void*, void*, std::size_t) = &value_convert<VIN, VOUT>;
};
template <typename VIN, typename VOUT>
void(*const default_converter < VIN, VOUT,
typename std::enable_if<std::is_scalar<VIN>::value and std::is_scalar<VOUT>::value and
value_traits<VIN>::quant<value_traits<VOUT>::quant>::type>::ptr)(
void*, void*, std::size_t) = &value_convert<VIN, VOUT>;
#define MLN_INTERNAL_CONV_EXPAND(r, data, VIN) \
if (sidx == typeid(VIN)) \
......
......@@ -162,7 +162,7 @@ namespace mln
/*********************************/
template <typename T, std::size_t nLevel, typename Allocator, bool queue>
inline bounded_hqueue<T, nLevel, Allocator, queue, typename std::enable_if<(nLevel > 16)>::type>::bounded_hqueue()
inline bounded_hqueue<T, nLevel, Allocator, queue, std::enable_if_t<(nLevel > 16)>>::bounded_hqueue()
: m_q(NULL), m_end(NULL)
{
m_head.resize(nLevel);
......@@ -170,14 +170,14 @@ namespace mln
}
template <typename T, std::size_t nLevel, typename Allocator, bool queue>
inline bounded_hqueue<T, nLevel, Allocator, queue, typename std::enable_if<(nLevel > 16)>::type>::bounded_hqueue(
inline bounded_hqueue<T, nLevel, Allocator, queue, std::enable_if_t<(nLevel > 16)>>::bounded_hqueue(
const size_t* histo)
{
init(histo);
}
template <typename T, std::size_t nLevel, typename Allocator, bool queue>
inline bounded_hqueue<T, nLevel, Allocator, queue, typename std::enable_if<(nLevel > 16)>::type>::~bounded_hqueue()
inline bounded_hqueue<T, nLevel, Allocator, queue, std::enable_if_t<(nLevel > 16)>>::~bounded_hqueue()
{
if (m_q != NULL)
{
......@@ -189,7 +189,7 @@ namespace mln
}
template <typename T, std::size_t nLevel, typename Allocator, bool queue>
inline void bounded_hqueue<T, nLevel, Allocator, queue, typename std::enable_if<(nLevel > 16)>::type>::init(
inline void bounded_hqueue<T, nLevel, Allocator, queue, std::enable_if_t<(nLevel > 16)>>::init(
const size_t* histo)
{
mln_precondition(m_q == NULL);
......@@ -206,7 +206,7 @@ namespace mln
}
template <typename T, std::size_t nLevel, typename Allocator, bool queue>
inline bool bounded_hqueue<T, nLevel, Allocator, queue, typename std::enable_if<(nLevel > 16)>::type>::empty(
inline bool bounded_hqueue<T, nLevel, Allocator, queue, std::enable_if_t<(nLevel > 16)>>::empty(
unsigned level) const
{
mln_precondition(level < nLevel);
......@@ -214,7 +214,7 @@ namespace mln
}
template <typename T, std::size_t nLevel, typename Allocator, bool queue>
inline void bounded_hqueue<T, nLevel, Allocator, queue, typename std::enable_if<(nLevel > 16)>::type>::push_at_level(
inline void bounded_hqueue<T, nLevel, Allocator, queue, std::enable_if_t<(nLevel > 16)>>::push_at_level(
const T& x, unsigned level)
{
mln_precondition(level < nLevel);
......@@ -223,7 +223,7 @@ namespace mln
}
template <typename T, std::size_t nLevel, typename Allocator, bool queue>
inline T bounded_hqueue<T, nLevel, Allocator, queue, typename std::enable_if<(nLevel > 16)>::type>::pop_at_level(
inline T bounded_hqueue<T, nLevel, Allocator, queue, std::enable_if_t<(nLevel > 16)>>::pop_at_level(
unsigned level)
{
mln_precondition(level < nLevel);
......@@ -243,7 +243,7 @@ namespace mln
}
template <typename T, std::size_t nLevel, typename Allocator, bool queue>
inline T bounded_hqueue<T, nLevel, Allocator, queue, typename std::enable_if<(nLevel > 16)>::type>::top_at_level(
inline T bounded_hqueue<T, nLevel, Allocator, queue, std::enable_if_t<(nLevel > 16)>>::top_at_level(
unsigned level) const
{
mln_precondition(level < nLevel);
......
project(tests)
# add link flag to test framework
add_definitions(-DMLN_IMG_PATH="${CMAKE_SOURCE_DIR}/img/")
add_compile_definitions(MLN_IMG_PATH="${CMAKE_SOURCE_DIR}/img/")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment