Ignore:
Timestamp:
Feb 7, 2017, 8:48:23 AM (6 years ago)
Author:
Peter
Message:

fixes #884

Element-by-element operations in VectorMutable? such as operator+=,
operator-=, mul, and div did not work, when underlying data structure
of lhs and rhs overlap such that elements in rhs are affected by the
operation on lhs before they have been used on rhs. The fix is to use
a temporary Vector when there is risk for overlap.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/0.14-stable/test/vector.cc

    r3616 r3618  
    439439  utility::VectorConstView const_view(vec, 0, 5, 1);
    440440  view += const_view;
    441   suite.out() << "result: " << view << "\n";
    442441  for (size_t i=0; i<view.size(); ++i) {
    443     if (i==2 || i==4)
    444       suite.xadd(suite.equal(view(i), 2));
    445     else
    446       suite.add(suite.equal(view(i), 2));
    447   }
    448 }
     442    suite.add(suite.equal(view(i), 2));
     443  }
     444
     445  // vec =     { 2, 1, 2, 1, 2, 1, 2, 1, 2, 1}
     446  // view =    { 2,    2,    2,    2,    2}
     447  // const_view{ 2, 1, 2, 1, 2}
     448  view = const_view;
     449  // view =    { 2,    1,    2,    1,    2}
     450  utility::Vector correct(5);
     451  correct(0) = 2;
     452  correct(1) = 1;
     453  correct(2) = 2;
     454  correct(3) = 1;
     455  correct(4) = 2;
     456  if (view != correct) {
     457    suite.add(false);
     458    suite.err() << "error: view: \n" << view << "\nexpected: " << correct
     459                << "\n";
     460  }
     461}
Note: See TracChangeset for help on using the changeset viewer.