Re: [IMP-dev] [IMP-commits] r1073 - in trunk/kernel: include pyext test/misc
Other places we call such methods "distance". I'm not sure we are entirely consistent everywhere on having get or not in non-member functions, but we should be. Personally, I prefer not having the "get" when it is not a member (since there is no where to get it from) but could go either way.
Notification of IMP commits wrote: > Author: ben@SALILAB.ORG > Date: 2008-12-22 13:29:36 -0800 (Mon, 22 Dec 2008) > New Revision: 1073 > > Modified: > trunk/kernel/include/VectorD.h > trunk/kernel/pyext/Vector3D.i > trunk/kernel/test/misc/test_vector3d.py > Log: > Patch from Dina, with minor cleanup and additions by me: add methods to > calculate distance and squared distance between two "pointlike" vectors. > > > Modified: trunk/kernel/include/VectorD.h > =================================================================== > --- trunk/kernel/include/VectorD.h 2008-12-22 21:08:32 UTC (rev 1072) > +++ trunk/kernel/include/VectorD.h 2008-12-22 21:29:36 UTC (rev 1073) > @@ -339,7 +339,24 @@ > } > > > +//! compute the squared distance between two vectors > template <unsigned int D> > +Float get_squared_distance(const VectorD<D> &v1, const VectorD<D> &v2) { > + Float d, s = 0; > + for (unsigned int i=0; i< D; ++i) { > + d = v1[i] - v2[i]; > + s += d*d; > + } > + return s; > +} > + > +//! compute the distance between two vectors > +template <unsigned int D> > +Float get_distance(const VectorD<D> &v1, const VectorD<D> &v2) { > + return std::sqrt(get_squared_distance(v1, v2)); > +} > + > +template <unsigned int D> > struct SpacesIO > { > const VectorD<D> &v_; > > Modified: trunk/kernel/pyext/Vector3D.i > =================================================================== > --- trunk/kernel/pyext/Vector3D.i 2008-12-22 21:08:32 UTC (rev 1072) > +++ trunk/kernel/pyext/Vector3D.i 2008-12-22 21:29:36 UTC (rev 1073) > @@ -56,4 +56,6 @@ > %template(random_vector_on_unit_sphere) random_vector_on_unit_sphere<3>; > %template(random_vector_in_unit_sphere) random_vector_in_unit_sphere<3>; > %template(random_vector_in_unit_box) random_vector_in_unit_box<3>; > -} > \ No newline at end of file > + %template(get_distance) get_distance<3>; > + %template(get_squared_distance) get_squared_distance<3>; > +} > > Modified: trunk/kernel/test/misc/test_vector3d.py > =================================================================== > --- trunk/kernel/test/misc/test_vector3d.py 2008-12-22 21:08:32 UTC (rev 1072) > +++ trunk/kernel/test/misc/test_vector3d.py 2008-12-22 21:29:36 UTC (rev 1073) > @@ -100,6 +100,14 @@ > for i in range(3): > self.assertEqual(prod[i], expected_prod[i]) > self.assertEqual(v1[i], expected_prod[i]) > + > + def test_distance(self): > + """Check distance between two vectors""" > + v1 = IMP.Vector3D(3.0, 6.0, 9.0) > + v2 = IMP.Vector3D(1.0, 2.0, 3.0) > + self.assertEqual(IMP.get_squared_distance(v1, v2), 56) > + self.assertInTolerance(IMP.get_distance(v1, v2), 7.4833, 0.01) > + > def test_generators(self): > """Check the Vector3D generators""" > # test calling since it is a bit non-trivial in SWIG > > _______________________________________________ > IMP-commits mailing list > IMP-commits@salilab.org > https://salilab.org/mailman/listinfo/imp-commits >
Daniel Russel wrote: > Other places we call such methods "distance". I'm not sure we are > entirely consistent everywhere on having get or not in non-member > functions, but we should be. Personally, I prefer not having the "get" > when it is not a member (since there is no where to get it from) but > could go either way.
I was just thinking the same thing. I also don't have a strong preference either way, but for now it should at least match the similar function for calculating distance between two XYZDecorators, so I'll change it.
Ben
I think that the distance in XYZDecorator should call the VectorD distance implementation.
On Mon, Dec 22, 2008 at 1:40 PM, Ben Webb ben@salilab.org wrote:
> Daniel Russel wrote: > > Other places we call such methods "distance". I'm not sure we are > > entirely consistent everywhere on having get or not in non-member > > functions, but we should be. Personally, I prefer not having the "get" > > when it is not a member (since there is no where to get it from) but > > could go either way. > > I was just thinking the same thing. I also don't have a strong > preference either way, but for now it should at least match the similar > function for calculating distance between two XYZDecorators, so I'll > change it. > > Ben > -- > ben@salilab.org http://salilab.org/~ben/http://salilab.org/%7Eben/ > "It is a capital mistake to theorize before one has data." > - Sir Arthur Conan Doyle > _______________________________________________ > IMP-dev mailing list > IMP-dev@salilab.org > https://salilab.org/mailman/listinfo/imp-dev >
yes, you are right, it should be without get, I just copied it from the first version, when they were members...
On Mon, Dec 22, 2008 at 1:33 PM, Daniel Russel drussel@gmail.com wrote:
> Other places we call such methods "distance". I'm not sure we are entirely > consistent everywhere on having get or not in non-member functions, but we > should be. Personally, I prefer not having the "get" when it is not a member > (since there is no where to get it from) but could go either way. > > Notification of IMP commits wrote: > >> Author: ben@SALILAB.ORG >> Date: 2008-12-22 13:29:36 -0800 (Mon, 22 Dec 2008) >> New Revision: 1073 >> >> Modified: >> trunk/kernel/include/VectorD.h >> trunk/kernel/pyext/Vector3D.i >> trunk/kernel/test/misc/test_vector3d.py >> Log: >> Patch from Dina, with minor cleanup and additions by me: add methods to >> calculate distance and squared distance between two "pointlike" vectors. >> >> >> Modified: trunk/kernel/include/VectorD.h >> =================================================================== >> --- trunk/kernel/include/VectorD.h 2008-12-22 21:08:32 UTC (rev 1072) >> +++ trunk/kernel/include/VectorD.h 2008-12-22 21:29:36 UTC (rev 1073) >> @@ -339,7 +339,24 @@ >> } >> +//! compute the squared distance between two vectors >> template <unsigned int D> >> +Float get_squared_distance(const VectorD<D> &v1, const VectorD<D> &v2) { >> + Float d, s = 0; >> + for (unsigned int i=0; i< D; ++i) { >> + d = v1[i] - v2[i]; >> + s += d*d; >> + } >> + return s; >> +} >> + >> +//! compute the distance between two vectors >> +template <unsigned int D> >> +Float get_distance(const VectorD<D> &v1, const VectorD<D> &v2) { >> + return std::sqrt(get_squared_distance(v1, v2)); >> +} >> + >> +template <unsigned int D> >> struct SpacesIO >> { >> const VectorD<D> &v_; >> >> Modified: trunk/kernel/pyext/Vector3D.i >> =================================================================== >> --- trunk/kernel/pyext/Vector3D.i 2008-12-22 21:08:32 UTC (rev 1072) >> +++ trunk/kernel/pyext/Vector3D.i 2008-12-22 21:29:36 UTC (rev 1073) >> @@ -56,4 +56,6 @@ >> %template(random_vector_on_unit_sphere) >> random_vector_on_unit_sphere<3>; >> %template(random_vector_in_unit_sphere) >> random_vector_in_unit_sphere<3>; >> %template(random_vector_in_unit_box) random_vector_in_unit_box<3>; >> -} >> \ No newline at end of file >> + %template(get_distance) get_distance<3>; >> + %template(get_squared_distance) get_squared_distance<3>; >> +} >> >> Modified: trunk/kernel/test/misc/test_vector3d.py >> =================================================================== >> --- trunk/kernel/test/misc/test_vector3d.py 2008-12-22 21:08:32 UTC >> (rev 1072) >> +++ trunk/kernel/test/misc/test_vector3d.py 2008-12-22 21:29:36 UTC >> (rev 1073) >> @@ -100,6 +100,14 @@ >> for i in range(3): >> self.assertEqual(prod[i], expected_prod[i]) >> self.assertEqual(v1[i], expected_prod[i]) >> + >> + def test_distance(self): >> + """Check distance between two vectors""" >> + v1 = IMP.Vector3D(3.0, 6.0, 9.0) >> + v2 = IMP.Vector3D(1.0, 2.0, 3.0) >> + self.assertEqual(IMP.get_squared_distance(v1, v2), 56) >> + self.assertInTolerance(IMP.get_distance(v1, v2), 7.4833, 0.01) >> + >> def test_generators(self): >> """Check the Vector3D generators""" >> # test calling since it is a bit non-trivial in SWIG >> >> _______________________________________________ >> IMP-commits mailing list >> IMP-commits@salilab.org >> https://salilab.org/mailman/listinfo/imp-commits >> >> > > _______________________________________________ > IMP-dev mailing list > IMP-dev@salilab.org > https://salilab.org/mailman/listinfo/imp-dev >
participants (3)
-
Ben Webb
-
Daniel Russel
-
Dina Schneidman