Ignore:
Timestamp:
Dec 4, 2010, 11:54:32 PM (14 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

Extended MatrixContent class.

  • MatrixContent formerly has been just a structure to contain the gsl_matrix due to forward declaration reasons.
  • now MatrixContent is a true wrapper to gsl_matrix, i.e. all functionality that is now specific to 3 dimensions has been shifted from Matrix over to MatrixContent.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/LinearAlgebra/gslmatrix.cpp

    r9eb7580 r3bc926  
    2727
    2828#include <cassert>
     29#include <iostream>
    2930#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>
    3035
    3136/** Constructor of class GSLMatrix.
     
    4651  matrix = gsl_matrix_alloc(rows, columns);
    4752  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 */
     62GSLMatrix::GSLMatrix(size_t m, size_t n, gsl_matrix *&src) :
     63    rows(m),
     64    columns(n)
     65{
     66  matrix = src;
     67  src = NULL;
    4868};
    4969
     
    90110 * \return (m,n)-th element of matrix
    91111 */
    92 double GSLMatrix::Get(size_t m, size_t n)
     112double GSLMatrix::Get(size_t m, size_t n) const
    93113{
    94114  return gsl_matrix_get (matrix, m, n);
     
    121141 * \return const pointer to \a m-th element
    122142 */
    123 const double *GSLMatrix::const_Pointer(size_t m, size_t n)
     143const double *GSLMatrix::const_Pointer(size_t m, size_t n) const
    124144{
    125145  return gsl_matrix_const_ptr (matrix, m, n);
    126146};
     147
     148/** Returns the number of rows of the matrix.
     149 * \return number of rows
     150 */
     151size_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 */
     159size_t GSLMatrix::getColumnCount() const
     160{
     161  return columns;
     162}
    127163
    128164/* ========================== Initializing =============================== */
     
    204240 * \return true - is null, false - else
    205241 */
    206 bool GSLMatrix::IsNull()
     242bool GSLMatrix::IsNull() const
    207243{
    208244  return gsl_matrix_isnull (matrix);
     
    212248 * \return true - is positive, false - else
    213249 */
    214 bool GSLMatrix::IsPositive()
     250bool GSLMatrix::IsPositive() const
    215251{
    216252  return gsl_matrix_ispos (matrix);
     
    220256 * \return true - is negative, false - else
    221257 */
    222 bool GSLMatrix::IsNegative()
     258bool GSLMatrix::IsNegative() const
    223259{
    224260  return gsl_matrix_isneg (matrix);
     
    228264 * \return true - is non-negative, false - else
    229265 */
    230 bool GSLMatrix::IsNonNegative()
     266bool GSLMatrix::IsNonNegative() const
    231267{
    232268  return gsl_matrix_isnonneg (matrix);
     
    237273 * \return true - matrix is positive-definite, false - else
    238274 */
    239 bool GSLMatrix::IsPositiveDefinite()
     275bool GSLMatrix::IsPositiveDefinite() const
    240276{
    241277  if (rows != columns)  // only possible for square matrices.
     
    249285 * if matrix is square, uses LU decomposition.
    250286 */
    251 double GSLMatrix::Determinant()
     287double GSLMatrix::Determinant() const
    252288{
    253289  int signum = 0;
     
    259295};
    260296
     297
     298/* ============================ Properties ============================== */
     299
     300const GSLMatrix &GSLMatrix::operator+=(const GSLMatrix &rhs)
     301{
     302  gsl_matrix_add(matrix, rhs.matrix);
     303  return *this;
     304}
     305
     306const GSLMatrix &GSLMatrix::operator-=(const GSLMatrix &rhs)
     307{
     308  gsl_matrix_sub(matrix, rhs.matrix);
     309  return *this;
     310}
     311
     312const GSLMatrix &GSLMatrix::operator*=(const GSLMatrix &rhs)
     313{
     314  (*this) = (*this)*rhs;
     315  return *this;
     316}
     317
     318const GSLMatrix GSLMatrix::operator+(const GSLMatrix &rhs) const
     319{
     320  GSLMatrix tmp = *this;
     321  tmp+=rhs;
     322  return tmp;
     323}
     324
     325const GSLMatrix GSLMatrix::operator-(const GSLMatrix &rhs) const
     326{
     327  GSLMatrix tmp = *this;
     328  tmp-=rhs;
     329  return tmp;
     330}
     331
     332const 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 */
     344ostream &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.