votca 2026-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#include <cassert>
23
24// Local VOTCA includes
25#include "eigen.h"
26
27namespace votca {
28namespace xtp {
29
30class MatrixFreeOperator;
31}
32} // namespace votca
33namespace Eigen {
34namespace internal {
35// MatrixReplacement looks-like a Matrix, so let's inherits its traits:
36template <>
37struct traits<votca::xtp::MatrixFreeOperator>
38 : public Eigen::internal::traits<Eigen::MatrixXd> {};
39} // namespace internal
40} // namespace Eigen
41
42namespace votca {
43namespace xtp {
44
45class MatrixFreeOperator : public Eigen::EigenBase<MatrixFreeOperator> {
46 public:
47 enum {
48 ColsAtCompileTime = Eigen::Dynamic,
49 MaxColsAtCompileTime = Eigen::Dynamic,
50 IsRowMajor = false
51 };
52
53 Index rows() const { return this->size_; }
54 Index cols() const { return this->size_; }
55
56 template <typename Vtype>
57 Eigen::Product<MatrixFreeOperator, Vtype, Eigen::AliasFreeProduct> operator*(
58 const Eigen::MatrixBase<Vtype>& x) const {
59 return Eigen::Product<MatrixFreeOperator, Vtype, Eigen::AliasFreeProduct>(
60 *this, x.derived());
61 }
62
63 virtual Eigen::VectorXd diagonal() const = 0;
64 virtual Eigen::MatrixXd matmul(const Eigen::MatrixXd& input) const = 0;
65 Index size() const;
66 void set_size(Index size);
67
68 private:
70};
71} // namespace xtp
72} // namespace votca
73
74namespace Eigen {
75
76namespace internal {
77
78// replacement of the mat*mat operation
79template <typename Mtype>
80struct generic_product_impl<votca::xtp::MatrixFreeOperator, Mtype, DenseShape,
81 DenseShape, GemmProduct>
82 : generic_product_impl_base<
83 votca::xtp::MatrixFreeOperator, Mtype,
84 generic_product_impl<votca::xtp::MatrixFreeOperator, Mtype>> {
85
86 typedef
87 typename Product<votca::xtp::MatrixFreeOperator, Mtype>::Scalar Scalar;
88
89 template <typename Dest>
90 static void scaleAndAddTo(Dest& dst, const votca::xtp::MatrixFreeOperator& op,
91 const Mtype& m, const Scalar& alpha) {
92 // returns dst = alpha * op * v
93 // alpha must be 1 here
94 assert(alpha == Scalar(1) && "scaling is not implemented");
95 EIGEN_ONLY_USED_FOR_DEBUG(alpha);
96 dst = op.matmul(m);
97 }
98};
99} // namespace internal
100} // namespace Eigen
101
102#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
Provides a means for comparing floating point numbers.
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)