Commit 1e3fc247 authored by Pietro Incardona's avatar Pietro Incardona

Adding Vector operators file

parent 29d4f607
SUBDIRS = src
bin_PROGRAMS =
\ No newline at end of file
bin_PROGRAMS =
test:
cd src && make test
......@@ -10,3 +10,7 @@ nobase_include_HEADERS = PSE/Kernels.hpp PSE/Kernels_test_util.hpp
.cu.o :
$(NVCC) $(NVCCFLAGS) -o $@ -c $<
test: numerics
source $(HOME)/openfpm_vars && cd .. && mpirun -np 2 ./src/numerics && mpirun -np 3 ./src/numerics && mpirun -np 4 ./src/numerics
This diff is collapsed.
/*
* vector_dist_operators_unit_tests.hpp
*
* Created on: Jun 11, 2016
* Author: i-bird
*/
#ifndef OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATORS_UNIT_TESTS_HPP_
#define OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATORS_UNIT_TESTS_HPP_
constexpr int A = 0;
constexpr int B = 1;
constexpr int C = 2;
constexpr int PA = 3;
constexpr int PB = 4;
constexpr int PC = 5;
//////////////////// Here we define all the function to checl the operators
template <unsigned int prp, typename vector> bool check_values(const vector & v,float a)
{
bool ret = true;
auto it = v.getDomainIterator();
while (it.isNext())
{
ret &= v.template getProp<prp>(it.get()) == a;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename vector> bool check_values_complex_expr(const vector & vd)
{
bool ret = true;
auto it = vd.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
float base1 = vd.template getProp<B>(key) + 2.0 + vd.template getProp<B>(key) - 2.0*vd.template getProp<C>(key) / 5.0;
float base2 = vd.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sum(const vector & vd, double d)
{
bool ret = true;
auto it = vd.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = vd.template getProp<B>(key) + d;
rtype base2 = vd.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sum(const vector & vd1, const vector & vd2)
{
bool ret = true;
auto it = vd1.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = vd1.template getProp<B>(key) + vd2.template getProp<C>(key);
rtype base2 = vd1.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sum_3(const vector & vd1)
{
bool ret = true;
auto it = vd1.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = vd1.template getProp<B>(key) + vd1.template getProp<C>(key) + vd1.template getProp<B>(key);
rtype base2 = vd1.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sum_4(const vector & vd1)
{
bool ret = true;
auto it = vd1.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = vd1.template getProp<B>(key) + vd1.template getProp<C>(key) + vd1.template getProp<B>(key) + vd1.template getProp<C>(key);
rtype base2 = vd1.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sub(const vector & vd, double d)
{
bool ret = true;
auto it = vd.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = vd.template getProp<B>(key) - d;
rtype base2 = vd.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sub(double d, const vector & vd)
{
bool ret = true;
auto it = vd.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = d - vd.template getProp<B>(key);
rtype base2 = vd.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sub(const vector & vd1, const vector & vd2)
{
bool ret = true;
auto it = vd1.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = vd1.template getProp<C>(key) - vd2.template getProp<B>(key);
rtype base2 = vd1.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sub_31(const vector & vd1)
{
bool ret = true;
auto it = vd1.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = vd1.template getProp<B>(key) - (vd1.template getProp<C>(key) + vd1.template getProp<B>(key));
rtype base2 = vd1.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sub_32(const vector & vd1)
{
bool ret = true;
auto it = vd1.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = (vd1.template getProp<C>(key) + vd1.template getProp<B>(key)) - vd1.template getProp<B>(key);
rtype base2 = vd1.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_sub_4(const vector & vd1)
{
bool ret = true;
auto it = vd1.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = (vd1.template getProp<C>(key) + vd1.template getProp<B>(key)) - (vd1.template getProp<C>(key) + vd1.template getProp<B>(key));
rtype base2 = vd1.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_mul(const vector & vd, double d)
{
bool ret = true;
auto it = vd.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = vd.template getProp<B>(key) * d;
rtype base2 = vd.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_mul(const vector & vd1, const vector & vd2)
{
bool ret = true;
auto it = vd1.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = vd1.template getProp<C>(key) * vd2.template getProp<B>(key);
rtype base2 = vd1.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_mul_3(const vector & vd1)
{
bool ret = true;
auto it = vd1.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = vd1.template getProp<B>(key) * (vd1.template getProp<B>(key) + vd1.template getProp<C>(key));
rtype base2 = vd1.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_mul_4(const vector & vd1)
{
bool ret = true;
auto it = vd1.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = (vd1.template getProp<B>(key) + vd1.template getProp<C>(key)) * (vd1.template getProp<B>(key) + vd1.template getProp<C>(key));
rtype base2 = vd1.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_div(const vector & vd, double d)
{
bool ret = true;
auto it = vd.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = vd.template getProp<B>(key) / d;
rtype base2 = vd.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_div(double d, const vector & vd)
{
bool ret = true;
auto it = vd.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = d / vd.template getProp<B>(key);
rtype base2 = vd.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_div(const vector & vd1, const vector & vd2)
{
bool ret = true;
auto it = vd1.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = vd1.template getProp<C>(key) / vd2.template getProp<B>(key);
rtype base2 = vd1.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_div_31(const vector & vd1)
{
bool ret = true;
auto it = vd1.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = vd1.template getProp<B>(key) / (vd1.template getProp<B>(key) + vd1.template getProp<C>(key));
rtype base2 = vd1.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_div_32(const vector & vd1)
{
bool ret = true;
auto it = vd1.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = (vd1.template getProp<C>(key) + vd1.template getProp<B>(key)) / vd1.template getProp<B>(key);
rtype base2 = vd1.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename rtype, typename vector, unsigned int A, unsigned int B, unsigned int C> bool check_values_div_4(const vector & vd1)
{
bool ret = true;
auto it = vd1.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
rtype base1 = (vd1.template getProp<B>(key) + vd1.template getProp<C>(key)) / (vd1.template getProp<B>(key) + vd1.template getProp<C>(key));
rtype base2 = vd1.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename vector> bool check_values_scal_norm_dist(vector & vd)
{
bool ret = true;
auto it = vd.getDomainIterator();
while (it.isNext())
{
auto key = it.get();
float base1 = vd.template getProp<PB>(key) * vd.template getProp<PC>(key) + norm(vd.template getProp<PC>(key) + vd.template getProp<PB>(key)) + distance(vd.template getProp<PC>(key),vd.template getProp<PB>(key));
float base2 = vd.template getProp<A>(key);
ret &= base1 == base2;
++it;
}
BOOST_REQUIRE_EQUAL(ret,true);
return ret;
}
template <typename vector> void fill_values(const vector & v)
{
auto it = v.getDomainIterator();
while (it.isNext())
{
auto p = it.get();
v.template getProp<A>(p) = p.getKey()+1;
v.template getProp<B>(p) = 2.0*p.getKey()+1;
v.template getProp<C>(p) = 3.0*p.getKey()+1;
for (size_t k = 0 ; k < 3 ; k++)
{
v.template getProp<PA>(p)[k] = p.getKey()+1+k;
v.template getProp<PB>(p)[k] = 2.0*p.getKey()+1+k;
v.template getProp<PC>(p)[k] = 3.0*p.getKey()+1+k;
}
++it;
}
}
//! Exponential kernel
struct exp_kernel
{
float var;
exp_kernel(float var)
:var(var)
{}
inline float value(Point<3,float> & p, Point<3,float> q,float pA,float pB)
{
float dist = norm(p-q);
return (pA - pB) * exp(dist * dist / var);
}
};
////////////////////////////////////////////////////////////////////////////