SOLIDstate
A C++ library for solid state physics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
DirectSum.hpp
Go to the documentation of this file.
1 #ifndef MISC_DIRECTSUM_HPP
2 #define MISC_DIRECTSUM_HPP
3 
4 #include <armadillo>
5 #include <type_traits>
6 
7 namespace solid
8 {
9 
28 template <template <typename> class T1, typename T2>
29 T1<T2> DirectSum(T1<T2> A, T1<T2> B)
30 {
31  unsigned long int ncA = A.n_cols;
32  unsigned long int ncB = B.n_cols;
33  unsigned long int nrA = A.n_rows;
34  unsigned long int nrB = B.n_rows;
35 
36  T1<T2> ret(nrA + nrB, ncA + ncB);
37 
38  if constexpr (std::is_same<T1<T2>, arma::Mat<T2>>::value)
39  ret.fill(0);
40  ret.submat(0, 0, nrA - 1, ncA - 1) = A;
41  ret.submat(nrA, ncA, nrA + nrB - 1, ncA + ncB - 1) = B;
42  return ret;
43 }
44 
45 } // namespace solid
46 
47 #endif
T1< T2 > DirectSum(T1< T2 > A, T1< T2 > B)
Direct sum of two matrices.
Definition: DirectSum.hpp:29