vector_dist_operator_assign.hpp 10.2 KB
Newer Older
Pietro Incardona's avatar
Pietro Incardona committed
1 2 3 4 5 6 7 8 9 10
/*
 * vector_dist_operator_assign.ipp
 *
 *  Created on: Jul 21, 2016
 *      Author: i-bird
 */

#ifndef OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATOR_ASSIGN_HPP_
#define OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATOR_ASSIGN_HPP_

11 12
//! Construct a vector expression from a type T that is already an expression
//! it does nothing
Pietro Incardona's avatar
Pietro Incardona committed
13 14 15
template<typename T>
struct construct_expression
{
16
	//! It return the expression itself
Pietro Incardona's avatar
Pietro Incardona committed
17 18 19 20 21 22
	static inline const T & construct(const T & e)
	{
		return e;
	}
};

23
//! construct a vector expression from a double
Pietro Incardona's avatar
Pietro Incardona committed
24 25 26
template<>
struct construct_expression<double>
{
27
	//! It return an expression from a double
Pietro Incardona's avatar
Pietro Incardona committed
28 29 30 31 32 33
	static inline vector_dist_expression<0,double> construct(double e)
	{
		return vector_dist_expression<0,double>(e);
	}
};

34
//! construct a vector expression from a float
Pietro Incardona's avatar
Pietro Incardona committed
35 36 37
template<>
struct construct_expression<float>
{
38
	//! It return an expression from a float
Pietro Incardona's avatar
Pietro Incardona committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
	static inline vector_dist_expression<0,float> construct(const float e)
	{
		return vector_dist_expression<0,float>(e);
	}
};

template<typename prp1, typename expr1, typename prp2, typename expr2> void assign(prp1 & p1, const expr1 & v_e1, prp2 & p2, const expr2 & v_e2)
{
	auto v_exp1 = construct_expression<expr1>::construct(v_e1);
	auto v_exp2 = construct_expression<expr2>::construct(v_e2);

	v_exp1.init();
	v_exp2.init();

	auto it = p1.getVector().getDomainIterator();

	while (it.isNext())
	{
		auto key = it.get();

59 60
		pos_or_propL<typename prp1::vtype,prp1::prop>::value(p1.getVector(),key) = v_exp1.value(key);
		pos_or_propL<typename prp2::vtype,prp2::prop>::value(p2.getVector(),key) = v_exp2.value(key);
Pietro Incardona's avatar
Pietro Incardona committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

		++it;
	}
}

template<typename prp1, typename expr1, typename prp2, typename expr2, typename prp3, typename expr3> void assign(prp1 & p1, const expr1 & v_e1, prp2 & p2, const expr2 & v_e2, prp3 & p3, const expr3 & v_e3)
{
	auto v_exp1 = construct_expression<expr1>::construct(v_e1);
	auto v_exp2 = construct_expression<expr2>::construct(v_e2);
	auto v_exp3 = construct_expression<expr3>::construct(v_e3);

	v_exp1.init();
	v_exp2.init();
	v_exp3.init();

	auto it = p1.getVector().getDomainIterator();

	while (it.isNext())
	{
		auto key = it.get();

82 83 84
		pos_or_propL<typename prp1::vtype,prp1::prop>::value(p1.getVector(),key) = v_exp1.value(key);
		pos_or_propL<typename prp2::vtype,prp2::prop>::value(p2.getVector(),key) = v_exp2.value(key);
		pos_or_propL<typename prp3::vtype,prp3::prop>::value(p3.getVector(),key) = v_exp3.value(key);
Pietro Incardona's avatar
Pietro Incardona committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

		++it;
	}
}

template<typename prp1, typename expr1,
		 typename prp2, typename expr2,
		 typename prp3, typename expr3,
		 typename prp4, typename expr4>
void assign(prp1 & p1, const expr1 & v_e1,
			prp2 & p2, const expr2 & v_e2,
			prp3 & p3, const expr3 & v_e3,
			prp4 & p4, const expr4 & v_e4)
{
	auto v_exp1 = construct_expression<expr1>::construct(v_e1);
	auto v_exp2 = construct_expression<expr2>::construct(v_e2);
	auto v_exp3 = construct_expression<expr3>::construct(v_e3);
	auto v_exp4 = construct_expression<expr4>::construct(v_e4);

	v_exp1.init();
	v_exp2.init();
	v_exp3.init();
	v_exp4.init();

	auto it = p1.getVector().getDomainIterator();

	while (it.isNext())
	{
		auto key = it.get();

115 116 117 118
		pos_or_propL<typename prp1::vtype,prp1::prop>::value(p1.getVector(),key) = v_exp1.value(key);
		pos_or_propL<typename prp2::vtype,prp2::prop>::value(p2.getVector(),key) = v_exp2.value(key);
		pos_or_propL<typename prp3::vtype,prp3::prop>::value(p3.getVector(),key) = v_exp3.value(key);
		pos_or_propL<typename prp4::vtype,prp4::prop>::value(p4.getVector(),key) = v_exp4.value(key);
Pietro Incardona's avatar
Pietro Incardona committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153

		++it;
	}
}


template<typename prp1, typename expr1,
		 typename prp2, typename expr2,
		 typename prp3, typename expr3,
		 typename prp4, typename expr4,
		 typename prp5, typename expr5>
void assign(prp1 & p1, const expr1 & v_e1,
			prp2 & p2, const expr2 & v_e2,
			prp3 & p3, const expr3 & v_e3,
			prp4 & p4, const expr4 & v_e4,
			prp5 & p5, const expr5 & v_e5)
{
	auto v_exp1 = construct_expression<expr1>::construct(v_e1);
	auto v_exp2 = construct_expression<expr2>::construct(v_e2);
	auto v_exp3 = construct_expression<expr3>::construct(v_e3);
	auto v_exp4 = construct_expression<expr4>::construct(v_e4);
	auto v_exp5 = construct_expression<expr5>::construct(v_e5);

	v_exp1.init();
	v_exp2.init();
	v_exp3.init();
	v_exp4.init();
	v_exp5.init();

	auto it = p1.getVector().getDomainIterator();

	while (it.isNext())
	{
		auto key = it.get();

154 155 156 157 158
		pos_or_propL<typename prp1::vtype,prp1::prop>::value(p1.getVector(),key) = v_exp1.value(key);
		pos_or_propL<typename prp2::vtype,prp2::prop>::value(p2.getVector(),key) = v_exp2.value(key);
		pos_or_propL<typename prp3::vtype,prp3::prop>::value(p3.getVector(),key) = v_exp3.value(key);
		pos_or_propL<typename prp4::vtype,prp4::prop>::value(p4.getVector(),key) = v_exp4.value(key);
		pos_or_propL<typename prp5::vtype,prp5::prop>::value(p5.getVector(),key) = v_exp5.value(key);
Pietro Incardona's avatar
Pietro Incardona committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196

		++it;
	}
}

template<typename prp1, typename expr1,
		 typename prp2, typename expr2,
		 typename prp3, typename expr3,
		 typename prp4, typename expr4,
		 typename prp5, typename expr5,
		 typename prp6, typename expr6>
void assign(prp1 & p1, const expr1 & v_e1,
			prp2 & p2, const expr2 & v_e2,
			prp3 & p3, const expr3 & v_e3,
			prp4 & p4, const expr4 & v_e4,
			prp5 & p5, const expr5 & v_e5,
			prp6 & p6, const expr6 & v_e6)
{
	auto v_exp1 = construct_expression<expr1>::construct(v_e1);
	auto v_exp2 = construct_expression<expr2>::construct(v_e2);
	auto v_exp3 = construct_expression<expr3>::construct(v_e3);
	auto v_exp4 = construct_expression<expr4>::construct(v_e4);
	auto v_exp5 = construct_expression<expr5>::construct(v_e5);
	auto v_exp6 = construct_expression<expr6>::construct(v_e6);

	v_exp1.init();
	v_exp2.init();
	v_exp3.init();
	v_exp4.init();
	v_exp5.init();
	v_exp6.init();

	auto it = p1.getVector().getDomainIterator();

	while (it.isNext())
	{
		auto key = it.get();

197 198 199 200 201 202
		pos_or_propL<typename prp1::vtype,prp1::prop>::value(p1.getVector(),key) = v_exp1.value(key);
		pos_or_propL<typename prp2::vtype,prp2::prop>::value(p2.getVector(),key) = v_exp2.value(key);
		pos_or_propL<typename prp3::vtype,prp3::prop>::value(p3.getVector(),key) = v_exp3.value(key);
		pos_or_propL<typename prp4::vtype,prp4::prop>::value(p4.getVector(),key) = v_exp4.value(key);
		pos_or_propL<typename prp5::vtype,prp5::prop>::value(p5.getVector(),key) = v_exp5.value(key);
		pos_or_propL<typename prp6::vtype,prp6::prop>::value(p6.getVector(),key) = v_exp6.value(key);
Pietro Incardona's avatar
Pietro Incardona committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246

		++it;
	}
}



template<typename prp1, typename expr1,
		 typename prp2, typename expr2,
		 typename prp3, typename expr3,
		 typename prp4, typename expr4,
		 typename prp5, typename expr5,
		 typename prp6, typename expr6,
		 typename prp7, typename expr7>
void assign(prp1 & p1, const expr1 & v_e1,
			prp2 & p2, const expr2 & v_e2,
			prp3 & p3, const expr3 & v_e3,
			prp4 & p4, const expr4 & v_e4,
			prp5 & p5, const expr5 & v_e5,
			prp6 & p6, const expr6 & v_e6,
			prp7 & p7, const expr7 & v_e7)
{
	auto v_exp1 = construct_expression<expr1>::construct(v_e1);
	auto v_exp2 = construct_expression<expr2>::construct(v_e2);
	auto v_exp3 = construct_expression<expr3>::construct(v_e3);
	auto v_exp4 = construct_expression<expr4>::construct(v_e4);
	auto v_exp5 = construct_expression<expr5>::construct(v_e5);
	auto v_exp6 = construct_expression<expr6>::construct(v_e6);
	auto v_exp7 = construct_expression<expr7>::construct(v_e7);

	v_exp1.init();
	v_exp2.init();
	v_exp3.init();
	v_exp4.init();
	v_exp5.init();
	v_exp6.init();
	v_exp7.init();

	auto it = p1.getVector().getDomainIterator();

	while (it.isNext())
	{
		auto key = it.get();

247 248 249 250 251 252 253
		pos_or_propL<typename prp1::vtype,prp1::prop>::value(p1.getVector(),key) = v_exp1.value(key);
		pos_or_propL<typename prp2::vtype,prp2::prop>::value(p2.getVector(),key) = v_exp2.value(key);
		pos_or_propL<typename prp3::vtype,prp3::prop>::value(p3.getVector(),key) = v_exp3.value(key);
		pos_or_propL<typename prp4::vtype,prp4::prop>::value(p4.getVector(),key) = v_exp4.value(key);
		pos_or_propL<typename prp5::vtype,prp5::prop>::value(p5.getVector(),key) = v_exp5.value(key);
		pos_or_propL<typename prp6::vtype,prp6::prop>::value(p6.getVector(),key) = v_exp6.value(key);
		pos_or_propL<typename prp7::vtype,prp7::prop>::value(p7.getVector(),key) = v_exp7.value(key);
Pietro Incardona's avatar
Pietro Incardona committed
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300

		++it;
	}
}


template<typename prp1, typename expr1,
		 typename prp2, typename expr2,
		 typename prp3, typename expr3,
		 typename prp4, typename expr4,
		 typename prp5, typename expr5,
		 typename prp6, typename expr6,
		 typename prp7, typename expr7,
		 typename prp8, typename expr8>
void assign(prp1 & p1, const expr1 & v_e1,
			prp2 & p2, const expr2 & v_e2,
			prp3 & p3, const expr3 & v_e3,
			prp4 & p4, const expr4 & v_e4,
			prp5 & p5, const expr5 & v_e5,
			prp6 & p6, const expr6 & v_e6,
			prp7 & p7, const expr7 & v_e7,
			prp8 & p8, const expr8 & v_e8)
{
	auto v_exp1 = construct_expression<expr1>::construct(v_e1);
	auto v_exp2 = construct_expression<expr2>::construct(v_e2);
	auto v_exp3 = construct_expression<expr3>::construct(v_e3);
	auto v_exp4 = construct_expression<expr4>::construct(v_e4);
	auto v_exp5 = construct_expression<expr5>::construct(v_e5);
	auto v_exp6 = construct_expression<expr6>::construct(v_e6);
	auto v_exp7 = construct_expression<expr7>::construct(v_e7);
	auto v_exp8 = construct_expression<expr8>::construct(v_e8);

	v_exp1.init();
	v_exp2.init();
	v_exp3.init();
	v_exp4.init();
	v_exp5.init();
	v_exp6.init();
	v_exp7.init();
	v_exp8.init();

	auto it = p1.getVector().getDomainIterator();

	while (it.isNext())
	{
		auto key = it.get();

301 302 303 304 305 306 307 308
		pos_or_propL<typename prp1::vtype,prp1::prop>::value(p1.getVector(),key) = v_exp1.value(key);
		pos_or_propL<typename prp2::vtype,prp2::prop>::value(p2.getVector(),key) = v_exp2.value(key);
		pos_or_propL<typename prp3::vtype,prp3::prop>::value(p3.getVector(),key) = v_exp3.value(key);
		pos_or_propL<typename prp4::vtype,prp4::prop>::value(p4.getVector(),key) = v_exp4.value(key);
		pos_or_propL<typename prp5::vtype,prp5::prop>::value(p5.getVector(),key) = v_exp5.value(key);
		pos_or_propL<typename prp6::vtype,prp6::prop>::value(p6.getVector(),key) = v_exp6.value(key);
		pos_or_propL<typename prp7::vtype,prp7::prop>::value(p7.getVector(),key) = v_exp7.value(key);
		pos_or_propL<typename prp8::vtype,prp8::prop>::value(p8.getVector(),key) = v_exp8.value(key);
Pietro Incardona's avatar
Pietro Incardona committed
309 310 311 312 313 314

		++it;
	}
}

#endif /* OPENFPM_NUMERICS_SRC_OPERATORS_VECTOR_VECTOR_DIST_OPERATOR_ASSIGN_HPP_ */