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 file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 #ifndef _psi_src_lib_libmints_dimension_h_
30 #define _psi_src_lib_libmints_dimension_h_
31 
32 #include <string>
33 #include <cstdio>
34 #include <vector>
35 
36 namespace psi {
37 
38 
39 
40 class Dimension
41 {
42  std::string name_;
43  std::vector<int> blocks_;
44 
45 public:
46  Dimension();
47  Dimension(const Dimension& other);
48  Dimension(int n, const std::string& name = "");
49  Dimension(const std::vector<int>& other);
50  ~Dimension();
51 
53  Dimension& operator=(const Dimension& other);
54 
56  Dimension& operator=(const int* other);
57 
58  Dimension& operator+=(const Dimension& b);
59  Dimension& operator-=(const Dimension& b);
60 
62  void init(int n, const std::string& name = "");
63 
65  int n() const { return static_cast<int>(blocks_.size()); }
66 
68  const std::string& name() const { return name_; }
69 
71  void set_name(const std::string& name) { name_ = name; }
72 
74  int& operator[](int i) { return blocks_[i]; }
75  const int& operator[](int i) const { return blocks_[i]; }
76  const std::vector<int>& blocks() const { return blocks_; }
77 
79  operator int*() { return blocks_.data(); }
81  operator const int*() const { return blocks_.data(); }
82 
84  int sum() const;
85  int max() const;
86 
88  void zero();
89 
90  void print() const;
91 
92  // Only used for python
93  const int& get(int i) const { return blocks_[i]; }
94  void set(int i, int val) { blocks_[i] = val; }
95 
96  friend bool operator==(const Dimension& a, const Dimension& b);
97  friend bool operator!=(const Dimension& a, const Dimension& b);
98  friend Dimension operator+(const Dimension& a, const Dimension& b);
99  friend Dimension operator-(const Dimension& a, const Dimension& b);
100 };
101 
102 }
103 
104 #endif // _psi_src_lib_libmints_dimension_h_
int sum() const
Return the sum of constituent dimensions.
Definition: dimension.cc:66
friend Dimension operator+(const Dimension &a, const Dimension &b)
Definition: dimension.cc:151
void zero()
Zero all the elements.
Definition: dimension.cc:84
friend bool operator!=(const Dimension &a, const Dimension &b)
Definition: dimension.cc:147
std::vector< int > blocks_
Definition: dimension.h:43
Definition: pointgrp.h:106
int & operator[](int i)
Blocks access.
Definition: dimension.h:74
int n() const
Return the rank.
Definition: dimension.h:65
void set(int i, int val)
Definition: dimension.h:94
int max() const
Definition: dimension.cc:75
~Dimension()
Definition: dimension.cc:56
const int & operator[](int i) const
Definition: dimension.h:75
void init(int n, const std::string &name="")
Re-initializes the object.
Definition: dimension.cc:60
void print() const
Definition: dimension.cc:91
std::string name_
Definition: dimension.h:42
const std::string & name() const
Return the name of the dimension.
Definition: dimension.h:68
Definition: dimension.h:40
Dimension & operator+=(const Dimension &b)
Definition: dimension.cc:115
friend Dimension operator-(const Dimension &a, const Dimension &b)
Definition: dimension.cc:165
Dimension & operator-=(const Dimension &b)
Definition: dimension.cc:129
Dimension & operator=(const Dimension &other)
Assignment operator.
Definition: dimension.cc:100
Dimension()
Definition: dimension.cc:36
const std::vector< int > & blocks() const
Definition: dimension.h:76
friend bool operator==(const Dimension &a, const Dimension &b)
Definition: dimension.cc:143
void set_name(const std::string &name)
Set the name of the dimension.
Definition: dimension.h:71