PEXSI
 All Classes Namespaces Files Functions Variables Typedefs Pages
NumMat.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012 The Regents of the University of California,
3  through Lawrence Berkeley National Laboratory.
4 
5 Authors: Lexing Ying, Mathias Jacquelin and Lin Lin
6 
7 This file is part of PEXSI. All rights reserved.
8 
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11 
12 (1) Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
14 (2) Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 (3) Neither the name of the University of California, Lawrence Berkeley
18 National Laboratory, U.S. Dept. of Energy nor the names of its contributors may
19 be used to endorse or promote products derived from this software without
20 specific prior written permission.
21 
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
26 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 You are under no obligation whatsoever to provide any bug fixes, patches, or
34 upgrades to the features, functionality or performance of the source code
35 ("Enhancements") to anyone; however, if you choose to make your Enhancements
36 available either publicly, or directly to Lawrence Berkeley National
37 Laboratory, without imposing a separate written license agreement for such
38 Enhancements, then you hereby grant the following license: a non-exclusive,
39 royalty-free perpetual license to install, use, modify, prepare derivative
40 works, incorporate into other computer software, distribute, and sublicense
41 such enhancements or derivative works thereof, in binary and source code form.
42  */
46 #ifndef _PEXSI_NUMMAT_HPP_
47 #define _PEXSI_NUMMAT_HPP_
48 
49 #include "pexsi/environment.hpp"
50 
51 
52 namespace PEXSI{
60  template <class F>
61  class NumMat
62  {
63  public:
65  bool owndata_;
66 
68  Int m_;
69 
71  Int n_;
72 
74  F* data_;
75 
77  Int bufsize_;
78 
80  void allocate(F* data=NULL);
81 
83  void deallocate();
84 
85  public:
86  NumMat(Int m=0, Int n=0);
87  NumMat(Int m, Int n, bool owndata, F* data);
88  NumMat(const NumMat& C);
89  ~NumMat();
90  NumMat& Copy(const NumMat& C);
91  NumMat& operator=(const NumMat& C);
92  void Resize(Int m, Int n);
93  void Clear();
94  const F& operator()(Int i, Int j) const;
95  F& operator()(Int i, Int j);
96  F* Data() const { return data_; }
97  F* VecData(Int j) const;
98  Int m() const { return m_; }
99  Int n() const { return n_; }
100  Int Size() const {return m_*n_;}
101  Int ByteSize() const { return m_*n_*sizeof(F);}
102  Int AllocatedSize() const {return bufsize_;}
103  };
104 
105  // Commonly used
106  typedef NumMat<bool> BolNumMat;
107  typedef NumMat<Int> IntNumMat;
108  typedef NumMat<Real> DblNumMat;
109  typedef NumMat<Complex> CpxNumMat;
110 
111  // *********************************************************************
112  // Utility functions
113  // *********************************************************************
115  template <class F> inline void SetValue(NumMat<F>& M, F val);
116 
118  template <class F> inline Real Energy(const NumMat<F>& M);
119 
120 } // namespace PEXSI
121 
122 
123 
124 #include "pexsi/NumMat_impl.hpp"
125 
126 #endif // _PEXSI_NUMMAT_HPP_
Environmental variables.
Int bufsize_
Actual size of the allocated buffer. Similar to the capacity of a std::vector.
Definition: NumMat.hpp:77
Real Energy(const NumMat< F > &M)
Energy computes the L2 norm of a matrix (treated as a vector).
Definition: NumMat_impl.hpp:176
F * data_
The pointer for the actual data.
Definition: NumMat.hpp:74
void deallocate()
Helper function freeing memory pointed by the data_ attribute.
Definition: NumMat_impl.hpp:66
void allocate(F *data=NULL)
Helper function allocating the memory pointed by the data_ attribute.
Definition: NumMat_impl.hpp:52
void SetValue(NumMat< F > &M, F val)
SetValue sets a numerical matrix to a constant val.
Definition: NumMat_impl.hpp:171
Implementation of numerical matrix.
bool owndata_
Whether it owns the data.
Definition: NumMat.hpp:65
Numerical matrix.
Definition: NumMat.hpp:61
Int m_
The size of the first dimension.
Definition: NumMat.hpp:68
Int n_
The size of second dimension.
Definition: NumMat.hpp:71