spop_symmat_meat.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 spop_symmat
  16. //! @{
  17. template<typename T1>
  18. inline
  19. void
  20. spop_symmat::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_symmat>& in)
  21. {
  22. arma_extra_debug_sigprint();
  23. typedef typename T1::elem_type eT;
  24. const unwrap_spmat<T1> U(in.m);
  25. const SpMat<eT>& X = U.M;
  26. arma_debug_check( (X.n_rows != X.n_cols), "symmatu()/symmatl(): given matrix must be square sized" );
  27. if(X.n_nonzero == uword(0)) { out.zeros(X.n_rows, X.n_cols); return; }
  28. const bool upper = (in.aux_uword_a == 0);
  29. const SpMat<eT> A = (upper) ? trimatu(X) : trimatl(X); // in this case trimatu() and trimatl() return the same type
  30. const SpMat<eT> B = A.st();
  31. spglue_merge::symmat_merge(out, A, B);
  32. }
  33. template<typename T1>
  34. inline
  35. void
  36. spop_symmat_cx::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_symmat_cx>& in)
  37. {
  38. arma_extra_debug_sigprint();
  39. typedef typename T1::elem_type eT;
  40. const unwrap_spmat<T1> U(in.m);
  41. const SpMat<eT>& X = U.M;
  42. arma_debug_check( (X.n_rows != X.n_cols), "symmatu()/symmatl(): given matrix must be square sized" );
  43. if(X.n_nonzero == uword(0)) { out.zeros(X.n_rows, X.n_cols); return; }
  44. const bool upper = (in.aux_uword_a == 0);
  45. const bool do_conj = (in.aux_uword_b == 1);
  46. const SpMat<eT> A = (upper) ? trimatu(X) : trimatl(X); // in this case trimatu() and trimatl() return the same type
  47. if(do_conj)
  48. {
  49. const SpMat<eT> B = A.t();
  50. spglue_merge::symmat_merge(out, A, B);
  51. }
  52. else
  53. {
  54. const SpMat<eT> B = A.st();
  55. spglue_merge::symmat_merge(out, A, B);
  56. }
  57. }
  58. //! @}