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 class Dimension
39 {
40  std::string name_;
41  std::vector<int> blocks_;
42 
43 public:
44  Dimension();
45  Dimension(const Dimension& other);
46  Dimension(int n, const std::string& name = "");
47  Dimension(const std::vector<int>& other);
48  ~Dimension();
49 
51  Dimension& operator=(const Dimension& other);
52 
54  Dimension& operator=(const int* other);
55 
56  Dimension& operator+=(const Dimension& b);
57  Dimension& operator-=(const Dimension& b);
58 
60  void init(int n, const std::string& name = "");
61 
63  int n() const { return static_cast<int>(blocks_.size()); }
64 
66  const std::string& name() const { return name_; }
67 
69  void set_name(const std::string& name) { name_ = name; }
70 
72  int& operator[](int i) { return blocks_[i]; }
73  const int& operator[](int i) const { return blocks_[i]; }
74  const std::vector<int>& blocks() const { return blocks_; }
75 
77  operator int*() { return blocks_.data(); }
79  operator const int*() const { return blocks_.data(); }
80 
82  int sum() const;
83  int max() const;
84 
86  void zero();
87 
88  void print() const;
89 
90  // Only used for python
91  const int& get(int i) const { return blocks_[i]; }
92  void set(int i, int val) { blocks_[i] = val; }
93 
94  friend bool operator==(const Dimension& a, const Dimension& b);
95  friend bool operator!=(const Dimension& a, const Dimension& b);
96  friend Dimension operator+(const Dimension& a, const Dimension& b);
97  friend Dimension operator-(const Dimension& a, const Dimension& b);
98 };
99 
120 class Slice
121 {
124 
125 public:
129  Slice(const Dimension& begin,const Dimension& end);
131  Slice(const Slice& other);
132 
134  const Dimension& begin() const {return begin_;}
136  const Dimension& end() const {return end_;}
138  Slice& operator+=(const Dimension& increment);
139 
140 private:
142  bool validate_slice();
143 };
144 
145 }
146 
147 #endif // _psi_src_lib_libmints_dimension_h_
int sum() const
Return the sum of constituent dimensions.
Definition: dimension.cc:69
friend Dimension operator+(const Dimension &a, const Dimension &b)
Definition: dimension.cc:154
void zero()
Zero all the elements.
Definition: dimension.cc:87
friend bool operator!=(const Dimension &a, const Dimension &b)
Definition: dimension.cc:150
std::vector< int > blocks_
Definition: dimension.h:41
Definition: pointgrp.h:106
const Dimension & end() const
Get the past-the-end element of this slice.
Definition: dimension.h:136
Slice & operator+=(const Dimension &increment)
Increment the beginning and end of this slice.
Definition: dimension.cc:193
int & operator[](int i)
Blocks access.
Definition: dimension.h:72
int n() const
Return the rank.
Definition: dimension.h:63
void set(int i, int val)
Definition: dimension.h:92
Slicing for Matrices and Vectors objects.
Definition: dimension.h:120
int max() const
Definition: dimension.cc:78
~Dimension()
Definition: dimension.cc:59
const int & operator[](int i) const
Definition: dimension.h:73
void init(int n, const std::string &name="")
Re-initializes the object.
Definition: dimension.cc:63
void print() const
Definition: dimension.cc:94
std::string name_
Definition: dimension.h:40
const std::string & name() const
Return the name of the dimension.
Definition: dimension.h:66
Definition: dimension.h:38
Dimension & operator+=(const Dimension &b)
Definition: dimension.cc:118
friend Dimension operator-(const Dimension &a, const Dimension &b)
Definition: dimension.cc:168
Dimension begin_
Definition: dimension.h:122
Dimension & operator-=(const Dimension &b)
Definition: dimension.cc:132
Dimension & operator=(const Dimension &other)
Assignment operator.
Definition: dimension.cc:103
Slice(const Dimension &begin, const Dimension &end)
Definition: dimension.cc:181
Dimension()
Definition: dimension.cc:39
bool validate_slice()
Check if this Slice is acceptable.
Definition: dimension.cc:201
const std::vector< int > & blocks() const
Definition: dimension.h:74
Dimension end_
Definition: dimension.h:123
const Dimension & begin() const
Get the first element of this slice.
Definition: dimension.h:134
friend bool operator==(const Dimension &a, const Dimension &b)
Definition: dimension.cc:146
void set_name(const std::string &name)
Set the name of the dimension.
Definition: dimension.h:69