Changeset 3bc926 for src/LinearAlgebra/gslmatrix.cpp
- Timestamp:
- Dec 4, 2010, 11:54:32 PM (14 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- cca9ef
- Parents:
- 9eb7580
- git-author:
- Frederik Heber <heber@…> (11/15/10 12:36:18)
- git-committer:
- Frederik Heber <heber@…> (12/04/10 23:54:32)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/LinearAlgebra/gslmatrix.cpp ¶
r9eb7580 r3bc926 27 27 28 28 #include <cassert> 29 #include <iostream> 29 30 #include <gsl/gsl_linalg.h> 31 #include <gsl/gsl_blas.h> 32 #include <gsl/gsl_eigen.h> 33 #include <gsl/gsl_matrix.h> 34 #include <gsl/gsl_vector.h> 30 35 31 36 /** Constructor of class GSLMatrix. … … 46 51 matrix = gsl_matrix_alloc(rows, columns); 47 52 gsl_matrix_memcpy (matrix, src->matrix); 53 }; 54 55 /** Copy constructor of class GSLMatrix. 56 * We take over pointer to gsl_matrix and set the parameter pointer to NULL 57 * afterwards. 58 * \param m row count 59 * \param n column count 60 * \param *&src source gsl_matrix 61 */ 62 GSLMatrix::GSLMatrix(size_t m, size_t n, gsl_matrix *&src) : 63 rows(m), 64 columns(n) 65 { 66 matrix = src; 67 src = NULL; 48 68 }; 49 69 … … 90 110 * \return (m,n)-th element of matrix 91 111 */ 92 double GSLMatrix::Get(size_t m, size_t n) 112 double GSLMatrix::Get(size_t m, size_t n) const 93 113 { 94 114 return gsl_matrix_get (matrix, m, n); … … 121 141 * \return const pointer to \a m-th element 122 142 */ 123 const double *GSLMatrix::const_Pointer(size_t m, size_t n) 143 const double *GSLMatrix::const_Pointer(size_t m, size_t n) const 124 144 { 125 145 return gsl_matrix_const_ptr (matrix, m, n); 126 146 }; 147 148 /** Returns the number of rows of the matrix. 149 * \return number of rows 150 */ 151 size_t GSLMatrix::getRowCount() const 152 { 153 return rows; 154 } 155 156 /** Returns the number of columns of the matrix. 157 * \return number of columns 158 */ 159 size_t GSLMatrix::getColumnCount() const 160 { 161 return columns; 162 } 127 163 128 164 /* ========================== Initializing =============================== */ … … 204 240 * \return true - is null, false - else 205 241 */ 206 bool GSLMatrix::IsNull() 242 bool GSLMatrix::IsNull() const 207 243 { 208 244 return gsl_matrix_isnull (matrix); … … 212 248 * \return true - is positive, false - else 213 249 */ 214 bool GSLMatrix::IsPositive() 250 bool GSLMatrix::IsPositive() const 215 251 { 216 252 return gsl_matrix_ispos (matrix); … … 220 256 * \return true - is negative, false - else 221 257 */ 222 bool GSLMatrix::IsNegative() 258 bool GSLMatrix::IsNegative() const 223 259 { 224 260 return gsl_matrix_isneg (matrix); … … 228 264 * \return true - is non-negative, false - else 229 265 */ 230 bool GSLMatrix::IsNonNegative() 266 bool GSLMatrix::IsNonNegative() const 231 267 { 232 268 return gsl_matrix_isnonneg (matrix); … … 237 273 * \return true - matrix is positive-definite, false - else 238 274 */ 239 bool GSLMatrix::IsPositiveDefinite() 275 bool GSLMatrix::IsPositiveDefinite() const 240 276 { 241 277 if (rows != columns) // only possible for square matrices. … … 249 285 * if matrix is square, uses LU decomposition. 250 286 */ 251 double GSLMatrix::Determinant() 287 double GSLMatrix::Determinant() const 252 288 { 253 289 int signum = 0; … … 259 295 }; 260 296 297 298 /* ============================ Properties ============================== */ 299 300 const GSLMatrix &GSLMatrix::operator+=(const GSLMatrix &rhs) 301 { 302 gsl_matrix_add(matrix, rhs.matrix); 303 return *this; 304 } 305 306 const GSLMatrix &GSLMatrix::operator-=(const GSLMatrix &rhs) 307 { 308 gsl_matrix_sub(matrix, rhs.matrix); 309 return *this; 310 } 311 312 const GSLMatrix &GSLMatrix::operator*=(const GSLMatrix &rhs) 313 { 314 (*this) = (*this)*rhs; 315 return *this; 316 } 317 318 const GSLMatrix GSLMatrix::operator+(const GSLMatrix &rhs) const 319 { 320 GSLMatrix tmp = *this; 321 tmp+=rhs; 322 return tmp; 323 } 324 325 const GSLMatrix GSLMatrix::operator-(const GSLMatrix &rhs) const 326 { 327 GSLMatrix tmp = *this; 328 tmp-=rhs; 329 return tmp; 330 } 331 332 const GSLMatrix GSLMatrix::operator*(const GSLMatrix &rhs) const 333 { 334 gsl_matrix *res = gsl_matrix_alloc(rhs.rows, rhs.columns); 335 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, matrix, rhs.matrix, 0.0, res); 336 return GSLMatrix(rhs.rows, rhs.columns, res); 337 } 338 339 /** Print matrix in a matlab style manner. 340 * \param &ost reference to output stream 341 * \param &mat reference to matrix to print 342 * \return reference to obtained output stream for concatenation 343 */ 344 ostream &operator<<(ostream &ost,const GSLMatrix &mat) 345 { 346 ost << "["; 347 for(size_t i = 0;i<mat.rows;++i){ 348 for(size_t j = 0; j<mat.columns;++j){ 349 ost << mat.Get(i,j); 350 if(j!=mat.columns-1) 351 ost << " "; 352 } 353 if(i!=mat.rows-1) 354 ost << "; "; 355 } 356 ost << "]"; 357 return ost; 358 } 359
Note:
See TracChangeset
for help on using the changeset viewer.