Changeset 0d4424 for src


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:
c134d9
Parents:
cca9ef
git-author:
Frederik Heber <heber@…> (11/15/10 14:02:38)
git-committer:
Frederik Heber <heber@…> (12/04/10 23:54:32)
Message:

Made gslmatrix obsolete.

Location:
src
Files:
6 edited
4 moved

Legend:

Unmodified
Added
Removed
  • src/LinearAlgebra/Line.cpp

    rcca9ef r0d4424  
    2828#include "Helpers/Log.hpp"
    2929#include "Helpers/Verbose.hpp"
    30 #include "LinearAlgebra/gslmatrix.hpp"
     30#include "LinearAlgebra/MatrixContent.hpp"
    3131#include "Helpers/Info.hpp"
    3232#include "Exceptions/LinearDependenceException.hpp"
     
    116116  Vector res;
    117117
    118   auto_ptr<GSLMatrix> M = auto_ptr<GSLMatrix>(new GSLMatrix(4,4));
    119 
    120   M->SetAll(1.);
     118  auto_ptr<MatrixContent> M = auto_ptr<MatrixContent>(new MatrixContent(4,4));
     119
     120  M->setValue(1.);
    121121  for (int i=0;i<3;i++) {
    122     M->Set(0, i, Line1a[i]);
    123     M->Set(1, i, Line1b[i]);
    124     M->Set(2, i, Line2a[i]);
    125     M->Set(3, i, Line2b[i]);
     122    M->set(0, i, Line1a[i]);
     123    M->set(1, i, Line1b[i]);
     124    M->set(2, i, Line2a[i]);
     125    M->set(3, i, Line2b[i]);
    126126  }
    127127
  • src/LinearAlgebra/MatrixContent.cpp

    rcca9ef r0d4424  
    2525#include <gsl/gsl_blas.h>
    2626#include <gsl/gsl_eigen.h>
     27#include <gsl/gsl_linalg.h>
    2728#include <gsl/gsl_matrix.h>
    2829#include <gsl/gsl_multimin.h>
     
    131132    for(int j=columns;j--;){
    132133      set(i,j,0.);
     134    }
     135  }
     136}
     137
     138/** Set all matrix components to a given value.
     139 * \param _value value to set each component to
     140 */
     141void MatrixContent::setValue(double _value)
     142{
     143  for(int i=rows;i--;){
     144    for(int j=columns;j--;){
     145      set(i,j,_value);
    133146    }
    134147  }
     
    196209}
    197210
     211/* ========================== Accessing =============================== */
     212
    198213/** Accessor for manipulating component (i,j).
    199214 * \param i row number
     
    224239}
    225240
     241/** These functions return a pointer to the \a m-th element of a matrix.
     242 *  If \a m or \a n lies outside the allowed range of 0 to GSLMatrix::dimension-1 then the error handler is invoked and a null pointer is returned.
     243 * \param m index
     244 * \return pointer to \a m-th element
     245 */
     246double *MatrixContent::Pointer(size_t m, size_t n)
     247{
     248  return gsl_matrix_ptr (content, m, n);
     249};
     250
     251/** These functions return a constant pointer to the \a m-th element of a matrix.
     252 *  If \a m or \a n lies outside the allowed range of 0 to GSLMatrix::dimension-1 then the error handler is invoked and a null pointer is returned.
     253 * \param m index
     254 * \return const pointer to \a m-th element
     255 */
     256const double *MatrixContent::const_Pointer(size_t m, size_t n) const
     257{
     258  return gsl_matrix_const_ptr (content, m, n);
     259};
     260
     261/* ========================== Initializing =============================== */
     262
    226263/** Setter for component (i,j).
    227264 * \param i row numbr
     
    238275}
    239276
     277/** This function sets the matrix from a double array.
     278 * Creates a matrix view of the array and performs a memcopy.
     279 * \param *x array of values (no dimension check is performed)
     280 */
     281void MatrixContent::setFromDoubleArray(double * x)
     282{
     283  gsl_matrix_view m = gsl_matrix_view_array (x, rows, columns);
     284  gsl_matrix_memcpy (content, &m.matrix);
     285};
     286
     287/* ====================== Exchanging elements ============================ */
     288/** This function exchanges the \a i-th and \a j-th row of the matrix in-place.
     289 * \param i i-th row to swap with ...
     290 * \param j ... j-th row to swap against
     291 */
     292bool MatrixContent::SwapRows(size_t i, size_t j)
     293{
     294  return (gsl_matrix_swap_rows (content, i, j) == GSL_SUCCESS);
     295};
     296
     297/** This function exchanges the \a i-th and \a j-th column of the matrix in-place.
     298 * \param i i-th column to swap with ...
     299 * \param j ... j-th column to swap against
     300 */
     301bool MatrixContent::SwapColumns(size_t i, size_t j)
     302{
     303  return (gsl_matrix_swap_columns (content, i, j) == GSL_SUCCESS);
     304};
     305
     306/** This function exchanges the \a i-th row and \a j-th column of the matrix in-place.
     307 * The matrix must be square for this operation to be possible.
     308 * \param i i-th row to swap with ...
     309 * \param j ... j-th column to swap against
     310 */
     311bool MatrixContent::SwapRowColumn(size_t i, size_t j)
     312{
     313  assert (rows == columns && "The matrix must be square for swapping row against column to be possible.");
     314  return (gsl_matrix_swap_rowcol (content, i, j) == GSL_SUCCESS);
     315};
     316
    240317/** Return transposed matrix.
    241318 * \return new matrix that is transposed of this.
     
    244321{
    245322  std::cout << "const MatrixContent::transpose()." << std::endl;
    246   gsl_matrix *res = gsl_matrix_alloc(rows, columns);
     323  gsl_matrix *res = gsl_matrix_alloc(columns, rows);  // column and row dimensions exchanged!
    247324  gsl_matrix_transpose_memcpy(res, content);
    248325  MatrixContent newContent(res);
     
    286363  return eval;
    287364}
     365
     366/* ============================ Properties ============================== */
     367/** Checks whether matrix' elements are strictly null.
     368 * \return true - is null, false - else
     369 */
     370bool MatrixContent::IsNull() const
     371{
     372  return gsl_matrix_isnull (content);
     373};
     374
     375/** Checks whether matrix' elements are strictly positive.
     376 * \return true - is positive, false - else
     377 */
     378bool MatrixContent::IsPositive() const
     379{
     380  return gsl_matrix_ispos (content);
     381};
     382
     383/** Checks whether matrix' elements are strictly negative.
     384 * \return true - is negative, false - else
     385 */
     386bool MatrixContent::IsNegative() const
     387{
     388  return gsl_matrix_isneg (content);
     389};
     390
     391/** Checks whether matrix' elements are strictly non-negative.
     392 * \return true - is non-negative, false - else
     393 */
     394bool MatrixContent::IsNonNegative() const
     395{
     396  return gsl_matrix_isnonneg (content);
     397};
     398
     399/** This function performs a Cholesky decomposition to determine whether matrix is positive definite.
     400 * We check whether GSL returns GSL_EDOM as error, indicating that decomposition failed due to matrix not being positive-definite.
     401 * \return true - matrix is positive-definite, false - else
     402 */
     403bool MatrixContent::IsPositiveDefinite() const
     404{
     405  if (rows != columns)  // only possible for square matrices.
     406    return false;
     407  else
     408    return (gsl_linalg_cholesky_decomp (content) != GSL_EDOM);
     409};
     410
     411
     412/** Calculates the determinant of the matrix.
     413 * if matrix is square, uses LU decomposition.
     414 */
     415double MatrixContent::Determinant() const
     416{
     417  int signum = 0;
     418  assert (rows == columns && "Determinant can only be calculated for square matrices.");
     419  gsl_permutation *p = gsl_permutation_alloc(rows);
     420  gsl_linalg_LU_decomp(content, p, &signum);
     421  gsl_permutation_free(p);
     422  return gsl_linalg_LU_det(content, signum);
     423};
     424
     425/* ============================= Operators =============================== */
    288426
    289427/** Scalar multiplication operator.
  • src/LinearAlgebra/MatrixContent.hpp

    rcca9ef r0d4424  
    4141  friend Vector operator*(const MatrixContent &mat,const Vector &vec);
    4242  friend class RealSpaceMatrix;
     43  friend class LinearSystemOfEquations;
     44
     45  friend class MatrixContentTest;
     46  friend class MatrixContentSymmetricTest;
    4347public:
    4448  MatrixContent(size_t rows, size_t columns);
     
    5357  const double at(size_t i, size_t j) const;
    5458  void set(size_t i, size_t j, const double value);
     59  void setFromDoubleArray(double * x);
     60
     61  // Exchanging elements
     62  bool SwapRows(size_t i, size_t j);
     63  bool SwapColumns(size_t i, size_t j);
     64  bool SwapRowColumn(size_t i, size_t j);
    5565
    5666  // Transformations
     
    5969  gsl_vector* transformToEigenbasis();
    6070
     71  // Properties
     72  bool IsNull() const;
     73  bool IsPositive() const;
     74  bool IsNegative() const;
     75  bool IsNonNegative() const;
     76  bool IsPositiveDefinite() const;
     77  double Determinant() const;
     78
    6179  // Initializing
    6280  void setIdentity();
    6381  void setZero();
     82  void setValue(double _value);
    6483
    6584  // Operators
     
    7291  bool operator==(const MatrixContent &rhs) const;
    7392
     93protected:
     94  double *Pointer(size_t m, size_t n);
     95  const double *const_Pointer(size_t m, size_t n) const;
    7496
    7597private:
  • src/LinearAlgebra/linearsystemofequations.cpp

    rcca9ef r0d4424  
    2121
    2222#include "defs.hpp"
    23 #include "LinearAlgebra/gslmatrix.hpp"
     23#include "LinearAlgebra/MatrixContent.hpp"
    2424#include "LinearAlgebra/gslvector.hpp"
    2525#include "LinearAlgebra/linearsystemofequations.hpp"
     
    3737LinearSystemOfEquations::LinearSystemOfEquations(int m, int n) : rows(m), columns(n), IsSymmetric(false)
    3838{
    39   A = new GSLMatrix(m, n);
     39  A = new MatrixContent(m, n);
    4040  b = new GSLVector(m);
    4141  x = new GSLVector(n);
     
    8585void LinearSystemOfEquations::SetA(double *x)
    8686{
    87   A->SetFromDoubleArray(x);
     87  A->setFromDoubleArray(x);
    8888};
    8989
     
    129129  if (IsSymmetric) { // use LU
    130130    gsl_permutation * p = gsl_permutation_alloc (x->dimension);
    131     gsl_linalg_LU_decomp (A->matrix, p, &s);
    132     gsl_linalg_LU_solve (A->matrix, p, b->vector, x->vector);
     131    gsl_linalg_LU_decomp (A->content, p, &s);
     132    gsl_linalg_LU_solve (A->content, p, b->vector, x->vector);
    133133    gsl_permutation_free (p);
    134134  } else {  // use Householder
    135     //GSLMatrix *backup = new GSLMatrix(rows,columns);
     135    //MatrixContent *backup = new MatrixContent(rows,columns);
    136136    //*backup = *A;
    137     gsl_linalg_HH_solve (A->matrix, b->vector, x->vector);
     137    gsl_linalg_HH_solve (A->content, b->vector, x->vector);
    138138    //*A = *backup;
    139139    //delete(backup);
  • src/LinearAlgebra/linearsystemofequations.hpp

    rcca9ef r0d4424  
    2121
    2222class Vector;
    23 class GSLMatrix;
     23class MatrixContent;
    2424class GSLVector;
    2525
     
    4646  GSLVector *b;
    4747  GSLVector *x;
    48   GSLMatrix *A;
     48  MatrixContent *A;
    4949
    5050private:
  • src/unittests/Makefile.am

    rcca9ef r0d4424  
    2222  CountBondsUnitTest \
    2323  FormulaUnittest \
    24   GSLMatrixSymmetricUnitTest \
    25   GSLMatrixUnitTest \
    2624  GSLVectorUnitTest \
    2725  InfoUnitTest \
     
    3230  LogUnitTest \
    3331  manipulateAtomsTest \
     32  MatrixContentSymmetricUnitTest \
     33  MatrixContentUnitTest \
    3434  MatrixUnittest \
    3535  MenuDescriptionUnitTest \
     
    8282  CountBondsUnitTest.cpp \
    8383  FormulaUnittest.cpp \
    84   gslmatrixsymmetricunittest.cpp \
    85   gslmatrixunittest.cpp \
    8684  gslvectorunittest.cpp \
    8785  infounittest.cpp \
     
    9189  listofbondsunittest.cpp \
    9290  logunittest.cpp \
     91  MatrixContentSymmetricUnittest.cpp \
     92  MatrixContentUnittest.cpp \
    9393  MatrixUnittest.cpp \
    9494  manipulateAtomsTest.cpp \
     
    122122  CountBondsUnitTest.hpp \
    123123  FormulaUnittest.hpp \
    124   gslmatrixsymmetricunittest.hpp \
    125   gslmatrixunittest.hpp \
    126124  gslvectorunittest.hpp \
    127125  infounittest.hpp \
     
    132130  logunittest.hpp \
    133131  manipulateAtomsTest.hpp \
     132  MatrixContentSymmetricUnittest.hpp \
     133  MatrixContentUnittest.hpp \
    134134  MatrixUnittest.hpp \
    135135  MenuDescriptionUnitTest.hpp \
     
    187187FormulaUnittest_LDADD = ${ALLLIBS}
    188188
    189 GSLMatrixSymmetricUnitTest_SOURCES = UnitTestMain.cpp gslmatrixsymmetricunittest.cpp gslmatrixsymmetricunittest.hpp
    190 GSLMatrixSymmetricUnitTest_LDADD = ${ALLLIBS}
    191 
    192 GSLMatrixUnitTest_SOURCES = UnitTestMain.cpp gslmatrixunittest.cpp gslmatrixunittest.hpp
    193 GSLMatrixUnitTest_LDADD = ${ALLLIBS}
     189MatrixContentSymmetricUnitTest_SOURCES = UnitTestMain.cpp MatrixContentSymmetricUnittest.cpp MatrixContentSymmetricUnittest
     190MatrixContentSymmetricUnitTest_LDADD = ${ALLLIBS}
     191
     192MatrixContentUnitTest_SOURCES = UnitTestMain.cpp MatrixContentUnittest.cpp MatrixContentUnittest.hpp
     193MatrixContentUnitTest_LDADD = ${ALLLIBS}
    194194
    195195GSLVectorUnitTest_SOURCES = UnitTestMain.cpp gslvectorunittest.cpp gslvectorunittest.hpp
  • src/unittests/MatrixContentSymmetricUnittest.cpp

    rcca9ef r0d4424  
    77
    88/*
    9  * gslmatrixunittest.cpp
     9 * MatrixContentSymmetricUnittest.cpp
    1010 *
    1111 *  Created on: Jan 8, 2010
     
    2424#include <cppunit/ui/text/TestRunner.h>
    2525
    26 #include "gslmatrixsymmetricunittest.hpp"
     26#include "MatrixContentSymmetricUnittest.hpp"
     27
     28#include "LinearAlgebra/MatrixContent.hpp"
    2729
    2830#ifdef HAVE_TESTRUNNER
     
    3335
    3436// Registers the fixture into the 'registry'
    35 CPPUNIT_TEST_SUITE_REGISTRATION( GSLMatrixSymmetricTest );
    36 
    37 
    38 void GSLMatrixSymmetricTest::setUp()
    39 {
    40   m = new GSLMatrix(3,3);
    41 };
    42 
    43 void GSLMatrixSymmetricTest::tearDown()
     37CPPUNIT_TEST_SUITE_REGISTRATION( MatrixContentSymmetricTest );
     38
     39
     40void MatrixContentSymmetricTest::setUp()
     41{
     42  m = new MatrixContent(3,3);
     43};
     44
     45void MatrixContentSymmetricTest::tearDown()
    4446{
    4547  delete(m);
     
    4951 *
    5052 */
    51 void GSLMatrixSymmetricTest::AccessTest()
     53void MatrixContentSymmetricTest::AccessTest()
    5254{
    5355  // check whether all elements are initially zero
    5456  for (int i=0;i<3;i++)
    5557    for (int j=0;j<3;j++)
    56       CPPUNIT_ASSERT_EQUAL( 0., m->Get(i,j) );
     58      CPPUNIT_ASSERT_EQUAL( 0., m->at(i,j) );
    5759
    5860  // set
    5961  for (int i=0;i<3;i++)
    6062    for (int j=0;j<3;j++)
    61       m->Set(i,j, i*3+j );
     63      m->set(i,j, i*3+j );
    6264
    6365  // and check
     
    6567  for (int i=0;i<3;i++)
    6668    for (int j=0;j<3;j++) {
    67       CPPUNIT_ASSERT_EQUAL( (double)(i*3+j), m->Get(i,j) );
     69      CPPUNIT_ASSERT_EQUAL( (double)(i*3+j), m->at(i,j) );
    6870      ptr = m->Pointer(i,j);
    6971      CPPUNIT_ASSERT_EQUAL( (double)(i*3+j), *ptr );
     
    7375  for (int i=0;i<3;i++)
    7476    for (int j=0;j<3;j++)
    75       m->Set(i,j, i*3+j );
    76   GSLMatrix *dest = new GSLMatrix(3,3);
     77      m->set(i,j, i*3+j );
     78  MatrixContent *dest = new MatrixContent(3,3);
    7779  *dest = *m;
    7880  for (int i=0;i<3;i++)
    7981    for (int j=0;j<3;j++)
    80       CPPUNIT_ASSERT_EQUAL( dest->Get(i,j), m->Get(i,j) );
     82      CPPUNIT_ASSERT_EQUAL( dest->at(i,j), m->at(i,j) );
    8183  delete(dest);
    8284
    8385  // out of bounds
    84   //CPPUNIT_ASSERT_EQUAL(0., v->Get(4,2) );
    85   //CPPUNIT_ASSERT_EQUAL(0., v->Get(2,17) );
    86   //CPPUNIT_ASSERT_EQUAL(0., v->Get(1024,140040) );
    87   //CPPUNIT_ASSERT_EQUAL(0., v->Get(-1,0) );
    88   //CPPUNIT_ASSERT_EQUAL(0., v->Get(0,-1) );
    89   //CPPUNIT_ASSERT_EQUAL(0., v->Get(-1,-1) );
     86  //CPPUNIT_ASSERT_EQUAL(0., v->at(4,2) );
     87  //CPPUNIT_ASSERT_EQUAL(0., v->at(2,17) );
     88  //CPPUNIT_ASSERT_EQUAL(0., v->at(1024,140040) );
     89  //CPPUNIT_ASSERT_EQUAL(0., v->at(-1,0) );
     90  //CPPUNIT_ASSERT_EQUAL(0., v->at(0,-1) );
     91  //CPPUNIT_ASSERT_EQUAL(0., v->at(-1,-1) );
    9092};
    9193
     
    9395 *
    9496 */
    95 void GSLMatrixSymmetricTest::InitializationTest()
     97void MatrixContentSymmetricTest::InitializationTest()
    9698{
    9799  // set zero
    98   m->SetZero();
    99   for (int i=0;i<3;i++)
    100     for (int j=0;j<3;j++)
    101       CPPUNIT_ASSERT_EQUAL( 0., m->Get(i,j) );
     100  m->setZero();
     101  for (int i=0;i<3;i++)
     102    for (int j=0;j<3;j++)
     103      CPPUNIT_ASSERT_EQUAL( 0., m->at(i,j) );
    102104
    103105  // set all
    104   m->SetAll(1.5);
    105   for (int i=0;i<3;i++)
    106     for (int j=0;j<3;j++)
    107       CPPUNIT_ASSERT_EQUAL( 1.5, m->Get(i,j) );
     106  m->setValue(1.5);
     107  for (int i=0;i<3;i++)
     108    for (int j=0;j<3;j++)
     109      CPPUNIT_ASSERT_EQUAL( 1.5, m->at(i,j) );
    108110
    109111  // set basis
    110   m->SetIdentity();
    111   for (int i=0;i<3;i++)
    112     for (int j=0;j<3;j++)
    113       CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m->Get(i,j) );
     112  m->setIdentity();
     113  for (int i=0;i<3;i++)
     114    for (int j=0;j<3;j++)
     115      CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m->at(i,j) );
    114116
    115117  // set from array
     
    117119                     0., 1., 0.,
    118120                     0., 0., 1. };
    119   m->SetFromDoubleArray(array);
    120   for (int i=0;i<3;i++)
    121     for (int j=0;j<3;j++)
    122       CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m->Get(i,j) );
     121  m->setFromDoubleArray(array);
     122  for (int i=0;i<3;i++)
     123    for (int j=0;j<3;j++)
     124      CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m->at(i,j) );
    123125
    124126};
     
    127129 *
    128130 */
    129 void GSLMatrixSymmetricTest::CopyTest()
     131void MatrixContentSymmetricTest::CopyTest()
    130132{
    131133  // set basis
    132   GSLMatrix *dest = NULL;
     134  MatrixContent *dest = NULL;
    133135  for (int i=0;i<3;i++) {
    134     m->SetAll(i);
    135     dest = new GSLMatrix(m);
    136     for (int j=0;j<3;j++)
    137       CPPUNIT_ASSERT_EQUAL( m->Get(i,j) , dest->Get(i,j) );
     136    m->setValue(i);
     137    dest = new MatrixContent(m);
     138    for (int j=0;j<3;j++)
     139      CPPUNIT_ASSERT_EQUAL( m->at(i,j) , dest->at(i,j) );
    138140
    139141    delete(dest);
     
    144146 *
    145147 */
    146 void GSLMatrixSymmetricTest::ExchangeTest()
     148void MatrixContentSymmetricTest::ExchangeTest()
    147149{
    148150  // set to 1,1,1,2, ...
    149151  for (int i=0;i<3;i++)
    150152    for (int j=0;j<3;j++)
    151       m->Set(i,j, i+1 );
     153      m->set(i,j, i+1 );
    152154
    153155  // swap such that nothing happens
     
    155157  for (int i=0;i<3;i++)
    156158    for (int j=0;j<3;j++)
    157       CPPUNIT_ASSERT_EQUAL( (double)i+1., m->Get(i,j) );
     159      CPPUNIT_ASSERT_EQUAL( (double)i+1., m->at(i,j) );
    158160
    159161  // swap two rows
     
    163165      switch (j) {
    164166        case 0:
    165           CPPUNIT_ASSERT_EQUAL( 1., m->Get(j,i) );
     167          CPPUNIT_ASSERT_EQUAL( 1., m->at(j,i) );
    166168          break;
    167169        case 1:
    168           CPPUNIT_ASSERT_EQUAL( 3., m->Get(j,i) );
     170          CPPUNIT_ASSERT_EQUAL( 3., m->at(j,i) );
    169171          break;
    170172        case 2:
    171           CPPUNIT_ASSERT_EQUAL( 2., m->Get(j,i) );
     173          CPPUNIT_ASSERT_EQUAL( 2., m->at(j,i) );
    172174          break;
    173175        default:
    174           CPPUNIT_ASSERT_EQUAL( -1., m->Get(i,j) );
     176          CPPUNIT_ASSERT_EQUAL( -1., m->at(i,j) );
    175177      }
    176178  // check that op is reversable
     
    178180  for (int i=0;i<3;i++)
    179181    for (int j=0;j<3;j++)
    180       CPPUNIT_ASSERT_EQUAL( (double)i+1., m->Get(i,j) );
     182      CPPUNIT_ASSERT_EQUAL( (double)i+1., m->at(i,j) );
    181183
    182184  // set to 1,2,3,1, ...
    183185  for (int i=0;i<3;i++)
    184186    for (int j=0;j<3;j++)
    185       m->Set(i,j, j+1. );
     187      m->set(i,j, j+1. );
    186188
    187189  // swap such that nothing happens
     
    189191  for (int i=0;i<3;i++)
    190192    for (int j=0;j<3;j++)
    191       CPPUNIT_ASSERT_EQUAL( (double)j+1., m->Get(i,j) );
     193      CPPUNIT_ASSERT_EQUAL( (double)j+1., m->at(i,j) );
    192194
    193195  // swap two columns
     
    197199      switch (j) {
    198200        case 0:
    199           CPPUNIT_ASSERT_EQUAL( 3., m->Get(i,j) );
     201          CPPUNIT_ASSERT_EQUAL( 3., m->at(i,j) );
    200202          break;
    201203        case 1:
    202           CPPUNIT_ASSERT_EQUAL( 2., m->Get(i,j) );
     204          CPPUNIT_ASSERT_EQUAL( 2., m->at(i,j) );
    203205          break;
    204206        case 2:
    205           CPPUNIT_ASSERT_EQUAL( 1., m->Get(i,j) );
     207          CPPUNIT_ASSERT_EQUAL( 1., m->at(i,j) );
    206208          break;
    207209        default:
    208           CPPUNIT_ASSERT_EQUAL( -1., m->Get(i,j) );
     210          CPPUNIT_ASSERT_EQUAL( -1., m->at(i,j) );
    209211      }
    210212  // check that op is reversable
     
    212214  for (int i=0;i<3;i++)
    213215    for (int j=0;j<3;j++)
    214       CPPUNIT_ASSERT_EQUAL( (double)j+1., m->Get(i,j) );
    215 
    216 
    217   // set to 1,2,3,4, ...
    218   for (int i=0;i<3;i++)
    219     for (int j=0;j<3;j++)
    220       m->Set(i,j, 3*i+j+1 );
     216      CPPUNIT_ASSERT_EQUAL( (double)j+1., m->at(i,j) );
     217
     218
     219  // set to 1,2,3, ...
     220  MatrixContent *n =  new MatrixContent(3,3);
     221  for (int i=0;i<3;i++)
     222    for (int j=0;j<3;j++) {
     223      m->set(i,j, 3*i+j+1 );
     224      n->set(i,j, 3*j+i+1 );
     225    }
    221226  // transpose
    222   m->Transpose();
    223   for (int i=0;i<3;i++)
    224     for (int j=0;j<3;j++)
    225       CPPUNIT_ASSERT_EQUAL( (double)(3*i+j+1), m->Get(j,i) );
     227  MatrixContent res = ((const MatrixContent)*m).transpose();
     228  CPPUNIT_ASSERT( *n == res );
    226229  // second transpose
    227   m->Transpose();
    228   for (int i=0;i<3;i++)
    229     for (int j=0;j<3;j++)
    230       CPPUNIT_ASSERT_EQUAL( (double)(3*i+j+1), m->Get(i,j) );
     230  res.transpose();
     231  CPPUNIT_ASSERT( *m == res );
    231232};
    232233
     
    234235 *
    235236 */
    236 void GSLMatrixSymmetricTest::PropertiesTest()
     237void MatrixContentSymmetricTest::PropertiesTest()
    237238{
    238239  // is zero
    239   m->SetZero();
     240  m->setZero();
    240241  CPPUNIT_ASSERT_EQUAL( true, m->IsNull() );
    241242  CPPUNIT_ASSERT_EQUAL( false, m->IsPositive() );
     
    244245
    245246  // is positive
    246   m->SetAll(0.5);
     247  m->setValue(0.5);
    247248  CPPUNIT_ASSERT_EQUAL( false, m->IsNull() );
    248249  CPPUNIT_ASSERT_EQUAL( true, m->IsPositive() );
     
    251252
    252253  // is negative
    253   m->SetAll(-0.1);
     254  m->setValue(-0.1);
    254255  CPPUNIT_ASSERT_EQUAL( false, m->IsNull() );
    255256  CPPUNIT_ASSERT_EQUAL( false, m->IsPositive() );
     
    261262                     0., 1., 1.,
    262263                     0., 0., 1. };
    263   m->SetFromDoubleArray(array);
     264  m->setFromDoubleArray(array);
    264265  CPPUNIT_ASSERT_EQUAL( true, m->IsPositiveDefinite() );
    265266
    266267  //determinant
    267   m->SetIdentity();
     268  m->setIdentity();
    268269  CPPUNIT_ASSERT_EQUAL( 1., m->Determinant() );
    269270
    270   m->SetZero();
     271  m->setZero();
    271272  CPPUNIT_ASSERT_EQUAL( 0., m->Determinant() );
    272273
    273   m->Set( 0, 0, 1.);
    274   m->Set( 1, 1, 1.);
    275   m->Set( 2, 1, 1.);
     274  m->set( 0, 0, 1.);
     275  m->set( 1, 1, 1.);
     276  m->set( 2, 1, 1.);
    276277  CPPUNIT_ASSERT_EQUAL( 0., m->Determinant() );
    277278 
     
    279280                     -3., 1., 1.,
    280281                     1., 5.5, 1. };
    281   m->SetFromDoubleArray(array2);
     282  m->setFromDoubleArray(array2);
    282283  CPPUNIT_ASSERT_EQUAL( -26.5, m->Determinant() );
    283284};
  • src/unittests/MatrixContentSymmetricUnittest.hpp

    rcca9ef r0d4424  
    11/*
    2  * gslmatrixunittest.hpp
     2 * MatrixContentSymmetricUnittest.hpp
    33 *
    44 *  Created on: Jan 8, 2010
     
    66 */
    77
    8 #ifndef GSLMATRIXUNITTEST_HPP_
    9 #define GSLMATRIXUNITTEST_HPP_
     8#ifndef MATRIXCONTENTSYMMETRICUNITTEST_HPP_
     9#define MATRIXCONTENTSYMMETRICUNITTEST_HPP_
    1010
    1111#include <cppunit/extensions/HelperMacros.h>
    1212
    13 #include "LinearAlgebra/gslmatrix.hpp"
     13class MatrixContent;
    1414
    1515/********************************************** Test classes **************************************/
    1616
    17 class GSLMatrixSymmetricTest : public CppUnit::TestFixture
     17class MatrixContentSymmetricTest : public CppUnit::TestFixture
    1818{
    19     CPPUNIT_TEST_SUITE( GSLMatrixSymmetricTest) ;
     19    CPPUNIT_TEST_SUITE( MatrixContentSymmetricTest) ;
    2020    CPPUNIT_TEST (AccessTest );
    2121    CPPUNIT_TEST (InitializationTest );
     
    3636
    3737private:
    38     GSLMatrix *m;
     38    MatrixContent *m;
    3939};
    4040
    4141
    42 #endif /* GSLMATRIXUNITTEST_HPP_ */
     42#endif /* MATRIXCONTENTSYMMETRICUNITTEST_HPP_ */
  • src/unittests/MatrixContentUnittest.cpp

    rcca9ef r0d4424  
    77
    88/*
    9  * gslmatrixunittest.cpp
     9 * MatrixContentUnittest.cpp
    1010 *
    1111 *  Created on: Jan 8, 2010
     
    2424#include <cppunit/ui/text/TestRunner.h>
    2525
    26 #include "gslmatrixunittest.hpp"
     26#include "MatrixContentUnittest.hpp"
     27
     28#include "LinearAlgebra/MatrixContent.hpp"
    2729
    2830#ifdef HAVE_TESTRUNNER
     
    3335
    3436// Registers the fixture into the 'registry'
    35 CPPUNIT_TEST_SUITE_REGISTRATION( GSLMatrixTest );
    36 
    37 
    38 void GSLMatrixTest::setUp()
    39 {
    40   m = new GSLMatrix(4,3);
    41 };
    42 
    43 void GSLMatrixTest::tearDown()
     37CPPUNIT_TEST_SUITE_REGISTRATION( MatrixContentTest );
     38
     39
     40void MatrixContentTest::setUp()
     41{
     42  m = new MatrixContent(4,3);
     43};
     44
     45void MatrixContentTest::tearDown()
    4446{
    4547  delete(m);
     
    4951 *
    5052 */
    51 void GSLMatrixTest::AccessTest()
     53void MatrixContentTest::AccessTest()
    5254{
    5355  // check whether all elements are initially zero
    5456  for (int i=0;i<4;i++)
    5557    for (int j=0;j<3;j++)
    56       CPPUNIT_ASSERT_EQUAL( 0., m->Get(i,j) );
     58      CPPUNIT_ASSERT_EQUAL( 0., m->at(i,j) );
    5759
    5860  // set
    5961  for (int i=0;i<4;i++)
    6062    for (int j=0;j<3;j++)
    61       m->Set(i,j, i*3+j );
     63      m->set(i,j, i*3+j );
    6264
    6365  // and check
     
    6567  for (int i=0;i<4;i++)
    6668    for (int j=0;j<3;j++) {
    67       CPPUNIT_ASSERT_EQUAL( (double)(i*3+j), m->Get(i,j) );
     69      CPPUNIT_ASSERT_EQUAL( (double)(i*3+j), m->at(i,j) );
    6870      ptr = m->Pointer(i,j);
    6971      CPPUNIT_ASSERT_EQUAL( (double)(i*3+j), *ptr );
     
    7375  for (int i=0;i<4;i++)
    7476    for (int j=0;j<3;j++)
    75       m->Set(i,j, i*3+j );
    76   GSLMatrix *dest = new GSLMatrix(4,3);
     77      m->set(i,j, i*3+j );
     78  MatrixContent *dest = new MatrixContent(4,3);
    7779  *dest = *m;
    7880  for (int i=0;i<4;i++)
    7981    for (int j=0;j<3;j++)
    80       CPPUNIT_ASSERT_EQUAL( dest->Get(i,j), m->Get(i,j) );
     82      CPPUNIT_ASSERT_EQUAL( dest->at(i,j), m->at(i,j) );
    8183  delete(dest);
    8284
    8385  // out of bounds
    84   //CPPUNIT_ASSERT_EQUAL(0., v->Get(5,2) );
    85   //CPPUNIT_ASSERT_EQUAL(0., v->Get(2,17) );
    86   //CPPUNIT_ASSERT_EQUAL(0., v->Get(1024,140040) );
    87   //CPPUNIT_ASSERT_EQUAL(0., v->Get(-1,0) );
    88   //CPPUNIT_ASSERT_EQUAL(0., v->Get(0,-1) );
    89   //CPPUNIT_ASSERT_EQUAL(0., v->Get(-1,-1) );
     86  //CPPUNIT_ASSERT_EQUAL(0., v->at(5,2) );
     87  //CPPUNIT_ASSERT_EQUAL(0., v->at(2,17) );
     88  //CPPUNIT_ASSERT_EQUAL(0., v->at(1024,140040) );
     89  //CPPUNIT_ASSERT_EQUAL(0., v->at(-1,0) );
     90  //CPPUNIT_ASSERT_EQUAL(0., v->at(0,-1) );
     91  //CPPUNIT_ASSERT_EQUAL(0., v->at(-1,-1) );
    9092};
    9193
     
    9395 *
    9496 */
    95 void GSLMatrixTest::InitializationTest()
     97void MatrixContentTest::InitializationTest()
    9698{
    9799  // set zero
    98   m->SetZero();
    99   for (int i=0;i<4;i++)
    100     for (int j=0;j<3;j++)
    101       CPPUNIT_ASSERT_EQUAL( 0., m->Get(i,j) );
     100  m->setZero();
     101  for (int i=0;i<4;i++)
     102    for (int j=0;j<3;j++)
     103      CPPUNIT_ASSERT_EQUAL( 0., m->at(i,j) );
    102104
    103105  // set all
    104   m->SetAll(1.5);
    105   for (int i=0;i<4;i++)
    106     for (int j=0;j<3;j++)
    107       CPPUNIT_ASSERT_EQUAL( 1.5, m->Get(i,j) );
     106  m->setValue(1.5);
     107  for (int i=0;i<4;i++)
     108    for (int j=0;j<3;j++)
     109      CPPUNIT_ASSERT_EQUAL( 1.5, m->at(i,j) );
    108110
    109111  // set basis
    110   m->SetIdentity();
    111   for (int i=0;i<4;i++)
    112     for (int j=0;j<3;j++)
    113       CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m->Get(i,j) );
     112  m->setIdentity();
     113  for (int i=0;i<4;i++)
     114    for (int j=0;j<3;j++)
     115      CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m->at(i,j) );
    114116
    115117  // set from array
     
    118120                     0., 0., 1.,
    119121                     0., 0., 0. };
    120   m->SetFromDoubleArray(array);
    121   for (int i=0;i<4;i++)
    122     for (int j=0;j<3;j++)
    123       CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m->Get(i,j) );
     122  m->setFromDoubleArray(array);
     123  for (int i=0;i<4;i++)
     124    for (int j=0;j<3;j++)
     125      CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m->at(i,j) );
    124126
    125127};
     
    128130 *
    129131 */
    130 void GSLMatrixTest::CopyTest()
     132void MatrixContentTest::CopyTest()
    131133{
    132134  // set basis
    133   GSLMatrix *dest = NULL;
     135  MatrixContent *dest = NULL;
    134136  for (int i=0;i<4;i++) {
    135     m->SetAll(i);
    136     dest = new GSLMatrix(m);
    137     for (int j=0;j<3;j++)
    138       CPPUNIT_ASSERT_EQUAL( m->Get(i,j) , dest->Get(i,j) );
     137    m->setValue(i);
     138    dest = new MatrixContent(m);
     139    for (int j=0;j<3;j++)
     140      CPPUNIT_ASSERT_EQUAL( m->at(i,j) , dest->at(i,j) );
    139141
    140142    delete(dest);
     
    145147 *
    146148 */
    147 void GSLMatrixTest::ExchangeTest()
     149void MatrixContentTest::ExchangeTest()
    148150{
    149151  // set to 1,1,1,2, ...
    150152  for (int i=0;i<4;i++)
    151153    for (int j=0;j<3;j++)
    152       m->Set(i,j, i+1 );
     154      m->set(i,j, i+1 );
    153155
    154156  // swap such that nothing happens
     
    156158  for (int i=0;i<4;i++)
    157159    for (int j=0;j<3;j++)
    158       CPPUNIT_ASSERT_EQUAL( (double)i+1., m->Get(i,j) );
     160      CPPUNIT_ASSERT_EQUAL( (double)i+1., m->at(i,j) );
    159161
    160162  // swap two rows
     
    164166      switch (i) {
    165167        case 0:
    166           CPPUNIT_ASSERT_EQUAL( 1., m->Get(i,j) );
     168          CPPUNIT_ASSERT_EQUAL( 1., m->at(i,j) );
    167169          break;
    168170        case 1:
    169           CPPUNIT_ASSERT_EQUAL( 3., m->Get(i,j) );
     171          CPPUNIT_ASSERT_EQUAL( 3., m->at(i,j) );
    170172          break;
    171173        case 2:
    172           CPPUNIT_ASSERT_EQUAL( 2., m->Get(i,j) );
     174          CPPUNIT_ASSERT_EQUAL( 2., m->at(i,j) );
    173175          break;
    174176        case 3:
    175           CPPUNIT_ASSERT_EQUAL( 4., m->Get(i,j) );
     177          CPPUNIT_ASSERT_EQUAL( 4., m->at(i,j) );
    176178          break;
    177179        default:
    178           CPPUNIT_ASSERT_EQUAL( -1., m->Get(i,j) );
     180          CPPUNIT_ASSERT_EQUAL( -1., m->at(i,j) );
    179181      }
    180182  // check that op is reversable
     
    182184  for (int i=0;i<4;i++)
    183185    for (int j=0;j<3;j++)
    184       CPPUNIT_ASSERT_EQUAL( (double)i+1., m->Get(i,j) );
     186      CPPUNIT_ASSERT_EQUAL( (double)i+1., m->at(i,j) );
    185187
    186188  // set to 1,2,3,1, ...
    187189  for (int i=0;i<4;i++)
    188190    for (int j=0;j<3;j++)
    189       m->Set(i,j, j+1. );
     191      m->set(i,j, j+1. );
    190192
    191193  // swap such that nothing happens
     
    193195  for (int i=0;i<4;i++)
    194196    for (int j=0;j<3;j++)
    195       CPPUNIT_ASSERT_EQUAL( (double)j+1., m->Get(i,j) );
     197      CPPUNIT_ASSERT_EQUAL( (double)j+1., m->at(i,j) );
    196198
    197199  // swap two columns
     
    201203      switch (j) {
    202204        case 0:
    203           CPPUNIT_ASSERT_EQUAL( 3., m->Get(i,j) );
     205          CPPUNIT_ASSERT_EQUAL( 3., m->at(i,j) );
    204206          break;
    205207        case 1:
    206           CPPUNIT_ASSERT_EQUAL( 2., m->Get(i,j) );
     208          CPPUNIT_ASSERT_EQUAL( 2., m->at(i,j) );
    207209          break;
    208210        case 2:
    209           CPPUNIT_ASSERT_EQUAL( 1., m->Get(i,j) );
     211          CPPUNIT_ASSERT_EQUAL( 1., m->at(i,j) );
    210212          break;
    211213        default:
    212           CPPUNIT_ASSERT_EQUAL( -1., m->Get(i,j) );
     214          CPPUNIT_ASSERT_EQUAL( -1., m->at(i,j) );
    213215      }
    214216  // check that op is reversable
     
    216218  for (int i=0;i<4;i++)
    217219    for (int j=0;j<3;j++)
    218       CPPUNIT_ASSERT_EQUAL( (double)j+1., m->Get(i,j) );
     220      CPPUNIT_ASSERT_EQUAL( (double)j+1., m->at(i,j) );
    219221
    220222
    221223  // set to 1,2,3,4, ...
    222   for (int i=0;i<4;i++)
    223     for (int j=0;j<3;j++)
    224       m->Set(i,j, 3*i+j+1 );
     224  MatrixContent *n =  new MatrixContent(3,4);
     225  for (int i=0;i<4;i++)
     226    for (int j=0;j<3;j++) {
     227      m->set(i,j, 3*i+j+1 );
     228      n->set(j,i, 3*i+j+1 );
     229    }
    225230  // transpose
    226   CPPUNIT_ASSERT_EQUAL( true, m->Transpose() );
    227   for (int i=0;i<4;i++)
    228     for (int j=0;j<3;j++)
    229       CPPUNIT_ASSERT_EQUAL( (double)(3*i+j+1), m->Get(j,i) );
     231  MatrixContent res = ((const MatrixContent)(*m)).transpose();
     232  CPPUNIT_ASSERT( *n == res );
    230233  // second transpose
    231   CPPUNIT_ASSERT_EQUAL( true, m->Transpose() );
    232   for (int i=0;i<4;i++)
    233     for (int j=0;j<3;j++)
    234       CPPUNIT_ASSERT_EQUAL( (double)(3*i+j+1), m->Get(i,j) );
     234  MatrixContent res2 = ((const MatrixContent)res).transpose();
     235  CPPUNIT_ASSERT( *m == res2 );
    235236};
    236237
     
    238239 *
    239240 */
    240 void GSLMatrixTest::PropertiesTest()
     241void MatrixContentTest::PropertiesTest()
    241242{
    242243  // is zero
    243   m->SetZero();
     244  m->setZero();
    244245  CPPUNIT_ASSERT_EQUAL( true, m->IsNull() );
    245246  CPPUNIT_ASSERT_EQUAL( false, m->IsPositive() );
     
    248249
    249250  // is positive
    250   m->SetAll(0.5);
     251  m->setValue(0.5);
    251252  CPPUNIT_ASSERT_EQUAL( false, m->IsNull() );
    252253  CPPUNIT_ASSERT_EQUAL( true, m->IsPositive() );
     
    255256
    256257  // is negative
    257   m->SetAll(-0.1);
     258  m->setValue(-0.1);
    258259  CPPUNIT_ASSERT_EQUAL( false, m->IsNull() );
    259260  CPPUNIT_ASSERT_EQUAL( false, m->IsPositive() );
  • src/unittests/MatrixContentUnittest.hpp

    rcca9ef r0d4424  
    11/*
    2  * gslmatrixunittest.hpp
     2 * MatrixContentUnittest.hpp
    33 *
    44 *  Created on: Jan 8, 2010
     
    66 */
    77
    8 #ifndef GSLMATRIXUNITTEST_HPP_
    9 #define GSLMATRIXUNITTEST_HPP_
     8#ifndef MATRIXCONTENTUNITTEST_HPP_
     9#define MATRIXCONTENTUNITTEST_HPP_
    1010
    1111#include <cppunit/extensions/HelperMacros.h>
    1212
    13 #include "LinearAlgebra/gslmatrix.hpp"
     13class MatrixContent;
    1414
    1515/********************************************** Test classes **************************************/
    1616
    17 class GSLMatrixTest : public CppUnit::TestFixture
     17class MatrixContentTest : public CppUnit::TestFixture
    1818{
    19     CPPUNIT_TEST_SUITE( GSLMatrixTest) ;
     19    CPPUNIT_TEST_SUITE( MatrixContentTest) ;
    2020    CPPUNIT_TEST (AccessTest );
    2121    CPPUNIT_TEST (InitializationTest );
     
    3636
    3737private:
    38     GSLMatrix *m;
     38    MatrixContent *m;
    3939};
    4040
    4141
    42 #endif /* GSLMATRIXUNITTEST_HPP_ */
     42#endif /* MATRIXCONTENTUNITTEST_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.