votca 2026-dev
Loading...
Searching...
No Matches
symmetric_tiles.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2026 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20#pragma once
21#ifndef VOTCA_XTP_SYMMETRIC_TILES_H
22#define VOTCA_XTP_SYMMETRIC_TILES_H
23
24// Standard includes
25#include <algorithm>
26#include <memory>
27#include <vector>
28
29// Local VOTCA includes
30#include "eigen.h"
31
32namespace votca {
33namespace xtp {
34
49 public:
50 static constexpr Index DefaultTile = 1024;
51
52 SymmetricTiles() = default;
53
55 static double Bytes(Index n, Index tile = DefaultTile);
56
59 void Allocate(Index n, Index kind, Index tile = DefaultTile);
60 void Release();
61
62 bool allocated() const { return data_ != nullptr; }
63 bool built() const { return built_; }
64 Index size() const { return n_; }
65 Index kind() const { return kind_; }
66
68 void SetRowLower(Index r, const double* values);
70 void FinishBuild();
71
73 Eigen::MatrixXd Multiply(const Eigen::MatrixXd& X, double factor = 1.0) const;
74
76 double operator()(Index i, Index j) const;
77
78 private:
79 using RowMajorMap = Eigen::Map<
80 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>;
82 Eigen::Map<const Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic,
83 Eigen::RowMajor>>;
84
85 Index TileStart(Index I) const { return I * tile_; }
86 Index TileSize(Index I) const { return std::min(tile_, n_ - TileStart(I)); }
87 double* TileData(Index I, Index J) const {
88 return data_.get() + offset_[std::size_t(I * (I + 1) / 2 + J)];
89 }
90
91 Index n_ = 0;
95 bool built_ = false;
96 std::vector<std::size_t> offset_;
97 std::unique_ptr<double[]> data_;
98};
99
100} // namespace xtp
101} // namespace votca
102
103#endif // VOTCA_XTP_SYMMETRIC_TILES_H
std::vector< std::size_t > offset_
static constexpr Index DefaultTile
void Allocate(Index n, Index kind, Index tile=DefaultTile)
Eigen::Map< const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > > ConstRowMajorMap
Eigen::Map< Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > > RowMajorMap
double operator()(Index i, Index j) const
Element (i, j), for tests.
std::unique_ptr< double[]> data_
void FinishBuild()
Fills the upper halves of the diagonal tiles; marks the matrix built.
double * TileData(Index I, Index J) const
static double Bytes(Index n, Index tile=DefaultTile)
Bytes the tiles of an n x n matrix need.
Eigen::MatrixXd Multiply(const Eigen::MatrixXd &X, double factor=1.0) const
factor * S * X
void SetRowLower(Index r, const double *values)
Row r, columns 0..r (values[0..r]); rows may be set in parallel.
Index TileStart(Index I) const
Index TileSize(Index I) const
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26