SpValProxy_bones.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup SpValProxy
  16. //! @{
  17. // Sparse value proxy class, to prevent inserting 0s into sparse matrices.
  18. // T1 must be either SpMat or SpSubview.
  19. // This class uses T1::insert_element(), T1::delete_element(), T1::invalidate_cache()
  20. template<typename T1>
  21. class SpValProxy
  22. {
  23. public:
  24. typedef typename T1::elem_type eT; // Convenience typedef
  25. friend class SpMat<eT>;
  26. friend class SpSubview<eT>;
  27. /**
  28. * Create the sparse value proxy.
  29. * Otherwise, pass a pointer to a reference of the value.
  30. */
  31. arma_inline SpValProxy(uword row, uword col, T1& in_parent, eT* in_val_ptr = NULL);
  32. //! For swapping operations.
  33. arma_inline SpValProxy& operator=(const SpValProxy& rhs);
  34. template<typename T2>
  35. arma_inline SpValProxy& operator=(const SpValProxy<T2>& rhs);
  36. //! Overload all of the potential operators.
  37. //! First, the ones that could modify a value.
  38. arma_inline SpValProxy& operator=(const eT rhs);
  39. arma_inline SpValProxy& operator+=(const eT rhs);
  40. arma_inline SpValProxy& operator-=(const eT rhs);
  41. arma_inline SpValProxy& operator*=(const eT rhs);
  42. arma_inline SpValProxy& operator/=(const eT rhs);
  43. arma_inline SpValProxy& operator++();
  44. arma_inline SpValProxy& operator--();
  45. arma_inline eT operator++(const int);
  46. arma_inline eT operator--(const int);
  47. //! This will work for any other operations that do not modify a value.
  48. arma_inline operator eT() const;
  49. arma_inline typename get_pod_type<eT>::result real() const;
  50. arma_inline typename get_pod_type<eT>::result imag() const;
  51. private:
  52. // Deletes the element if it is zero. Does not check if val_ptr == NULL!
  53. arma_inline void check_zero();
  54. arma_aligned const uword row;
  55. arma_aligned const uword col;
  56. arma_aligned eT* val_ptr;
  57. arma_aligned T1& parent; // We will call this object if we need to insert or delete an element.
  58. };
  59. //! @}