| 483 | |
| 484 | template <typename T> |
| 485 | typename disable_if<is_matrix<T>,T>::type subtract ( |
| 486 | const T& a, |
| 487 | const T& b |
| 488 | ) |
| 489 | { |
| 490 | T temp; |
| 491 | |
| 492 | typename T::const_iterator i = a.begin(); |
| 493 | typename T::const_iterator j = b.begin(); |
| 494 | while (i != a.end() && j != b.end()) |
| 495 | { |
| 496 | if (i->first == j->first) |
| 497 | { |
| 498 | temp.insert(temp.end(), std::make_pair(i->first, i->second - j->second)); |
| 499 | ++i; |
| 500 | ++j; |
| 501 | } |
| 502 | else if (i->first < j->first) |
| 503 | { |
| 504 | temp.insert(temp.end(), *i); |
| 505 | ++i; |
| 506 | } |
| 507 | else |
| 508 | { |
| 509 | temp.insert(temp.end(), std::make_pair(j->first, -j->second)); |
| 510 | ++j; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | while (i != a.end()) |
| 515 | { |
| 516 | temp.insert(temp.end(), *i); |
| 517 | ++i; |
| 518 | } |
| 519 | while (j != b.end()) |
| 520 | { |
| 521 | temp.insert(temp.end(), std::make_pair(j->first, -j->second)); |
| 522 | ++j; |
| 523 | } |
| 524 | |
| 525 | return temp; |
| 526 | } |
| 527 | |
| 528 | template <typename T, typename U> |
| 529 | typename enable_if_c<is_matrix<T>::value && is_matrix<U>::value, matrix_subtract_exp<T,U> >::type subtract ( |