本文整理汇总了C++中VP::assign_temporary方法的典型用法代码示例。如果您正苦于以下问题:C++ VP::assign_temporary方法的具体用法?C++ VP::assign_temporary怎么用?C++ VP::assign_temporary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VP
的用法示例。
在下文中一共展示了VP::assign_temporary方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_with
void test_with (VP &v1, VP &v2, VP &v3) const {
{
value_type t;
size_type i;
real_type n;
// Default Construct
default_construct<VP>::test ();
// Copy and swap
initialize_vector (v1);
initialize_vector (v2);
v1 = v2;
std::cout << "v1 = v2 = " << v1 << std::endl;
v1.assign_temporary (v2);
std::cout << "v1.assign_temporary (v2) = " << v1 << std::endl;
v1.swap (v2);
std::cout << "v1.swap (v2) = " << v1 << " " << v2 << std::endl;
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
// Project range and slice
initialize_vector (v1);
initialize_vector (v2);
project (v1, ublas::range(0,1)) = project (v2, ublas::range(0,1));
project (v1, ublas::range(0,1)) = project (v2, ublas::slice(0,1,1));
project (v1, ublas::slice(2,-1,2)) = project (v2, ublas::slice(0,1,2));
project (v1, ublas::slice(2,-1,2)) = project (v2, ublas::range(0,2));
std::cout << "v1 = range/slice " << v1 << std::endl;
#endif
// Unary vector operations resulting in a vector
initialize_vector (v1);
v2 = - v1;
std::cout << "- v1 = " << v2 << std::endl;
v2 = ublas::conj (v1);
std::cout << "conj (v1) = " << v2 << std::endl;
// Binary vector operations resulting in a vector
initialize_vector (v1);
initialize_vector (v2);
initialize_vector (v3);
v3 = v1 + v2;
std::cout << "v1 + v2 = " << v3 << std::endl;
v3 = v1 - v2;
std::cout << "v1 - v2 = " << v3 << std::endl;
// Scaling a vector
t = N;
initialize_vector (v1);
v2 = value_type (1.) * v1;
std::cout << "1. * v1 = " << v2 << std::endl;
v2 = t * v1;
std::cout << "N * v1 = " << v2 << std::endl;
initialize_vector (v1);
v2 = v1 * value_type (1.);
std::cout << "v1 * 1. = " << v2 << std::endl;
v2 = v1 * t;
std::cout << "v1 * N = " << v2 << std::endl;
// Some assignments
initialize_vector (v1);
initialize_vector (v2);
v2 += v1;
std::cout << "v2 += v1 = " << v2 << std::endl;
v2 -= v1;
std::cout << "v2 -= v1 = " << v2 << std::endl;
v2 = v2 + v1;
std::cout << "v2 = v2 + v1 = " << v2 << std::endl;
v2 = v2 - v1;
std::cout << "v2 = v2 - v1 = " << v2 << std::endl;
v1 *= value_type (1.);
std::cout << "v1 *= 1. = " << v1 << std::endl;
v1 *= t;
std::cout << "v1 *= N = " << v1 << std::endl;
// Unary vector operations resulting in a scalar
initialize_vector (v1);
t = ublas::sum (v1);
std::cout << "sum (v1) = " << t << std::endl;
n = ublas::norm_1 (v1);
std::cout << "norm_1 (v1) = " << n << std::endl;
n = ublas::norm_2 (v1);
std::cout << "norm_2 (v1) = " << n << std::endl;
n = ublas::norm_inf (v1);
std::cout << "norm_inf (v1) = " << n << std::endl;
i = ublas::index_norm_inf (v1);
std::cout << "index_norm_inf (v1) = " << i << std::endl;
// Binary vector operations resulting in a scalar
initialize_vector (v1);
initialize_vector (v2);
t = ublas::inner_prod (v1, v2);
std::cout << "inner_prod (v1, v2) = " << t << std::endl;
}
}
示例2: operator
void operator () (VP &v1, VP &v2, VP &v3) const {
try {
value_type t;
size_type i;
real_type n;
// Copy and swap
initialize_vector (v1);
initialize_vector (v2);
v1 = v2;
std::cout << "v1 = v2 = " << v1 << std::endl;
v1.assign_temporary (v2);
std::cout << "v1.assign_temporary (v2) = " << v1 << std::endl;
v1.swap (v2);
std::cout << "v1.swap (v2) = " << v1 << " " << v2 << std::endl;
// Unary vector operations resulting in a vector
initialize_vector (v1);
v2 = - v1;
std::cout << "- v1 = " << v2 << std::endl;
v2 = ublas::conj (v1);
std::cout << "conj (v1) = " << v2 << std::endl;
// Binary vector operations resulting in a vector
initialize_vector (v1);
initialize_vector (v2);
v3 = v1 + v2;
std::cout << "v1 + v2 = " << v3 << std::endl;
v3 = v1 - v2;
std::cout << "v1 - v2 = " << v3 << std::endl;
// Scaling a vector
t = N;
initialize_vector (v1);
v2 = value_type (1.) * v1;
std::cout << "1. * v1 = " << v2 << std::endl;
v2 = t * v1;
std::cout << "N * v1 = " << v2 << std::endl;
initialize_vector (v1);
v2 = v1 * value_type (1.);
std::cout << "v1 * 1. = " << v2 << std::endl;
v2 = v1 * t;
std::cout << "v1 * N = " << v2 << std::endl;
// Some assignments
initialize_vector (v1);
initialize_vector (v2);
#ifdef BOOST_UBLAS_USE_ET
v2 += v1;
std::cout << "v2 += v1 = " << v2 << std::endl;
v2 -= v1;
std::cout << "v2 -= v1 = " << v2 << std::endl;
#else
v2 = v2 + v1;
std::cout << "v2 += v1 = " << v2 << std::endl;
v2 = v2 - v1;
std::cout << "v2 -= v1 = " << v2 << std::endl;
#endif
v1 *= value_type (1.);
std::cout << "v1 *= 1. = " << v1 << std::endl;
v1 *= t;
std::cout << "v1 *= N = " << v1 << std::endl;
// Unary vector operations resulting in a scalar
initialize_vector (v1);
t = ublas::sum (v1);
std::cout << "sum (v1) = " << t << std::endl;
n = ublas::norm_1 (v1);
std::cout << "norm_1 (v1) = " << n << std::endl;
n = ublas::norm_2 (v1);
std::cout << "norm_2 (v1) = " << n << std::endl;
n = ublas::norm_inf (v1);
std::cout << "norm_inf (v1) = " << n << std::endl;
i = ublas::index_norm_inf (v1);
std::cout << "index_norm_inf (v1) = " << i << std::endl;
// Binary vector operations resulting in a scalar
initialize_vector (v1);
initialize_vector (v2);
t = ublas::inner_prod (v1, v2);
std::cout << "inner_prod (v1, v2) = " << t << std::endl;
}
catch (std::exception &e) {
std::cout << e.what () << std::endl;
}
catch (...) {
std::cout << "unknown exception" << std::endl;
}
}
示例3: test_with
void test_with (VP &v1, VP &v2, VP &v3) const {
{
value_type t;
size_type i;
real_type n;
// Copy and swap
initialize_vector (v1);
initialize_vector (v2);
v1 = v2;
std::cout << "v1 = v2 = " << v1 << std::endl;
v1.assign_temporary (v2);
std::cout << "v1.assign_temporary (v2) = " << v1 << std::endl;
v1.swap (v2);
std::cout << "v1.swap (v2) = " << v1 << " " << v2 << std::endl;
// Zero assignment
v1 = ublas::zero_vector<value_type> (v1.size ());
std::cout << "v1.zero_vector = " << v1 << std::endl;
v1 = v2;
// Unary vector operations resulting in a vector
initialize_vector (v1);
v2 = - v1;
std::cout << "- v1 = " << v2 << std::endl;
v2 = ublas::conj (v1);
std::cout << "conj (v1) = " << v2 << std::endl;
// Binary vector operations resulting in a vector
initialize_vector (v1);
initialize_vector (v2);
v3 = v1 + v2;
std::cout << "v1 + v2 = " << v3 << std::endl;
v3 = v1 - v2;
std::cout << "v1 - v2 = " << v3 << std::endl;
// Scaling a vector
t = value_type (N);
initialize_vector (v1);
v2 = value_type (1.) * v1;
std::cout << "1. * v1 = " << v2 << std::endl;
// v2 = t * v1;
std::cout << "N * v1 = " << v2 << std::endl;
initialize_vector (v1);
// v2 = v1 * value_type (1.);
std::cout << "v1 * 1. = " << v2 << std::endl;
// v2 = v1 * t;
std::cout << "v1 * N = " << v2 << std::endl;
// Some assignments
initialize_vector (v1);
initialize_vector (v2);
v2 += v1;
std::cout << "v2 += v1 = " << v2 << std::endl;
v2 -= v1;
std::cout << "v2 -= v1 = " << v2 << std::endl;
v2 = v2 + v1;
std::cout << "v2 = v2 + v1 = " << v2 << std::endl;
v2 = v2 - v1;
std::cout << "v2 = v2 - v1 = " << v2 << std::endl;
v1 *= value_type (1.);
std::cout << "v1 *= 1. = " << v1 << std::endl;
v1 *= t;
std::cout << "v1 *= N = " << v1 << std::endl;
// Unary vector operations resulting in a scalar
initialize_vector (v1);
t = ublas::sum (v1);
std::cout << "sum (v1) = " << t << std::endl;
n = ublas::norm_1 (v1);
std::cout << "norm_1 (v1) = " << n << std::endl;
n = ublas::norm_2 (v1);
std::cout << "norm_2 (v1) = " << n << std::endl;
n = ublas::norm_inf (v1);
std::cout << "norm_inf (v1) = " << n << std::endl;
i = ublas::index_norm_inf (v1);
std::cout << "index_norm_inf (v1) = " << i << std::endl;
// Binary vector operations resulting in a scalar
initialize_vector (v1);
initialize_vector (v2);
t = ublas::inner_prod (v1, v2);
std::cout << "inner_prod (v1, v2) = " << t << std::endl;
}
}