Psi4
dimension.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2017 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  * @END LICENSE
26  */
27 
28 #ifndef _psi_src_lib_libmints_dimension_h_
29 #define _psi_src_lib_libmints_dimension_h_
30 
31 #include <string>
32 #include <cstdio>
33 #include <vector>
34 
35 namespace psi {
36 
37 
38 
39 class Dimension
40 {
41  std::string name_;
42  std::vector<int> blocks_;
43 
44 public:
45  Dimension();
46  Dimension(const Dimension& other);
47  Dimension(int n, const std::string& name = "");
48  Dimension(const std::vector<int>& other);
49  ~Dimension();
50 
52  Dimension& operator=(const Dimension& other);
53 
55  Dimension& operator=(const int* other);
56 
57  Dimension& operator+=(const Dimension& b);
58  Dimension& operator-=(const Dimension& b);
59 
61  void init(int n, const std::string& name = "");
62 
64  int n() const { return static_cast<int>(blocks_.size()); }
65 
67  const std::string& name() const { return name_; }
68 
70  void set_name(const std::string& name) { name_ = name; }
71 
73  int& operator[](int i) { return blocks_[i]; }
74  const int& operator[](int i) const { return blocks_[i]; }
75  const std::vector<int>& blocks() const { return blocks_; }
76 
78  operator int*() { return blocks_.data(); }
80  operator const int*() const { return blocks_.data(); }
81 
83  int sum() const;
84  int max() const;
85 
87  void zero();
88 
89  void print() const;
90 
91  // Only used for python
92  const int& get(int i) const { return blocks_[i]; }
93  void set(int i, int val) { blocks_[i] = val; }
94 
95  friend bool operator==(const Dimension& a, const Dimension& b);
96  friend bool operator!=(const Dimension& a, const Dimension& b);
97  friend Dimension operator+(const Dimension& a, const Dimension& b);
98  friend Dimension operator-(const Dimension& a, const Dimension& b);
99 };
100 
101 }
102 
103 #endif // _psi_src_lib_libmints_dimension_h_
int sum() const
Return the sum of constituent dimensions.
Definition: dimension.cc:65
friend Dimension operator+(const Dimension &a, const Dimension &b)
Definition: dimension.cc:150
void zero()
Zero all the elements.
Definition: dimension.cc:83
friend bool operator!=(const Dimension &a, const Dimension &b)
Definition: dimension.cc:146
std::vector< int > blocks_
Definition: dimension.h:42
Definition: pointgrp.h:105
int & operator[](int i)
Blocks access.
Definition: dimension.h:73
int n() const
Return the rank.
Definition: dimension.h:64
void set(int i, int val)
Definition: dimension.h:93
int max() const
Definition: dimension.cc:74
~Dimension()
Definition: dimension.cc:55
const int & operator[](int i) const
Definition: dimension.h:74
void init(int n, const std::string &name="")
Re-initializes the object.
Definition: dimension.cc:59
void print() const
Definition: dimension.cc:90
std::string name_
Definition: dimension.h:41
const std::string & name() const
Return the name of the dimension.
Definition: dimension.h:67
Definition: dimension.h:39
Dimension & operator+=(const Dimension &b)
Definition: dimension.cc:114
friend Dimension operator-(const Dimension &a, const Dimension &b)
Definition: dimension.cc:164
Dimension & operator-=(const Dimension &b)
Definition: dimension.cc:128
Dimension & operator=(const Dimension &other)
Assignment operator.
Definition: dimension.cc:99
Dimension()
Definition: dimension.cc:35
const std::vector< int > & blocks() const
Definition: dimension.h:75
friend bool operator==(const Dimension &a, const Dimension &b)
Definition: dimension.cc:142
void set_name(const std::string &name)
Set the name of the dimension.
Definition: dimension.h:70