msg_right_permutation_apply.h
Go to the documentation of this file.
#ifndef _RHEO_MSG_RIGHT_PERMUTATION_APPLY_H
#define _RHEO_MSG_RIGHT_PERMUTATION_APPLY_H
namespace rheolef {
/*F:
NAME: msg_right_permutation_apply -- sequentail apply (@PACKAGE@ @VERSION@)
DESCRIPTION:
Applies a permutation to an array.
ALGORITHM:
msg_right_permutation_apply
"input": the length array
| perm(0:n-1), x(0:nx-1)
"output": the pointer array and the total size
| y(0:n)
begin
| for i := 0 to n-1 do
| y(i) := x(perm(i))
| endfor
end
COMPLEXITY:
Time and memory complexity is O(n).
METHODS: @msg_right_permutation_apply
AUTHORS:
LMC-IMAG, 38041 Grenoble cedex 9, France
| Pierre.Saramito@imag.fr
DATE: 6 january 1999
END:
*/
//<msg_right_permutation_apply:
template <
class InputIterator,
class InputRandomIterator,
class OutputIterator,
class SetOp>
OutputIterator
msg_right_permutation_apply (
InputIterator perm,
InputIterator last_perm,
const InputRandomIterator& x,
OutputIterator y,
SetOp set_op)
{
for (; perm != last_perm; y++, perm++) {
// something like: (*y++) = x[(*perm++)];
set_op (y, x, *perm);
}
return y;
}
//>msg_right_permutation_apply:
// set(rhs,lhs,i) <==> *rhs = lhs[i] or *rhs = pair(i,rhs[i])
// 1) used by csr<Float>:
template<class OutputIterator, class InputRandomIterator, class Size>
struct msg_right_permutation_set_default {
void operator() (OutputIterator rhs, const InputRandomIterator& lhs, Size i) {
*rhs = lhs [i];
}
};
template <
class InputIterator,
class InputRandomIterator,
class OutputIterator>
inline
OutputIterator
msg_right_permutation_apply (
InputIterator perm,
InputIterator last_perm,
const InputRandomIterator& x,
OutputIterator y)
{
typedef typename std::iterator_traits<InputIterator>::value_type size_type;
msg_right_permutation_set_default<OutputIterator, InputRandomIterator, size_type> set_op;
return msg_right_permutation_apply (perm, last_perm, x, y, set_op);
}
#ifdef TO_CLEAN
// used by polymorphic_array<geo_element> in geo<Float>:
template<class OutputIterator, class InputRandomIterator, class Size>
struct msg_right_permutation_set_pair {
typedef typename std::iterator_traits<OutputIterator>::value_type T;
void operator() (OutputIterator rhs, const InputRandomIterator& lhs, Size i) {
*rhs = std::pair<Size,T>(i,lhs [i]);
}
};
#endif // TO_CLEAN
} // namespace rheolef
#endif // _RHEO_MSG_RIGHT_PERMUTATION_APPLY_H
rheolef::msg_right_permutation_set_default
Definition: msg_right_permutation_apply.h:76
rheolef::size_type
size_t size_type
Definition: basis_get.cc:76
rheolef::msg_right_permutation_set_default::operator()
void operator()(OutputIterator rhs, const InputRandomIterator &lhs, Size i)
Definition: msg_right_permutation_apply.h:77
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::msg_right_permutation_apply
OutputIterator msg_right_permutation_apply(InputIterator perm, InputIterator last_perm, const InputRandomIterator &x, OutputIterator y, SetOp set_op)
Definition: msg_right_permutation_apply.h:57
rheolef::set_op
Definition: msg_util.h:56
T
Expr1::float_type T
Definition: field_expr.h:218