I wanted to test how to use the function 
extract_subvector_to

in order to slice a part of a vector and put the result into another vector.
Using a short test program

    Vector<double> vec_1 = Vector<double>(9);
    Vector<double> vec_2 = Vector<double>(vec_1.size()/3);
    for(size_t i = 0; i < vec_1.size(); ++i)
        vec_1(i) = i+1;
    vec_2 = 0.;
    std::cout << "Before: \n";
    std::cout << vec_1 << '\n';
    std::cout << vec_2 << '\n';
    std::cout << "After: \n";
    vec_1.extract_subvector_to(vec_1.begin()+vec_2.size(), vec_1.begin()+2*
vec_2.size(), vec_2.begin());
    std::cout << vec_1 << '\n';
    std::cout << vec_2 << '\n';

I got
Before: 
1.000e+00 2.000e+00 3.000e+00 4.000e+00 5.000e+00 6.000e+00 7.000e+00 
8.000e+00 9.000e+00 

0.000e+00 0.000e+00 0.000e+00 

After: 
1.000e+00 2.000e+00 3.000e+00 4.000e+00 5.000e+00 6.000e+00 7.000e+00 
8.000e+00 9.000e+00 

5.000e+00 6.000e+00 7.000e+00 

but I would have expected for the last line to be something like
4.000e+00 5.000e+00 6.000e+00
after I start at position 3 (size of vec_2), which value is 4, and not 5.

Furthermore, when changing the line 
vec_1(i) = i+1;
to
vec_1(i) = i+2;
my output result in the last line changes to 
7.000e+00 8.000e+00 9.000e+00
thus indicating that I am now picking up the value at position 5, and not 3.

Am I misunderstanding something? Afaik vec_1.begin() should point at the 
beginning of vec_1, and not at the beginning of vec_1 + the value of 
vec_1[0]?




-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to