Changeset f6ad4d


Ignore:
Timestamp:
Mar 28, 2012, 8:17:35 AM (13 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:
53bc04
Parents:
418b5e
git-author:
Frederik Heber <heber@…> (03/14/12 16:14:03)
git-committer:
Frederik Heber <heber@…> (03/28/12 08:17:35)
Message:

Added copy cstor from Set to VectorSet and VectorSet::transform().

  • VectorSet::transform() required that Vector.hpp did not contain using namespace anymore.
  • Copy cstor allows to create from e.g. a std::vector<Vector> a VectorSet and then use the functions contained.
  • added unit tests on both.
Location:
LinearAlgebra/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • LinearAlgebra/src/LinearAlgebra/VectorSet.hpp

    r418b5e rf6ad4d  
    1818#include <algorithm>
    1919#include <limits>
     20#include <boost/bind.hpp>
    2021#include <boost/lambda/bind.hpp>
    2122#include <boost/lambda/lambda.hpp>
     
    2829
    2930#include "Vector.hpp"
     31
    3032#include <vector>
     33#include "RealSpaceMatrix.hpp"
    3134
    3235// this tests, whether we actually have a Vector
     
    5053
    5154  VectorSet(){}
     55  VectorSet(const Set &_set) : Set(_set) {}
    5256  virtual ~VectorSet(){}
     57
     58  /**
     59   * transform all Vectors within this set by a RealSpaceMatrix
     60   */
     61  void transform(const RealSpaceMatrix &M){
     62    // this is needed to allow template lookup
     63    std::transform(this->begin(),this->end(),this->begin(),
     64        boost::bind(static_cast<Vector(*)(const RealSpaceMatrix&,const Vector&)>(operator*), M, _1));
     65  }
    5366
    5467  /**
     
    5770  void translate(const Vector &translater){
    5871    // this is needed to allow template lookup
    59     std::transform(this->begin(),this->end(),this->begin(),std::bind1st(std::plus<Vector>(),translater));
     72    std::transform(this->begin(),this->end(),this->begin(),
     73        std::bind1st(std::plus<Vector>(),translater));
    6074  }
    6175
  • LinearAlgebra/src/unittests/VectorSetUnitTest.cpp

    r418b5e rf6ad4d  
    2525
    2626#include "VectorSetUnitTest.hpp"
     27
     28#include "RealSpaceMatrix.hpp"
     29#include "VectorSet.hpp"
    2730
    2831#ifdef HAVE_TESTRUNNER
     
    5659}
    5760
     61/** UnitTest for Cstor(Set &)
     62 */
     63void VectorSetTest::copyConstructorTest()
     64{
     65  VECTORSET(std::vector) worklist(list);
     66  CPPUNIT_ASSERT_EQUAL( list.size(), worklist.size() );
     67  std::vector<Vector>::const_iterator iter = list.begin();
     68  VECTORSET(std::vector)::const_iterator workiter = worklist.begin();
     69  for (;(iter != list.end()) && (workiter != worklist.end()); ++iter, ++workiter)
     70    CPPUNIT_ASSERT( ((*iter)) == (*workiter) );
     71}
     72
     73
    5874/** UnitTest for translate()
    5975 */
     
    6985}
    7086
     87/** UnitTest for transform()
     88 */
     89void VectorSetTest::transformTest()
     90{
     91  VECTORSET(std::vector) worklist(list);
     92  RealSpaceMatrix M;
     93  M.setIdentity();
     94  M *= 2.;
     95  worklist.transform(M);
     96  VECTORSET(std::vector)::const_iterator iter = list.begin();
     97  VECTORSET(std::vector)::const_iterator workiter = worklist.begin();
     98  for (;(iter != list.end()) && (workiter != worklist.end()); ++iter, ++workiter)
     99    CPPUNIT_ASSERT( (2.*(*iter)) == (*workiter) );
     100}
     101
    71102/** UnitTest for minDistance()
    72103 */
    73104void VectorSetTest::minDistanceTest()
    74105{
     106  VECTORSET(std::vector) worklist(list);
    75107  {
    76108    VECTORSET(std::vector) somelist;
     
    83115  {
    84116    Vector center(5.,0.,0.);
    85     Vector mindist = list.minDistance(center);
     117    Vector mindist = worklist.minDistance(center);
    86118    CPPUNIT_ASSERT_EQUAL (Vector(2., 1., 0.)-center, mindist);
    87119  }
    88120  {
    89     for (VECTORSET(std::vector)::const_iterator iter = list.begin();
    90         iter != list.end(); ++iter) {
    91       Vector mindist = list.minDistance(*iter);
     121    for (VECTORSET(std::vector)::const_iterator iter = worklist.begin();
     122        iter != worklist.end(); ++iter) {
     123      Vector mindist = worklist.minDistance(*iter);
    92124      CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,0.), mindist );
    93125    }
     
    99131void VectorSetTest::minDistSquaredTest()
    100132{
     133  VECTORSET(std::vector) worklist(list);
    101134  {
    102135    Vector center(5.,0.,0.);
    103     double mindist = list.minDistSquared(center);
     136    double mindist = worklist.minDistSquared(center);
    104137    double check = Vector(2., 1., 0.).DistanceSquared(center);
    105138    CPPUNIT_ASSERT_EQUAL( check, mindist );
    106139  }
    107140  {
    108     for (VECTORSET(std::vector)::const_iterator iter = list.begin();
    109         iter != list.end(); ++iter) {
    110       double mindist = list.minDistSquared(*iter);
     141    for (VECTORSET(std::vector)::const_iterator iter = worklist.begin();
     142        iter != worklist.end(); ++iter) {
     143      double mindist = worklist.minDistSquared(*iter);
    111144      CPPUNIT_ASSERT_EQUAL( 0., mindist );
    112145    }
  • LinearAlgebra/src/unittests/VectorSetUnitTest.hpp

    r418b5e rf6ad4d  
    1717#include <cppunit/extensions/HelperMacros.h>
    1818
    19 #include "VectorSet.hpp"
     19#include <vector>
     20
     21#include "Vector.hpp"
    2022
    2123/********************************************** Test classes **************************************/
     
    2426{
    2527    CPPUNIT_TEST_SUITE( VectorSetTest) ;
     28    CPPUNIT_TEST ( copyConstructorTest );
    2629    CPPUNIT_TEST ( translateTest );
     30    CPPUNIT_TEST ( transformTest );
    2731    CPPUNIT_TEST ( minDistanceTest );
    2832    CPPUNIT_TEST ( minDistSquaredTest );
     
    3337    void tearDown();
    3438
     39    void copyConstructorTest();
    3540    void translateTest();
     41    void transformTest();
    3642    void minDistanceTest();
    3743    void minDistSquaredTest();
    3844
    3945private:
    40     VECTORSET(std::vector) list;
     46    std::vector<Vector> list;
    4147};
    4248
Note: See TracChangeset for help on using the changeset viewer.