GQCP
Loading...
Searching...
No Matches
miscellaneous.hpp
Go to the documentation of this file.
1// This file is part of GQCG-GQCP.
2//
3// Copyright (C) 2017-2020 the GQCG developers
4//
5// GQCG-GQCP is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// GQCG-GQCP is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with GQCG-GQCP. If not, see <http://www.gnu.org/licenses/>.
17
18#pragma once
19
20
21#include <algorithm>
22#include <cstdlib>
23#include <fstream>
24#include <functional>
25#include <iterator>
26#include <string>
27#include <vector>
28
29
30namespace GQCP {
31
32
43template <typename T>
44size_t findElementIndex(const std::vector<T>& vector, const T& value) {
45
46 const auto& it = std::find(vector.begin(), vector.end(), value); // 'it' for iterator
47
48 // Check if the value was found
49 if (it == vector.end()) {
50 throw std::out_of_range("findElementIndex(const std::vector<T>&, const T&): the given value was not found in the given vector");
51 }
52
53 return std::distance(vector.begin(), it); // the 'difference' between two iterators is an index
54}
55
56
68std::vector<std::vector<size_t>> generatePartitionsOf(const size_t n, const size_t k);
69
82std::vector<std::vector<size_t>> generateUniquePartitionsOf(const size_t n, const size_t k);
83
89size_t grayCodeOf(const size_t S);
90
98size_t matrixIndexMajor(const size_t v, const size_t cols, const size_t skipped = 0);
99
107size_t matrixIndexMinor(const size_t v, const size_t cols, const size_t skipped = 0);
108
115void printExecutionTime(const std::string& method_name, const std::function<void()>& function);
116
122size_t strictTriangularRootOf(const size_t x);
123
129size_t triangularRootOf(const size_t x);
130
135std::ifstream validateAndOpen(const std::string& filename, const std::string& extension);
136
145size_t vectorIndex(const size_t i, const size_t j, const size_t cols, size_t skipped = 0);
146
147
148} // namespace GQCP
Definition: BaseOneElectronIntegralBuffer.hpp:25
size_t findElementIndex(const std::vector< T > &vector, const T &value)
Definition: miscellaneous.hpp:44
size_t strictTriangularRootOf(const size_t x)
Definition: miscellaneous.cpp:226
size_t triangularRootOf(const size_t x)
Definition: miscellaneous.cpp:237
size_t matrixIndexMinor(const size_t v, const size_t cols, const size_t skipped=0)
Definition: miscellaneous.cpp:191
size_t matrixIndexMajor(const size_t v, const size_t cols, const size_t skipped=0)
Definition: miscellaneous.cpp:179
size_t grayCodeOf(const size_t S)
Definition: miscellaneous.cpp:165
void printExecutionTime(const std::string &method_name, const std::function< void()> &function)
Definition: miscellaneous.cpp:202
std::vector< std::vector< size_t > > generatePartitionsOf(const size_t n, const size_t k)
Definition: miscellaneous.cpp:41
std::vector< std::vector< size_t > > generateUniquePartitionsOf(const size_t n, const size_t k)
Definition: miscellaneous.cpp:121
size_t vectorIndex(const size_t i, const size_t j, const size_t cols, size_t skipped=0)
Definition: miscellaneous.cpp:257
@ x
Definition: CartesianDirection.hpp:28
std::ifstream validateAndOpen(const std::string &filename, const std::string &extension)
Definition: miscellaneous.cpp:266