votca 2024.2-dev
Loading...
Searching...
No Matches
matrixfreeoperator.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
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 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18#pragma once
19#ifndef VOTCA_XTP_MATRIXFREEOPERATOR_H
20#define VOTCA_XTP_MATRIXFREEOPERATOR_H
21
22// Local VOTCA includes
23#include "eigen.h"
24
25namespace votca {
26namespace xtp {
27
28class MatrixFreeOperator;
29}
30} // namespace votca
31namespace Eigen {
32namespace internal {
33// MatrixReplacement looks-like a Matrix, so let's inherits its traits:
34template <>
35struct traits<votca::xtp::MatrixFreeOperator>
36 : public Eigen::internal::traits<Eigen::MatrixXd> {};
37} // namespace internal
38} // namespace Eigen
39
40namespace votca {
41namespace xtp {
42
43class MatrixFreeOperator : public Eigen::EigenBase<MatrixFreeOperator> {
44 public:
45 enum {
46 ColsAtCompileTime = Eigen::Dynamic,
47 MaxColsAtCompileTime = Eigen::Dynamic,
48 IsRowMajor = false
49 };
50
51 Index rows() const { return this->size_; }
52 Index cols() const { return this->size_; }
53
54 template <typename Vtype>
55 Eigen::Product<MatrixFreeOperator, Vtype, Eigen::AliasFreeProduct> operator*(
56 const Eigen::MatrixBase<Vtype>& x) const {
57 return Eigen::Product<MatrixFreeOperator, Vtype, Eigen::AliasFreeProduct>(
58 *this, x.derived());
59 }
60
61 virtual Eigen::VectorXd diagonal() const = 0;
62 virtual Eigen::MatrixXd matmul(const Eigen::MatrixXd& input) const = 0;
63 Index size() const;
64 void set_size(Index size);
65
66 private:
68};
69} // namespace xtp
70} // namespace votca
71
72namespace Eigen {
73
74namespace internal {
75
76// replacement of the mat*mat operation
77template <typename Mtype>
78struct generic_product_impl<votca::xtp::MatrixFreeOperator, Mtype, DenseShape,
79 DenseShape, GemmProduct>
80 : generic_product_impl_base<
81 votca::xtp::MatrixFreeOperator, Mtype,
82 generic_product_impl<votca::xtp::MatrixFreeOperator, Mtype>> {
83
84 typedef
85 typename Product<votca::xtp::MatrixFreeOperator, Mtype>::Scalar Scalar;
86
87 template <typename Dest>
88 static void scaleAndAddTo(Dest& dst, const votca::xtp::MatrixFreeOperator& op,
89 const Mtype& m, const Scalar& alpha) {
90 // returns dst = alpha * op * v
91 // alpha must be 1 here
92 assert(alpha == Scalar(1) && "scaling is not implemented");
93 EIGEN_ONLY_USED_FOR_DEBUG(alpha);
94 dst = op.matmul(m);
95 }
96};
97} // namespace internal
98} // namespace Eigen
99
100#endif // VOTCA_XTP_MATRIXFREEOPERATOR_H
Eigen::Product< MatrixFreeOperator, Vtype, Eigen::AliasFreeProduct > operator*(const Eigen::MatrixBase< Vtype > &x) const
virtual Eigen::MatrixXd matmul(const Eigen::MatrixXd &input) const =0
virtual Eigen::VectorXd diagonal() const =0
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
static void scaleAndAddTo(Dest &dst, const votca::xtp::MatrixFreeOperator &op, const Mtype &m, const Scalar &alpha)