> > (I would have expected something else) > We're always happy to receive contributions <https://github.com/dealii/dealii/compare> that improve the documentation! :-)
On Thursday, July 20, 2017 at 1:33:37 PM UTC+2, Maxi Miller wrote: > > Slightly confusing (I would have expected something else), but that > explains it. Thanks! > > Am Donnerstag, 20. Juli 2017 13:23:46 UTC+2 schrieb Jean-Paul Pelteret: >> >> Dear Maxi, >> >> The documentation for the alternate version of the function >> <http://dealii.org/developer/doxygen/deal.II/classVector.html#ad8919a8962fc120d69ba6ef7a5c7bfcf> >> >> gives a hint at whats going on here. The iterators that you're sending in >> are not the start and end point for the data to be copied, but rather the >> indices of the elements in the current vector that are being copied out. So >> what you're actually asking to do is to get the data at index positions [ >> vec_1.begin()+vec_2.size(), vec_1.begin()+2*vec_2.size()) == [4,8) in >> vec_1 and copy it to vec_2. You'll see that the arguemnts in the >> function that you're calling are named "indices_begin" and "indices_end". >> So when you increment the values in vec_1 you end up asking for the next >> elements when copying out the data. >> >> What I think you want to do is something like this: >> 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.; >> >> const std::vector< size_type > indices = {3,4,5}; >> vec_1.extract_subvector_to(indices.begin(), indices.end(), vec_2.begin >> ()); // or vec_1.extract_subvector_to(indices, vec_2.begin()); >> >> >> >> I hope that this clarifies the behaviour that you're seeing. >> >> Regards, >> Jean-Paul >> >> On Thursday, July 20, 2017 at 10:30:22 AM UTC+2, Maxi Miller wrote: >>> >>> 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.
