LIBINT 2.9.0
vectorn.h
1/*
2 * Copyright (C) 2004-2024 Edward F. Valeev
3 *
4 * This file is part of Libint compiler.
5 *
6 * Libint compiler is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Libint compiler is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Libint compiler. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_src_bin_libint_boostutil_h_
22#define _libint2_src_bin_libint_boostutil_h_
23
24#include <boost/tuple/tuple.hpp>
25
26namespace libint2 {
27
29template <typename T, int N>
30class VectorN {
31 public:
34 for (int i = 0; i < N; ++i) data_[i] = T();
35 }
36 VectorN(const VectorN& a) {
37 for (int i = 0; i < N; ++i) data_[i] = a.data_[i];
38 }
39
40 VectorN& operator+=(const VectorN& a) {
41 for (int i = 0; i < N; ++i) data_[i] += a.data_[i];
42 return *this;
43 }
44 VectorN& operator-=(const VectorN& a) {
45 for (int i = 0; i < N; ++i) data_[i] -= a.data_[i];
46 return *this;
47 }
48
50 T norm1() const {
51 T result(0);
52 for (int i = 0; i < N; ++i) result += abs(data_[i]);
53 return result;
54 }
55
56 T& operator[](int i) {
57 assert(i >= 0 && i < N);
58 return data_[i];
59 }
60 const T& operator[](int i) const {
61 assert(i >= 0 && i < N);
62 return data_[i];
63 }
64
65 private:
66 T data_[N];
67};
68
69template <typename T, int N>
70VectorN<T, N> operator+(const VectorN<T, N>& a, const VectorN<T, N>& b) {
71 VectorN<T, N> result(a);
72 result += b;
73 return result;
74}
75template <typename T, int N>
76VectorN<T, N> operator-(const VectorN<T, N>& a, const VectorN<T, N>& b) {
77 VectorN<T, N> result(a);
78 result -= b;
79 return result;
80}
81
82template <typename T, int N>
83inline VectorN<T, N> unit_vector(int i) {
84 assert(i >= 0 && i < N);
85 VectorN<T, N> result;
86 result[i] += 1;
87 return result;
88}
89
90// useful typedefs
91typedef VectorN<int, 3> IntVec3;
92inline IntVec3 unit_intvec3(int i) { return unit_vector<int, 3>(i); }
94inline bool ltzero(const IntVec3& a) {
95 for (int xyz = 0; xyz < 3; ++xyz)
96 if (a[xyz] < 0) return true;
97 return false;
98}
99
100} // namespace libint2
101
102#endif /* header guard */
vector of N elements of type T
Definition vectorn.h:30
VectorN()
Default is vector of zeroes.
Definition vectorn.h:33
T norm1() const
1-norm
Definition vectorn.h:50
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24
bool ltzero(const IntVec3 &a)
return true if has elements < 0
Definition vectorn.h:94