#include #include namespace triqs { namespace arrays { // better to put it in this namespace for ADL... template class immutable_diagonal_matrix_view { array_view data; // the diagonal stored as a 1d array public: immutable_diagonal_matrix_view(array_view v) : data(v) {} // constructor // the ImmutableMatrix concept typedef indexmaps::cuboid::domain_t<2> domain_type; domain_type domain() const { auto s = data.shape()[0]; return {s, s}; } typedef T value_type; T operator()(size_t i, size_t j) const { return (i == j ? data(i) : 0); } // just kronecker... friend std::ostream &operator<<(std::ostream &out, immutable_diagonal_matrix_view const &d) { return out << "diagonal_matrix " << d.data; } }; // Marking this class as belonging to the Matrix & Vector algebra. template struct ImmutableMatrix> : std::true_type {}; } } /// TESTING using namespace triqs::arrays; int main(int argc, char **argv) { auto a = array{1, 2, 3, 4}; auto d = immutable_diagonal_matrix_view{a}; std::cout << "domain = " << d.domain() << std::endl; std::cout << "d = " << d << std::endl; std::cout << "2*d = " << make_matrix(2 * d) << std::endl; std::cout << "d*d = " << matrix(d * d) << std::endl; }