vector_dist_operators.hpp 21.5 KB
Newer Older
Pietro Incardona's avatar
Pietro Incardona committed
1 2 3 4 5 6 7 8 9 10
/*
 * vector_dist_operators.hpp
 *
 *  Created on: Jun 11, 2016
 *      Author: i-bird
 */

#ifndef SRC_VECTOR_VECTOR_DIST_OPERATORS_HPP_
#define SRC_VECTOR_VECTOR_DIST_OPERATORS_HPP_

Pietro Incardona's avatar
Pietro Incardona committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
/*! \brief has_init check if a type has defined a
 * method called init
 *
 *
 * return true if T::init() is a valid expression (function pointers)
 * and produce a defined type
 *
 */

template<typename ObjType, typename Sfinae = void>
struct has_init: std::false_type {};

template<typename ObjType>
struct has_init<ObjType, typename Void<typename ObjType::has_init>::type> : std::true_type
{};

/*! \brief Call the init function if needed
 *
 * \param r_exp expression
 *
 */
template <typename T, bool has_init = has_init<T>::value >
struct call_init_if_needed
{
	static inline void call(T & r_exp)
	{
		r_exp.init();
	}
};

template <typename T>
struct call_init_if_needed<T,false>
{
	static inline void call(T & r_exp)
	{
	}
};


Pietro Incardona's avatar
Pietro Incardona committed
50 51 52 53 54
#define SUM 1
#define SUB 2
#define MUL 3
#define DIV 4

Pietro Incardona's avatar
Pietro Incardona committed
55 56 57 58 59 60
/*! \brief Unknown operation specialization
 *
 * \tparam exp1 expression1
 * \tparam exp2 expression2
 *
 */
Pietro Incardona's avatar
Pietro Incardona committed
61 62 63 64 65 66
template <typename exp1, typename exp2, unsigned int op>
class vector_dist_expression_op
{

};

Pietro Incardona's avatar
Pietro Incardona committed
67 68 69 70 71 72
/*! \brief Sum operation
 *
 * \tparam exp1 expression1
 * \tparam exp2 expression2
 *
 */
Pietro Incardona's avatar
Pietro Incardona committed
73 74 75 76 77 78 79 80
template <typename exp1, typename exp2>
class vector_dist_expression_op<exp1,exp2,SUM>
{
	const exp1 o1;
	const exp2 o2;

public:

Pietro Incardona's avatar
Pietro Incardona committed
81
	inline vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
Pietro Incardona's avatar
Pietro Incardona committed
82 83 84
	:o1(o1),o2(o2)
	{}

Pietro Incardona's avatar
Pietro Incardona committed
85 86 87 88 89 90
	/*! \brief Evaluate the expression
	 *
	 * \param key where to evaluate the expression
	 *
	 */
	template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx(0)) + o2.value(vect_dist_key_dx(0)))>::type > inline r_type value(const vect_dist_key_dx & key) const
Pietro Incardona's avatar
Pietro Incardona committed
91 92 93 94 95
	{
		return o1.value(key) + o2.value(key);
	}
};

Pietro Incardona's avatar
Pietro Incardona committed
96 97 98 99 100 101
/*! \brief Subtraction operation
 *
 * \tparam exp1 expression1
 * \tparam exp2 expression2
 *
 */
Pietro Incardona's avatar
Pietro Incardona committed
102 103 104 105 106 107 108 109
template <typename exp1, typename exp2>
class vector_dist_expression_op<exp1,exp2,SUB>
{
	const exp1 o1;
	const exp2 o2;

public:

Pietro Incardona's avatar
Pietro Incardona committed
110
	inline vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
Pietro Incardona's avatar
Pietro Incardona committed
111 112 113
	:o1(o1),o2(o2)
	{}

Pietro Incardona's avatar
Pietro Incardona committed
114 115 116 117 118 119
	/*! \brief Evaluate the expression
	 *
	 * \param key where to evaluate the expression
	 *
	 */
	template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx(0)) - o2.value(vect_dist_key_dx(0)))>::type > inline r_type value(const vect_dist_key_dx & key) const
Pietro Incardona's avatar
Pietro Incardona committed
120 121 122 123 124 125
	{
		return o1.value(key) - o2.value(key);
	}

};

Pietro Incardona's avatar
Pietro Incardona committed
126 127 128 129 130 131
/*! \brief Multiplication operation
 *
 * \tparam exp1 expression1
 * \tparam exp2 expression2
 *
 */
Pietro Incardona's avatar
Pietro Incardona committed
132 133 134 135 136 137 138 139 140 141 142 143
template <typename exp1, typename exp2>
class vector_dist_expression_op<exp1,exp2,MUL>
{
	const exp1 o1;
	const exp2 o2;

public:

	vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
	:o1(o1),o2(o2)
	{}

Pietro Incardona's avatar
Pietro Incardona committed
144 145 146 147 148 149
	/*! \brief Evaluate the expression
	 *
	 * \param key where to evaluate the expression
	 *
	 */
	template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx(0)) * o2.value(vect_dist_key_dx(0)))>::type > inline r_type value(const vect_dist_key_dx & key) const
Pietro Incardona's avatar
Pietro Incardona committed
150 151 152 153 154 155
	{
		return o1.value(key) * o2.value(key);
	}

};

Pietro Incardona's avatar
Pietro Incardona committed
156 157 158 159 160 161
/*! \brief Division operation
 *
 * \tparam exp1 expression1
 * \tparam exp2 expression2
 *
 */
Pietro Incardona's avatar
Pietro Incardona committed
162 163 164 165 166 167 168 169 170 171 172 173
template <typename exp1, typename exp2>
class vector_dist_expression_op<exp1,exp2,DIV>
{
	const exp1 o1;
	const exp2 o2;

public:

	vector_dist_expression_op(const exp1 & o1, const exp2 & o2)
	:o1(o1),o2(o2)
	{}

Pietro Incardona's avatar
Pietro Incardona committed
174 175 176 177 178 179
	/*! \brief Evaluate the expression
	 *
	 * \param key where to evaluate the expression
	 *
	 */
	template<typename r_type=typename std::remove_reference<decltype(o1.value(vect_dist_key_dx(0)) / o2.value(vect_dist_key_dx(0)))>::type > inline r_type value(const vect_dist_key_dx & key) const
Pietro Incardona's avatar
Pietro Incardona committed
180 181 182 183 184 185
	{
		return o1.value(key) / o2.value(key);
	}

};

Pietro Incardona's avatar
Pietro Incardona committed
186
/*! \brief Main class that encapsulate a vector properties
Pietro Incardona's avatar
Pietro Incardona committed
187
 *
Pietro Incardona's avatar
Pietro Incardona committed
188 189
 * \tparam prp property involved
 * \tparam vector involved
Pietro Incardona's avatar
Pietro Incardona committed
190 191 192 193 194 195 196 197 198 199 200 201 202
 *
 */
template<unsigned int prp, typename vector>
class vector_dist_expression
{
	vector & v;

public:

	vector_dist_expression(vector & v)
	:v(v)
	{}

Pietro Incardona's avatar
Pietro Incardona committed
203 204 205 206 207
	/*! \brief Evaluate the expression
	 *
	 * \param key where to evaluate the expression
	 *
	 */
Pietro Incardona's avatar
Pietro Incardona committed
208 209 210 211 212
	inline auto value(const vect_dist_key_dx & k) const -> decltype(v.template getProp<prp>(k))
	{
		return v.template getProp<prp>(k);
	}

Pietro Incardona's avatar
Pietro Incardona committed
213
	/*! \brief Fill the vector property with the evaluated expression
Pietro Incardona's avatar
Pietro Incardona committed
214 215 216 217 218 219 220 221 222 223 224 225
	 *
	 * \param v_exp expression to evaluate
	 *
	 */
	template<typename exp1, typename exp2, unsigned int op> vector & operator=(const vector_dist_expression_op<exp1,exp2,op> & v_exp)
	{
		auto it = v.getDomainIterator();

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

Pietro Incardona's avatar
Pietro Incardona committed
226 227
			auto exp = v_exp.value(key);
			call_init_if_needed<decltype(exp)>::call(exp);
Pietro Incardona's avatar
Pietro Incardona committed
228 229 230 231 232 233 234 235
			v.template getProp<prp>(key) = v_exp.value(key);

			++it;
		}

		return v;
	}

Pietro Incardona's avatar
Pietro Incardona committed
236
	/*! \brief Fill the vector property with the double
Pietro Incardona's avatar
Pietro Incardona committed
237
	 *
Pietro Incardona's avatar
Pietro Incardona committed
238
	 * \param d value to fill
Pietro Incardona's avatar
Pietro Incardona committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
	 *
	 */
	vector & operator=(double d)
	{
		auto it = v.getDomainIterator();

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

			v.template getProp<prp>(key) = d;

			++it;
		}

		return v;
	}
};

Pietro Incardona's avatar
Pietro Incardona committed
258
/*! \brief Main class that encapsulate a double constant
Pietro Incardona's avatar
Pietro Incardona committed
259
 *
Pietro Incardona's avatar
Pietro Incardona committed
260
 * \param prp no meaning
Pietro Incardona's avatar
Pietro Incardona committed
261 262 263 264 265 266 267 268 269 270 271 272 273
 *
 */
template<unsigned int prp>
class vector_dist_expression<prp,double>
{
	double d;

public:

	inline vector_dist_expression(double & d)
	:d(d)
	{}

Pietro Incardona's avatar
Pietro Incardona committed
274 275 276 277 278
	/*! \brief Evaluate the expression
	 *
	 * It just return the velue set in the constructor
	 *
	 */
Pietro Incardona's avatar
Pietro Incardona committed
279 280 281 282 283 284 285
	inline double value(const vect_dist_key_dx & k) const
	{
		return d;
	}
};


Pietro Incardona's avatar
Pietro Incardona committed
286
/* \brief sum two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
287
 *
Pietro Incardona's avatar
Pietro Incardona committed
288 289
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
290
 *
Pietro Incardona's avatar
Pietro Incardona committed
291
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
292 293 294 295 296 297 298 299 300 301 302
 *
 */
template<unsigned int p1, unsigned int p2, typename v1, typename v2>
inline vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression<p2,v2>,SUM>
operator+(const vector_dist_expression<p1,v1> & va, const vector_dist_expression<p2,v2> & vb)
{
	vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression<p2,v2>,SUM> exp_sum(va,vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
303
/* \brief sum two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
304
 *
Pietro Incardona's avatar
Pietro Incardona committed
305 306
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
307
 *
Pietro Incardona's avatar
Pietro Incardona committed
308
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
309 310 311 312 313 314 315 316 317 318 319
 *
 */
template<typename exp1 , typename exp2, unsigned int op1, unsigned int prp1, typename v1>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<prp1,v1>,SUM>
operator+(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression<prp1,v1> & vb)
{
	vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<prp1,v1>,SUM> exp_sum(va,vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
320
/* \brief sum two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
321
 *
Pietro Incardona's avatar
Pietro Incardona committed
322 323
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
324
 *
Pietro Incardona's avatar
Pietro Incardona committed
325
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
326 327 328 329 330 331 332 333 334 335 336
 *
 */
template<typename exp1 , typename exp2, unsigned int op1, unsigned int prp1, typename v1>
inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression_op<exp1,exp2,op1>,SUM>
operator+(const vector_dist_expression<prp1,v1> & va, const vector_dist_expression_op<exp1,exp2,op1> & vb)
{
	vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression_op<exp1,exp2,op1>,SUM> exp_sum(va,vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
337
/* \brief sum two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
338
 *
Pietro Incardona's avatar
Pietro Incardona committed
339 340
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
341
 *
Pietro Incardona's avatar
Pietro Incardona committed
342
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
343 344 345 346 347 348 349 350 351 352 353
 *
 */
template<typename exp1 , typename exp2, unsigned int op1, typename exp3 , typename exp4, unsigned int op2>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,SUM>
operator+(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression_op<exp3,exp4,op2> & vb)
{
	vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,SUM> exp_sum(va,vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
354
/* \brief sum two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
355
 *
Pietro Incardona's avatar
Pietro Incardona committed
356 357
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
358
 *
Pietro Incardona's avatar
Pietro Incardona committed
359
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
360 361 362 363 364 365 366 367 368 369 370
 *
 */
template<unsigned int prp1 , typename v1>
inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,SUM>
operator+(const vector_dist_expression<prp1,v1> & va, double d)
{
	vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,SUM> exp_sum(va,vector_dist_expression<0,double>(d));

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
371
/* \brief sum two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
372
 *
Pietro Incardona's avatar
Pietro Incardona committed
373 374
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
375
 *
Pietro Incardona's avatar
Pietro Incardona committed
376
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
377 378 379 380 381 382 383 384 385 386 387
 *
 */
template<unsigned int prp1 , typename v1>
inline vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<prp1,v1>,SUM>
operator+(double d, const vector_dist_expression<prp1,v1> & vb)
{
	vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<prp1,v1>,SUM> exp_sum(vector_dist_expression<0,double>(d),vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
388
/* \brief sum two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
389
 *
Pietro Incardona's avatar
Pietro Incardona committed
390 391
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
392
 *
Pietro Incardona's avatar
Pietro Incardona committed
393
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
394 395 396 397 398 399 400 401 402 403 404 405
 *
 */
template<typename exp1 , typename exp2, unsigned int op1>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,SUM>
operator+(const vector_dist_expression_op<exp1,exp2,op1> & va, double d)
{
	vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,SUM> exp_sum(va,vector_dist_expression<0,double>(d));

	return exp_sum;
}


Pietro Incardona's avatar
Pietro Incardona committed
406
/* \brief subtract two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
407
 *
Pietro Incardona's avatar
Pietro Incardona committed
408 409
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
410
 *
Pietro Incardona's avatar
Pietro Incardona committed
411
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
412 413 414 415 416 417 418 419 420 421 422 423
 *
 */
template<unsigned int p1, unsigned int p2, typename v1, typename v2>
inline vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression<p2,v2>,SUB>
operator-(const vector_dist_expression<p1,v1> & va, const vector_dist_expression<p2,v2> & vb)
{
	vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression<p2,v2>,SUB> exp_sum(va,vb);

	return exp_sum;
}


Pietro Incardona's avatar
Pietro Incardona committed
424
/* \brief subtract two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
425
 *
Pietro Incardona's avatar
Pietro Incardona committed
426 427
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
428
 *
Pietro Incardona's avatar
Pietro Incardona committed
429
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
430 431 432 433 434 435 436 437 438 439 440
 *
 */
template<typename exp1, typename exp2, unsigned int op1, unsigned int p2, typename v2>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<p2,v2>,SUB>
operator-(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression<p2,v2> & vb)
{
	vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<p2,v2>,SUB> exp_sum(va,vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
441
/* \brief subtract two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
442
 *
Pietro Incardona's avatar
Pietro Incardona committed
443 444
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
445
 *
Pietro Incardona's avatar
Pietro Incardona committed
446
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
447 448 449 450 451 452 453 454 455 456 457
 *
 */
template<typename exp1, typename exp2, unsigned int op1, unsigned int p2, typename v2>
inline vector_dist_expression_op<vector_dist_expression<p2,v2>,vector_dist_expression_op<exp1,exp2,op1>,SUB>
operator-(const vector_dist_expression<p2,v2> & va, const vector_dist_expression_op<exp1,exp2,op1> & vb)
{
	vector_dist_expression_op<vector_dist_expression<p2,v2>, vector_dist_expression_op<exp1,exp2,op1>,SUB> exp_sum(va,vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
458
/* \brief subtract two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
459
 *
Pietro Incardona's avatar
Pietro Incardona committed
460 461
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
462
 *
Pietro Incardona's avatar
Pietro Incardona committed
463
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
464 465 466 467 468 469 470 471 472 473 474
 *
 */
template<typename exp1, typename exp2, unsigned int op1, typename exp3, typename exp4, unsigned int op2>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,SUB>
operator-(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression_op<exp3,exp4,op2> & vb)
{
	vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,SUB> exp_sum(va,vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
475
/* \brief subtract two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
476
 *
Pietro Incardona's avatar
Pietro Incardona committed
477 478
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
479
 *
Pietro Incardona's avatar
Pietro Incardona committed
480
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
481 482 483 484 485 486 487 488 489 490 491
 *
 */
template<unsigned int prp1, typename v1>
inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,SUB>
operator-(const vector_dist_expression<prp1,v1> & va, double d)
{
	vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,SUB> exp_sum(va,vector_dist_expression<0,double>(d));

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
492
/* \brief subtract two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
493
 *
Pietro Incardona's avatar
Pietro Incardona committed
494 495
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
496
 *
Pietro Incardona's avatar
Pietro Incardona committed
497
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
498 499 500 501 502 503 504 505 506 507 508
 *
 */
template<unsigned int prp1, typename v1>
inline vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<prp1,v1>,SUB>
operator-(double d, const vector_dist_expression<prp1,v1> & vb)
{
	vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<prp1,v1>,SUB> exp_sum(vector_dist_expression<0,double>(d),vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
509
/* \brief Multiply two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
510
 *
Pietro Incardona's avatar
Pietro Incardona committed
511 512
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
513
 *
Pietro Incardona's avatar
Pietro Incardona committed
514
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
515 516 517 518 519 520 521 522 523 524 525
 *
 */
template<unsigned int p2, typename v2>
inline vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<p2,v2>,MUL>
operator*(double d, const vector_dist_expression<p2,v2> & vb)
{
	vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<p2,v2>,MUL> exp_sum(vector_dist_expression<0,double>(d),vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
526
/* \brief Multiply two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
527
 *
Pietro Incardona's avatar
Pietro Incardona committed
528 529
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
530
 *
Pietro Incardona's avatar
Pietro Incardona committed
531
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
532 533 534 535 536 537 538 539 540 541 542
 *
 */
template<unsigned int p2, typename v2>
inline vector_dist_expression_op<vector_dist_expression<p2,v2>,vector_dist_expression<0,double>,MUL>
operator*(const vector_dist_expression<p2,v2> & va, double d)
{
	vector_dist_expression_op<vector_dist_expression<p2,v2>,vector_dist_expression<0,double>,MUL> exp_sum(va,vector_dist_expression<0,double>(d));

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
543
/* \brief Multiply two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
544
 *
Pietro Incardona's avatar
Pietro Incardona committed
545 546
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
547
 *
Pietro Incardona's avatar
Pietro Incardona committed
548
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
549 550 551 552 553 554 555 556 557 558 559
 *
 */
template<unsigned int p1, typename v1,unsigned int p2, typename v2>
inline vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression<p2,v2>,MUL>
operator*(const vector_dist_expression<p1,v1> & va, const vector_dist_expression<p2,v2> & vb)
{
	vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression<p2,v2>,MUL> exp_sum(va,vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
560
/* \brief Multiply two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
561
 *
Pietro Incardona's avatar
Pietro Incardona committed
562 563
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
564
 *
Pietro Incardona's avatar
Pietro Incardona committed
565
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
566 567 568 569 570 571 572 573 574 575 576
 *
 */
template<unsigned int p1, typename v1, typename exp1, typename exp2, unsigned int op1>
inline vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression_op<exp1,exp2,op1>,MUL>
operator*(const vector_dist_expression<p1,v1> & va, const vector_dist_expression_op<exp1,exp2,op1> & vb)
{
	vector_dist_expression_op<vector_dist_expression<p1,v1>,vector_dist_expression_op<exp1,exp2,op1>,MUL> exp_sum(va,vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
577
/* \brief Multiply two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
578
 *
Pietro Incardona's avatar
Pietro Incardona committed
579 580
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
581
 *
Pietro Incardona's avatar
Pietro Incardona committed
582
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
583 584 585 586 587 588 589 590 591 592 593
 *
 */
template<unsigned int p1, typename v1, typename exp1, typename exp2, unsigned int op1>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<p1,v1>,MUL>
operator*(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression<p1,v1> & vb)
{
	vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<p1,v1>,MUL> exp_sum(va,vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
594
/* \brief Multiply two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
595
 *
Pietro Incardona's avatar
Pietro Incardona committed
596 597
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
598
 *
Pietro Incardona's avatar
Pietro Incardona committed
599
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
600 601 602 603 604 605 606 607 608 609 610
 *
 */
template<typename exp1, typename exp2, unsigned int op1, typename exp3 , typename exp4, unsigned int op2>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,MUL>
operator*(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression_op<exp3,exp4,op2> & vb)
{
	vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,MUL> exp_sum(va,vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
611
/* \brief Divide two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
612
 *
Pietro Incardona's avatar
Pietro Incardona committed
613 614
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
615
 *
Pietro Incardona's avatar
Pietro Incardona committed
616
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
617 618 619 620 621 622 623 624 625 626 627 628
 *
 */
template<typename exp1, typename exp2, unsigned int op1>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,DIV>
operator/(const vector_dist_expression_op<exp1,exp2,op1> & va, double d)
{
	vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,DIV> exp_sum(va,vector_dist_expression<0,double>(d));

	return exp_sum;
}


Pietro Incardona's avatar
Pietro Incardona committed
629
/* \brief Divide two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
630
 *
Pietro Incardona's avatar
Pietro Incardona committed
631 632
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
633
 *
Pietro Incardona's avatar
Pietro Incardona committed
634
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
635 636 637 638 639 640 641 642 643 644 645
 *
 */
template<typename exp1, typename exp2, unsigned int op1>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,DIV>
operator/(double d, const vector_dist_expression_op<exp1,exp2,op1> & va)
{
	vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<0,double>,DIV> exp_sum(vector_dist_expression<0,double>(d),va);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
646
/* \brief Divide two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
647
 *
Pietro Incardona's avatar
Pietro Incardona committed
648 649
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
650
 *
Pietro Incardona's avatar
Pietro Incardona committed
651
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
652 653 654 655 656 657 658 659 660 661 662
 *
 */
template<unsigned int prp1, typename v1>
inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,DIV>
operator/(const vector_dist_expression<prp1,v1> & va, double d)
{
	vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<0,double>,DIV> exp_sum(va,vector_dist_expression<0,double>(d));

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
663
/* \brief Divide two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
664
 *
Pietro Incardona's avatar
Pietro Incardona committed
665 666
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
667
 *
Pietro Incardona's avatar
Pietro Incardona committed
668
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
669 670 671
 *
 */
template<unsigned int prp1, typename v1>
Pietro Incardona's avatar
Pietro Incardona committed
672
inline vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<prp1,v1>,DIV>
Pietro Incardona's avatar
Pietro Incardona committed
673 674
operator/(double d, const vector_dist_expression<prp1,v1> & va)
{
Pietro Incardona's avatar
Pietro Incardona committed
675
	vector_dist_expression_op<vector_dist_expression<0,double>,vector_dist_expression<prp1,v1>,DIV> exp_sum(vector_dist_expression<0,double>(d),va);
Pietro Incardona's avatar
Pietro Incardona committed
676 677 678 679

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
680
/* \brief Divide two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
681
 *
Pietro Incardona's avatar
Pietro Incardona committed
682 683
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
684
 *
Pietro Incardona's avatar
Pietro Incardona committed
685
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
686 687 688 689 690 691 692 693 694 695 696
 *
 */
template<unsigned int prp1, typename v1, unsigned int prp2, typename v2>
inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<prp2,v2>,DIV>
operator/(const vector_dist_expression<prp1,v1> & va, const vector_dist_expression<prp2,v2> & vb)
{
	vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression<prp2,v2>,DIV> exp_sum(va,vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
697
/* \brief Divide two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
698
 *
Pietro Incardona's avatar
Pietro Incardona committed
699 700
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
701
 *
Pietro Incardona's avatar
Pietro Incardona committed
702
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
703 704 705 706 707 708 709 710 711 712 713
 *
 */
template<unsigned int prp1, typename v1, typename exp1,typename exp2, unsigned int op1>
inline vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression_op<exp1,exp2,op1>,DIV>
operator/(const vector_dist_expression<prp1,v1> & va, const vector_dist_expression_op<exp1,exp2,op1> & vb)
{
	vector_dist_expression_op<vector_dist_expression<prp1,v1>,vector_dist_expression_op<exp1,exp2,op1>,DIV> exp_sum(va,vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
714
/* \brief Divide two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
715
 *
Pietro Incardona's avatar
Pietro Incardona committed
716 717
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
718
 *
Pietro Incardona's avatar
Pietro Incardona committed
719
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
720 721 722 723 724 725 726 727 728 729 730
 *
 */
template<unsigned int prp1, typename v1, typename exp1,typename exp2, unsigned int op1>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<prp1,v1>,DIV>
operator/(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression<prp1,v1> & vb)
{
	vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression<prp1,v1>,DIV> exp_sum(va,vb);

	return exp_sum;
}

Pietro Incardona's avatar
Pietro Incardona committed
731
/* \brief Divide two distributed vector expression
Pietro Incardona's avatar
Pietro Incardona committed
732
 *
Pietro Incardona's avatar
Pietro Incardona committed
733 734
 * \param va vector expression one
 * \param vb vector expression two
Pietro Incardona's avatar
Pietro Incardona committed
735
 *
Pietro Incardona's avatar
Pietro Incardona committed
736
 * \return an object that encapsulate the expression
Pietro Incardona's avatar
Pietro Incardona committed
737 738 739 740 741 742 743 744 745 746 747 748
 *
 */
template<typename exp1,typename exp2, unsigned int op1, typename exp3, typename exp4, unsigned int op2>
inline vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,DIV>
operator/(const vector_dist_expression_op<exp1,exp2,op1> & va, const vector_dist_expression_op<exp3,exp4,op2> & vb)
{
	vector_dist_expression_op<vector_dist_expression_op<exp1,exp2,op1>,vector_dist_expression_op<exp3,exp4,op2>,DIV> exp_sum(va,vb);

	return exp_sum;
}

#endif /* SRC_VECTOR_VECTOR_DIST_OPERATORS_HPP_ */