Skip to content

Commit

Permalink
Fix errors and warnings generated by Visual Studio
Browse files Browse the repository at this point in the history
Visual Studio is very good at generating errors (and warnings). This
commit disables sort and reduce_by_key tests for Visual Studio because
this do not work there.
  • Loading branch information
ddemidov committed Dec 24, 2013
1 parent 1efac74 commit cbc3135
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tests/cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ BOOST_AUTO_TEST_CASE(convert_functions)

vex::vector<cl_int2> x(ctx, N);

cl_float2 y = {{4.2, 8.4}};
cl_float2 y = {{4.2f, 8.4f}};

x = vex::convert_int2(y);

Expand Down
7 changes: 5 additions & 2 deletions tests/reduce_by_key.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define BOOST_TEST_MODULE ReduceByKey
#include <algorithm>
#include <numeric>
#include <boost/test/unit_test.hpp>
#include <vexcl/vector.hpp>
#include <vexcl/reduce_by_key.hpp>
Expand Down Expand Up @@ -57,6 +58,7 @@ struct comp {
}
};

#ifndef _MSC_VER // Damn you Visual Studio!
BOOST_AUTO_TEST_CASE(rbk_tuple)
{
const int n = 1000 * 1000;
Expand Down Expand Up @@ -102,8 +104,8 @@ BOOST_AUTO_TEST_CASE(rbk_tuple)
);

int num_keys = vex::reduce_by_key(
std::tie(ikey1, ikey2), ivals,
std::tie(okey1, okey2), ovals,
boost::fusion::vector_tie(ikey1, ikey2), ivals,
boost::fusion::vector_tie(okey1, okey2), ovals,
equal, plus
);

Expand Down Expand Up @@ -134,5 +136,6 @@ BOOST_AUTO_TEST_CASE(rbk_tuple)
BOOST_CHECK_CLOSE(dev_sum, host_sum, 1e-8);
});
}
#endif

BOOST_AUTO_TEST_SUITE_END()
1 change: 1 addition & 0 deletions tests/scan.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define BOOST_TEST_MODULE Scan
#include <algorithm>
#include <numeric>
#include <boost/test/unit_test.hpp>
#include <vexcl/vector.hpp>
#include <vexcl/scan.hpp>
Expand Down
19 changes: 13 additions & 6 deletions tests/sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE(sort_keys_vals)

BOOST_CHECK( std::is_sorted(k.begin(), k.end()) );

struct {
struct even_first_t {
typedef bool result_type;

VEX_FUNCTION(device, bool(int, int),
Expand All @@ -48,6 +48,8 @@ BOOST_AUTO_TEST_CASE(sort_keys_vals)
if (bit1 == bit2) return a < b;
return bit1 < bit2;
}

even_first_t() {}
} even_first;

vex::sort_by_key(keys, vals, even_first);
Expand All @@ -56,6 +58,7 @@ BOOST_AUTO_TEST_CASE(sort_keys_vals)
BOOST_CHECK(std::is_sorted(k.begin(), k.end(), even_first));
}

#ifndef _MSC_VER
BOOST_AUTO_TEST_CASE(sort_keys_tuple)
{
const size_t n = 1000 * 1000;
Expand All @@ -66,7 +69,7 @@ BOOST_AUTO_TEST_CASE(sort_keys_tuple)
vex::vector<int> keys1(ctx, k1);
vex::vector<float> keys2(ctx, k2);

struct {
struct less_t {
typedef bool result_type;

VEX_FUNCTION(device, bool(int, float, int, float),
Expand All @@ -76,9 +79,11 @@ BOOST_AUTO_TEST_CASE(sort_keys_tuple)
result_type operator()(int a1, float a2, int b1, float b2) const {
return (a1 == b1) ? (a2 < b2) : (a1 < b1);
}

less_t() {}
} less;

vex::sort(std::tie(keys1, keys2), less );
vex::sort(boost::fusion::vector_tie(keys1, keys2), less );
vex::copy(keys1, k1);
vex::copy(keys2, k2);

Expand All @@ -104,7 +109,7 @@ BOOST_AUTO_TEST_CASE(sort_keys_vals_tuple)
vex::vector<long> vals1(ctx, v1);
vex::vector<short> vals2(ctx, v2);

struct {
struct less_t {
typedef bool result_type;

VEX_FUNCTION(device, bool(int, float, int, float),
Expand All @@ -114,9 +119,11 @@ BOOST_AUTO_TEST_CASE(sort_keys_vals_tuple)
result_type operator()(int a1, float a2, int b1, float b2) const {
return (a1 == b1) ? (a2 < b2) : (a1 < b1);
}

less_t() {}
} less;

vex::sort_by_key(std::tie(keys1, keys2), std::tie(vals1, vals2), less );
vex::sort_by_key(boost::fusion::vector_tie(keys1, keys2), boost::fusion::vector_tie(vals1, vals2), less );

vex::copy(keys1, k1);
vex::copy(keys2, k2);
Expand All @@ -128,6 +135,6 @@ BOOST_AUTO_TEST_CASE(sort_keys_vals_tuple)
return std::make_tuple(k1[i], k2[i]) < std::make_tuple(k1[j], k2[j]);
} ) );
}

#endif

BOOST_AUTO_TEST_SUITE_END()
5 changes: 4 additions & 1 deletion vexcl/detail/fusion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
#include <boost/fusion/include/swap.hpp>
#include <boost/fusion/include/at_c.hpp>
#include <boost/fusion/include/zip_view.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
#include <boost/fusion/include/vector_tie.hpp>
#ifndef BOOST_NO_VARIADIC_TEMPLATES
# include <boost/fusion/adapted/std_tuple.hpp>
#endif


namespace vex {
Expand Down
7 changes: 7 additions & 0 deletions vexcl/reductor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,17 @@ struct SUM {
struct MAX {
template <typename T>
static T initial() {
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable: 4146)
#endif
if (std::is_unsigned<T>::value)
return static_cast<T>(0);
else
return -std::numeric_limits<T>::max();
#ifdef _MSC_VER
# pragma warning(pop)
#endif
}

template <typename T>
Expand Down
2 changes: 2 additions & 0 deletions vexcl/scan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ void scan(
template <typename T>
struct plus : std::plus<T> {
VEX_FUNCTION(device, T(T, T), "return prm1 + prm2;");

plus() {}
};

/// Inclusive scan.
Expand Down
8 changes: 8 additions & 0 deletions vexcl/sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,8 @@ void sort_by_key_sink(K &&keys, V &&vals, Comp comp) {
template <typename T>
struct less : std::less<T> {
VEX_FUNCTION(device, bool(T, T), "return prm1 < prm2;");

less() {}
};

/// Function object class for less-than-or-equal inequality comparison.
Expand All @@ -2223,6 +2225,8 @@ struct less : std::less<T> {
template <typename T>
struct less_equal : std::less_equal<T> {
VEX_FUNCTION(device, bool(T, T), "return prm1 <= prm2;");

less_equal() {}
};

/// Function object class for greater-than inequality comparison.
Expand All @@ -2234,6 +2238,8 @@ struct less_equal : std::less_equal<T> {
template <typename T>
struct greater : std::greater<T> {
VEX_FUNCTION(device, bool(T, T), "return prm1 > prm2;");

greater() {}
};

/// Function object class for greater-than-or-equal inequality comparison.
Expand All @@ -2245,6 +2251,8 @@ struct greater : std::greater<T> {
template <typename T>
struct greater_equal : std::greater_equal<T> {
VEX_FUNCTION(device, bool(T, T), "return prm1 >= prm2;");

greater_equal() {}
};

/// Sorts the vector into ascending order.
Expand Down
2 changes: 1 addition & 1 deletion vexcl/spmat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class SpMat {
mtx[d].reset(
new SpMatCSR(queue[d],
row + part[d], row + part[d+1], col, val,
col_part[d], col_part[d+1], ghost_cols[d])
static_cast<col_t>(col_part[d]), static_cast<col_t>(col_part[d+1]), ghost_cols[d])
);
else
mtx[d].reset(
Expand Down
2 changes: 1 addition & 1 deletion vexcl/stencil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ void stencil<T>::apply(const vex::vector<T> &x, vex::vector<T> &y,
{
Base::exchange_halos(x);

T beta = append ? 1 : 0;
T beta = static_cast<T>(append ? 1 : 0);

for(unsigned d = 0; d < queue.size(); d++) {
if (size_t psize = x.part_size(d)) {
Expand Down

0 comments on commit cbc3135

Please sign in to comment.