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-2018 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 #include "psi4/pragma.h"
37 
38 namespace psi {
39 
41  private:
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 
91  void fill(int v);
92 
93  void print() const;
94 
95  // Only used for python
96  const int& get(int i) const { return blocks_[i]; }
97  void set(int i, int val) { blocks_[i] = val; }
98 
99  PSI_API friend bool operator==(const Dimension& a, const Dimension& b);
100  PSI_API friend bool operator!=(const Dimension& a, const Dimension& b);
101  PSI_API friend Dimension operator+(const Dimension& a, const Dimension& b);
102  PSI_API friend Dimension operator-(const Dimension& a, const Dimension& b);
103 };
104 
125 class PSI_API Slice {
128 
129  public:
133  Slice(const Dimension& begin, const Dimension& end);
135  Slice(const Slice& other);
136 
138  const Dimension& begin() const { return begin_; }
140  const Dimension& end() const { return end_; }
142  Slice& operator+=(const Dimension& increment);
143 
144  private:
146  bool validate_slice();
147 };
148 } // namespace psi
149 
150 #endif // _psi_src_lib_libmints_dimension_h_
PSI_API Dimension operator-(const Dimension &a, const Dimension &b)
Definition: dimension.cc:125
std::vector< int > blocks_
Definition: dimension.h:43
Definition: pointgrp.h:104
#define max(a, b)
Definition: svd.cc:38
const Dimension & end() const
Get the past-the-end element of this slice.
Definition: dimension.h:140
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:97
Slicing for Matrices and Vectors objects.
Definition: dimension.h:125
const int & operator[](int i) const
Definition: dimension.h:75
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
bool operator==(const string &c, const DPDMOSpace &rhs)
Definition: dpdmospace.cc:77
Dimension begin_
Definition: dimension.h:126
#define PSI_API
Definition: pragma.h:155
PSI_API Dimension operator+(const Dimension &a, const Dimension &b)
Definition: dimension.cc:112
const std::vector< int > & blocks() const
Definition: dimension.h:76
Dimension end_
Definition: dimension.h:127
const Dimension & begin() const
Get the first element of this slice.
Definition: dimension.h:138
void set_name(const std::string &name)
Set the name of the dimension.
Definition: dimension.h:71
PSI_API bool operator!=(const Dimension &a, const Dimension &b)
Definition: dimension.cc:110