LIBINT 2.7.2
vectorn.h
1/*
2 * Copyright (C) 2004-2021 Edward F. Valeev
3 *
4 * This file is part of Libint.
5 *
6 * Libint 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 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. 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
29 template <typename T, int N>
30 class VectorN {
31 public:
33 VectorN() { for(int i=0; i<N; ++i) data_[i] = T(); }
34 VectorN(const VectorN& a) { for(int i=0; i<N; ++i) data_[i] = a.data_[i]; }
35
36 VectorN& operator+=(const VectorN& a) {
37 for(int i=0; i<N; ++i)
38 data_[i] += a.data_[i];
39 return *this;
40 }
41 VectorN& operator-=(const VectorN& a) {
42 for(int i=0; i<N; ++i)
43 data_[i] -= a.data_[i];
44 return *this;
45 }
46
48 T norm1() const { T result(0); for(int i=0; i<N; ++i) result += abs(data_[i]); return result; }
49
50 T& operator[](int i) {
51 assert(i>=0 && i<N);
52 return data_[i];
53 }
54 const T& operator[](int i) const {
55 assert(i>=0 && i<N);
56 return data_[i];
57 }
58 private:
59 T data_[N];
60 };
61
62 template<typename T, int N>
63 VectorN<T,N> operator+(const VectorN<T,N>& a,
64 const VectorN<T,N>& b) {
65 VectorN<T,N> result(a);
66 result += b;
67 return result;
68 }
69 template<typename T, int N>
70 VectorN<T,N> operator-(const VectorN<T,N>& a,
71 const VectorN<T,N>& b) {
72 VectorN<T,N> result(a);
73 result -= b;
74 return result;
75 }
76
77 template <typename T, int N>
78 inline VectorN<T,N> unit_vector(int i) {
79 assert(i >= 0 && i < N);
80 VectorN<T,N> result;
81 result[i] += 1;
82 return result;
83 }
84
85 // useful typedefs
86 typedef VectorN<int,3> IntVec3;
87 inline IntVec3 unit_intvec3(int i) {
88 return unit_vector<int,3>(i);
89 }
91 inline bool ltzero(const IntVec3& a) {
92 for(int xyz=0; xyz<3; ++xyz)
93 if (a[xyz] < 0)
94 return true;
95 return false;
96 }
97
98}
99
100#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:48
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:91