typename _matmul_rvalue<A,B>::type operator * (A const & a, B const & b) { if (second_dim(a) != first_dim(b)) TRIQS_RUNTIME_ERROR<< "Matrix product : dimension mismatch in A*B "<< a<<" "<< b; auto R = typename _matmul_rvalue<A,B>::type( first_dim(a), second_dim(b)); blas::gemm(1.0,a, b, 0.0, R); return R; }
typename _mat_vec_mul_rvalue<M,V>::type operator * (M const & m, V const & v) { if (second_dim(m) != v.size()) TRIQS_RUNTIME_ERROR<< "Matrix product : dimension mismatch in Matrix*Vector "<< m<<" "<< v; auto R = typename _mat_vec_mul_rvalue<M,V>::type(first_dim(m)); blas::gemv(1.0,m,v,0.0,R); return R; }
matrix<double> impurity_trace::check_one_block_matrix_linear(node top, int b, bool print) { node p = tree.max(top); matrix<double> M = make_unit_matrix<double>(get_block_dim(b)); auto _ = arrays::range(); foreach_reverse(tree, top, [&](node n) { // multiply by the exponential unless it is the first call, i.e. first operator n==p if (n != p) { auto dtau = double(n->key - p->key); // M <- exp * M auto dim = first_dim(M); // same as get_block_dim(b1); for (int i = 0; i < dim; ++i) M(i, _) *= std::exp(-dtau * get_block_eigenval(b, i)); // M <- Op * M } // multiply by operator matrix unless it is delete_flag if (!n->delete_flag) { int bp = this->get_op_block_map(n, b); if (bp == -1) TRIQS_RUNTIME_ERROR << " Nasty error "; M = get_op_block_matrix(n, b) * M; b = bp; } p = n; }); return M; }
typename std::enable_if<is_blas_lapack_type<typename VTX::value_type>::value && have_same_value_type<VTX, VTY, MT>::value>::type ger(typename VTX::value_type alpha, VTX const &X, VTY const &Y, MT &A) { static_assert(is_amv_value_or_view_class<MT>::value, "ger : A must be a matrix or a matrix_view"); if ((first_dim(A) != Y.size()) || (second_dim(A) != X.size())) TRIQS_RUNTIME_ERROR << "Dimension mismatch in ger : A : " << get_shape(A()) << " while X : " << get_shape(X()) << " and Y : " << get_shape(Y()); const_qcache<VTX> Cx(X); // mettre la condition a la main const_qcache<VTY> Cy(Y); // mettre la condition a la main reflexive_qcache<MT> Ca(A); if (Ca().memory_layout_is_c()) // tA += alpha y tx f77::ger(get_n_rows(Ca()), get_n_cols(Ca()), alpha, Cy().data_start(), Cy().stride(), Cx().data_start(), Cx().stride(), Ca().data_start(), get_ld(Ca())); else f77::ger(get_n_rows(Ca()), get_n_cols(Ca()), alpha, Cx().data_start(), Cx().stride(), Cy().data_start(), Cy().stride(), Ca().data_start(), get_ld(Ca())); /* std::cerr << " Meme labout C"<< Ca().memory_layout_is_c() << " "<<A.memory_layout_is_c()<<std::endl ; std::cerr<< " has_contiguous_data(A) : "<< has_contiguous_data(A) << std::endl; std::cerr<< Ca()<< std::endl; std::cerr<< Ca()(0,0) << " "<< Ca()(1,0) << " "<< Ca()(0,1) << " "<< Ca()(1,1) << " "<< std::endl; std::cerr<< Ca().data_start()[0]<< " "<< Ca().data_start()[1]<< " "<< Ca().data_start()[2]<< " " << Ca().data_start()[3]<< " "<<std::endl; std::cerr<< A<< std::endl; std::cerr<< A(0,0) << " "<< A(1,0) << " "<< A(0,1) << " "<< A(1,1) << " "<< std::endl; std::cerr<< A.data_start()[0]<< " "<< A.data_start()[1]<< " "<< A.data_start()[2]<< " " << A.data_start()[3]<< " "<<std::endl; */ }
double operator()(configuration const& c) const { auto delta = (rhs - kern(c)) / error_bars; int M = first_dim(delta); double kappa = 0; for(int i = 1; i < M; ++i) kappa += corr(delta(i), delta(i-1)); kappa /= M - 1; return kappa; }
eigenelements_worker_base ( matrix_view <T,Opt> the_matrix) : mat(the_matrix) { if (mat.is_empty()) TRIQS_RUNTIME_ERROR<<"eigenelements_worker : the matrix is empty : matrix = "<<mat<<" "; if (!mat.is_square()) TRIQS_RUNTIME_ERROR<<"eigenelements_worker : the matrix "<<mat<<" is not square "; if (!mat.indexmap().is_contiguous()) TRIQS_RUNTIME_ERROR<<"eigenelements_worker : the matrix "<<mat<<" is not contiguous in memory"; dim = first_dim(mat); ev.resize(dim); lwork = 64*dim; work.resize(lwork); uplo='U';compz='N' ; has_run = false; }
double trace_rho_op(block_matrix_t const& density_matrix, many_body_op_t const& op, atom_diag const& atom) { h_scalar_t result = 0; if (atom.n_blocks() != density_matrix.size()) TRIQS_RUNTIME_ERROR << "trace_rho_op : size mismatch : number of blocks differ"; for (int bl = 0; bl < atom.n_blocks(); ++bl) { if (atom.get_block_dim(bl) != first_dim(density_matrix[bl])) TRIQS_RUNTIME_ERROR << "trace_rho_op : size mismatch : size of block " << bl << " differ"; for (auto const& x : op) { auto b_m = atom.matrix_element_of_monomial(x.monomial, bl); if (b_m.first == bl) result += x.coef * dot_product(b_m.second, density_matrix[bl]); } } if (imag(result) > threshold) TRIQS_RUNTIME_ERROR << "trace_rho_op: the result is not real."; return real(result); }
//--------------------------------- void _invoke(triqs::mpi::tag::scatter) { lhs.resize(laz.domain()); auto c = laz.c; auto slow_size = first_dim(laz.ref); auto slow_stride = laz.ref.indexmap().strides()[0]; auto sendcounts = std::vector<int>(c.size()); auto displs = std::vector<int>(c.size() + 1, 0); int recvcount = mpi::slice_length(slow_size - 1, c.size(), c.rank()) * slow_stride; for (int r = 0; r < c.size(); ++r) { sendcounts[r] = mpi::slice_length(slow_size - 1, c.size(), r) * slow_stride; displs[r + 1] = sendcounts[r] + displs[r]; } MPI_Scatterv((void *)laz.ref.data_start(), &sendcounts[0], &displs[0], D(), (void *)lhs.data_start(), recvcount, D(), laz.root, c.get()); }
std::c14::enable_if_t<is_amv_value_or_view_class<ArrayType>::value && !has_scalar_or_string_value_type<ArrayType>::value> h5_read(h5::group gr, std::string name, ArrayType& a) { static_assert(!std::is_const<ArrayType>::value, "Cannot read in const object"); auto gr2 = gr.open_group(name); // TODO checking scheme... // load the shape auto sha2 = a.shape(); array<int, 1> sha; h5_read(gr2, "shape", sha); if (first_dim(sha) != sha2.size()) TRIQS_RUNTIME_ERROR << " array<array<...>> load : rank mismatch. Expected " << sha2.size()<< " Got " << first_dim(sha); for (int u = 0; u < sha2.size(); ++u) sha2[u] = sha(u); if (a.shape() != sha2) a.resize(sha2); #ifndef __cpp_generic_lambdas foreach(a, h5_impl::_load_lambda<ArrayType>{a, gr2}); #else foreach(a, [&](auto... is) { h5_read(gr2, h5_impl::_h5_name(is...), a(is...)); }); #endif }
/// compute the array domain of the target array domain_type domain() const { auto dims = ref.shape(); long slow_size = first_dim(ref); if (std::is_same<Tag, mpi::tag::scatter>::value) { mpi::mpi_broadcast(slow_size, c, root); dims[0] = mpi::slice_length(slow_size - 1, c.size(), c.rank()); } if (std::is_same<Tag, mpi::tag::gather>::value) { if (!all) { dims[0] = mpi::mpi_reduce(slow_size, c, root); // valid only on root if (c.rank() != root) dims[0] = 1; // valid only on root } else dims[0] = mpi::mpi_all_reduce(slow_size, c, root); // in this case, it is valid on all nodes } // mpi::tag::reduce :do nothing return domain_type{dims}; }
void invoke() { if (!has_contiguous_data(lhs)) TRIQS_RUNTIME_ERROR << "mpi scatter of array into a non contiguous view"; resize_or_check_if_view(lhs, laz.domain().lengths()); auto c = laz.c; auto slow_size = first_dim(laz.ref); auto slow_stride = laz.ref.indexmap().strides()[0]; auto sendcounts = std::vector<int>(c.size()); auto displs = std::vector<int>(c.size() + 1, 0); int recvcount = mpi::slice_length(slow_size - 1, c.size(), c.rank()) * slow_stride; auto D = mpi::mpi_datatype<typename A::value_type>(); for (int r = 0; r < c.size(); ++r) { sendcounts[r] = mpi::slice_length(slow_size - 1, c.size(), r) * slow_stride; displs[r + 1] = sendcounts[r] + displs[r]; } MPI_Scatterv((void *)laz.ref.data_start(), &sendcounts[0], &displs[0], D, (void *)lhs.data_start(), recvcount, D, laz.root, c.get()); }
/// compute the array domain of the target array domain_type domain() const { auto dims = ref.shape(); long slow_size = first_dim(ref); // tag::reduce and all_reduce : do nothing if (std::is_same<Tag, tag::scatter>::value) { mpi::broadcast(slow_size, c, root); dims[0] = mpi::slice_length(slow_size - 1, c.size(), c.rank()); } if (std::is_same<Tag, tag::gather>::value) { auto s = mpi::reduce(slow_size, c, root); dims[0] = (c.rank()==root ? s : 1); // valid only on root } if (std::is_same<Tag, tag::allgather>::value) { dims[0] = mpi::all_reduce(slow_size, c, root); // in this case, it is valid on all nodes } return domain_type{dims}; }
// returns the # of cols of the matrix *seen* as fortran matrix template <typename MatrixType> int get_n_cols (MatrixType const & A) { return (A.memory_layout_is_fortran() ? second_dim(A) : first_dim(A)); }
void write_array(h5::group g, std::string const& name, array_const_view<std::string, 1> V) { std::vector<std::string> tmp(first_dim(V)); std::copy(begin(V), end(V), begin(tmp)); h5_write(g, name, tmp); }
det_and_inverse_worker (ViewType const & a): V(a), dim(first_dim(a)), ipiv(dim), step(0) { if (first_dim(a)!=second_dim(a)) TRIQS_RUNTIME_ERROR<<"Inverse/Det error : non-square matrix. Dimensions are : ("<<first_dim(a)<<","<<second_dim(a)<<")"<<"\n "; if (!(has_contiguous_data(a))) TRIQS_RUNTIME_ERROR<<"det_and_inverse_worker only takes a contiguous view"; }
template <typename AA> inverse_lazy(AA &&a_) : a(std::forward<AA>(a_)), M{}, computed{false} { if (first_dim(a) != second_dim(a)) TRIQS_RUNTIME_ERROR << "Inverse : matrix is not square but of size " << first_dim(a) << " x " << second_dim(a); }