File indexing completed on 2025-03-23 11:26:01
0001 /*************************************************************************** 0002 * Copyright (C) 2006 by Alan Grimes * 0003 * agrimes@speakeasy.net * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 0021 // #ifndef QVECTOR_H 0022 #include "qvector.h" 0023 // #endif 0024 0025 #include <QDebug> 0026 #include <cassert> 0027 #include <cmath> 0028 #include <cstdlib> // for null 0029 #include <iostream> 0030 0031 using namespace std; 0032 0033 /* 0034 #ifndef BADRNG_H 0035 #include "badrng.h" 0036 #endif 0037 */ 0038 0039 // ###################################### 0040 0041 double QuickVector::at(CUI m_a) const 0042 { 0043 // if(!m_a || m_a > m) return NAN; 0044 0045 return values[m_a]; 0046 } 0047 0048 // ##################################### 0049 0050 bool QuickVector::atPut(CUI m_a, const double val) 0051 { 0052 if (m_a >= m) 0053 return false; 0054 0055 values[m_a] = val; 0056 changed = true; 0057 return true; 0058 } 0059 0060 // ##################################### 0061 0062 bool QuickVector::atAdd(CUI m_a, const double val) 0063 { 0064 if (m_a >= m) 0065 return false; 0066 0067 values[m_a] += val; 0068 changed = true; 0069 return true; 0070 } 0071 0072 // ##################################### 0073 0074 QuickVector::QuickVector(CUI m_in) 0075 : m(m_in) 0076 , changed(true) 0077 { 0078 assert(m); 0079 values = new double[m]; 0080 memset(values, 0, sizeof(double) * m); 0081 } 0082 0083 // ##################################### 0084 0085 QuickVector::QuickVector(const QuickVector *old) 0086 : m(old->m) 0087 , changed(old->changed) 0088 { 0089 assert(m); 0090 values = new double[m]; 0091 0092 for (unsigned int j = 0; j < m; j++) 0093 values[j] = old->values[j]; 0094 } 0095 0096 // ##################################### 0097 0098 QuickVector::~QuickVector() 0099 { 0100 delete[] values; 0101 } 0102 0103 // ##################################### 0104 0105 /* 0106 void QuickVector::fillWithRandom() { 0107 for(unsigned int j = 0; j < m; j++) 0108 values[j] = drng(); 0109 } 0110 */ 0111 0112 // ##################################### 0113 0114 void QuickVector::fillWithZeros() 0115 { 0116 memset(values, 0, m * sizeof(double)); 0117 changed = true; 0118 } 0119 0120 // ##################################### 0121 0122 QuickVector &QuickVector::operator-(const QuickVector &y) const 0123 { 0124 // if(y.m != m) abort(); 0125 0126 QuickVector *ret; 0127 ret = new QuickVector(m); 0128 0129 for (unsigned int i = 0; i < m; i++) 0130 ret->values[i] = values[i] - y.values[i]; 0131 0132 return *ret; 0133 } 0134 0135 // #################################### 0136 0137 void QuickVector::dumpToAux() const 0138 { 0139 for (unsigned int i = 0; i < m; i++) 0140 cout << values[i] << ' '; 0141 cout << endl; 0142 } 0143 0144 // #################################### 0145 0146 bool QuickVector::swapElements(CUI m_a, CUI m_b) 0147 { 0148 if (m_a >= m || m_b >= m) 0149 return false; 0150 0151 double temp = values[m_a]; 0152 values[m_a] = values[m_b]; 0153 values[m_b] = temp; 0154 changed = true; 0155 0156 return true; 0157 } 0158 0159 // ################################### 0160 0161 QuickVector &QuickVector::operator=(const QuickVector &y) 0162 { 0163 assert(y.m == m); 0164 0165 for (unsigned int i = 0; i < m; i++) 0166 values[i] = y.values[i]; 0167 changed = true; 0168 return *this; 0169 } 0170 0171 // ################################### 0172 0173 QuickVector &QuickVector::operator*=(const QuickVector &y) 0174 { 0175 // if(y.m != m) return nullptr; 0176 0177 for (unsigned int i = 0; i < m; i++) 0178 values[i] *= y.values[i]; 0179 changed = true; 0180 return *this; 0181 } 0182 0183 // ################################### 0184 0185 QuickVector &QuickVector::operator+=(const QuickVector &y) 0186 { 0187 // if(y.m != m) return nullptr; 0188 0189 for (unsigned int i = 0; i < m; i++) 0190 values[i] += y.values[i]; 0191 changed = true; 0192 return *this; 0193 } 0194 0195 // ###################################