Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

square norm in pointvector #1365

Merged
merged 7 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,19 @@
- *DEC*
- Adding missing headers in some files of DEC.
(Roland Denis, [#1349](https://github.com/DGtal-team/DGtal/pull/1349))

- *Math*
- Fix possible division by zero in the MultiStatistics class.
(Kacper Pluta, [#1358](https://github.com/DGtal-team/DGtal/pull/1358))
- Fix possible division by zero in the MultiStatistics class.
(Kacper Pluta, [#1358](https://github.com/DGtal-team/DGtal/pull/1358))

- *Image*
- Fix bug in ImageLinearCellEmbedder.
(Jacques-Olivier Lachaud, [#1356](https://github.com/DGtal-team/DGtal/pull/1356))

- *Kernel*
- Adding square norm method to Point/Vector class. (David Coeurjolly,
[#1365](https://github.com/DGtal-team/DGtal/pull/1365))

# DGtal 0.9.4.1

## Bug Fixes
Expand Down
11 changes: 11 additions & 0 deletions src/DGtal/kernel/PointVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,17 @@ namespace DGtal
*/
double norm( const NormType type = L_2 ) const;

/**
* Computes the square L2 norm of a point/vector.
* \warning This method performs a conversion
* from the type T to double for each components to compute the
* norms.
*
* @return the square norm of the point/vector as a double.
*/
double sqnorm( ) const;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for choosing the name "sqnorm" instead of "squaredNorm" or "squaredL2Norm" ? Because it is not our usual naming conventions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've seen this name in previous lib.. But I can switch to squaredNorm is you want

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

squaredNorm is more homogeneous with DGtal code, but has the disadvantage to be longer (sometimes a problem for reading the code)... I let you decide.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's go with squaredNorm



/**
* Computes the 1-norm of a vector.
*
Expand Down
16 changes: 16 additions & 0 deletions src/DGtal/kernel/PointVector.ih
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,22 @@ negate()
template<DGtal::Dimension dim, typename TComponent, typename TContainer>
inline
double
DGtal::PointVector<dim, TComponent, TContainer>::sqnorm () const
{
double tmp = 0.0;
ASSERT ( dim > 0 );
double v;
for ( DGtal::Dimension i = 0; i < dimension; i++ )
{
v =NumberTraits<Component>::castToDouble(myArray[ i ]);
tmp += v*v;
rolanddenis marked this conversation as resolved.
Show resolved Hide resolved
}
return tmp;
}
//------------------------------------------------------------------------------
template<DGtal::Dimension dim, typename TComponent, typename TContainer>
inline
double
DGtal::PointVector<dim, TComponent, TContainer>::norm (const
typename Self::NormType aType ) const
{
Expand Down
1 change: 1 addition & 0 deletions tests/kernel/testPointVector-catch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ TEST_CASE( "Point Vector Unit tests" )
CAPTURE( normalized );
REQUIRE( aPoint.norm ( Point::L_1 ) == 6 );
REQUIRE( aPoint.norm ( Point::L_infty ) == 3 );
REQUIRE( aPoint.sqnorm() == Approx(aPoint.norm()*aPoint.norm()) );
REQUIRE( normalized[0] == Approx( 0.801784) );
REQUIRE( normalized[1] == Approx( -0.267261) );
REQUIRE( normalized[2] == Approx( 0.534522) );
Expand Down