File indexing completed on 2026-08-06 09:25:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef NINJA_S_MAT_H
0015 #define NINJA_S_MAT_H
0016
0017 #include <ninja/types.hh>
0018
0019 namespace ninja {
0020
0021 class SMatrix {
0022 public:
0023
0024
0025 SMatrix() : data_(0), n_rows_(0), owns_data_(false) {}
0026
0027
0028
0029
0030
0031 explicit SMatrix(int n)
0032 : data_(new Real[n*n]), n_rows_(n), owns_data_(true) {}
0033
0034
0035 SMatrix(int n, Real * data_ptr)
0036 : data_(data_ptr), n_rows_(data_ptr ? n : 0), owns_data_(false) {}
0037
0038
0039 SMatrix(const SMatrix & s_mat)
0040 : data_(s_mat.data_), n_rows_(s_mat.n_rows_), owns_data_(false) {}
0041
0042
0043
0044
0045
0046
0047
0048
0049 ~SMatrix()
0050 {
0051 if (owns_data_)
0052 delete [] data_;
0053 }
0054
0055
0056 SMatrix & operator= (const SMatrix & s_mat)
0057 {
0058 if (owns_data_)
0059 delete [] data_;
0060 data_ = s_mat.data_;
0061 n_rows_ = data_ ? s_mat.n_rows_ : 0;
0062 owns_data_ = false;
0063 return *this;
0064 }
0065
0066
0067
0068 SMatrix & allocate(int n)
0069 {
0070 if (owns_data_)
0071 delete [] data_;
0072 n_rows_ = n;
0073 data_ = new Real[n*n];
0074 owns_data_ = true;
0075 return *this;
0076 }
0077
0078
0079 void clear()
0080 {
0081 if (owns_data_)
0082 delete [] data_;
0083 data_ = 0;
0084 owns_data_ = false;
0085 }
0086
0087
0088 void copy(const SMatrix & s_mat) {
0089 if (s_mat.data_) {
0090 allocate(s_mat.n_rows_);
0091 for (int i=0; i<n_rows_*n_rows_; ++i)
0092 data_[i] = s_mat.data_[i];
0093 } else {
0094 clear();
0095 }
0096 }
0097
0098
0099 Real * data()
0100 {
0101 return data_;
0102 }
0103
0104
0105 bool isNull()
0106 {
0107 return (! data_);
0108 }
0109
0110
0111 SMatrix & fill(Real value)
0112 {
0113 for (int i=0; i<n_rows_*n_rows_; ++i)
0114 data_[i] = value;
0115 return *this;
0116 }
0117
0118
0119
0120 SMatrix & fillFromKinematics(const RealMomentum pi[],
0121 Real ir_threshold = 0)
0122 {
0123 Real temp;
0124 for (int i=0; i<n_rows_; ++i) {
0125 (*this)(i,i) = Real();
0126 for (int j=i+1; j<n_rows_; ++j) {
0127 temp = mp2(pi[i]-pi[j]);
0128 (*this)(i,j) = (*this)(j,i) = abs(temp) < ir_threshold ? 0
0129 : temp;
0130 }
0131 }
0132 return *this;
0133 }
0134
0135
0136 Real operator() (unsigned i, unsigned j) const
0137 {
0138 return data_[i*n_rows_+j];
0139 }
0140 Real & operator() (unsigned i, unsigned j)
0141 {
0142 return data_[i*n_rows_+j];
0143 }
0144
0145 private:
0146
0147 Real * data_;
0148 int n_rows_;
0149 bool owns_data_;
0150
0151 };
0152
0153 }
0154
0155 #endif