Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 additions & 0 deletions src/Picasso_BatchedLinearAlgebra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#ifndef PICASSO_BATCHEDLINEARALGEBRA_HPP
#define PICASSO_BATCHEDLINEARALGEBRA_HPP

#include <cassert>

#include <Kokkos_Core.hpp>

#include <functional>
Expand Down Expand Up @@ -1604,6 +1606,8 @@ struct Vector
#pragma unroll
#endif
auto norm2 = Kokkos::sqrt( ~( *this ) * ( *this ) );
assert( norm2 != 0.0 );

for ( int i = 0; i < N; ++i )
( *this )( i ) /= norm2;
return *this;
Expand Down Expand Up @@ -1735,6 +1739,16 @@ struct Vector<T, 1>
return *this;
}

// Normalization
KOKKOS_INLINE_FUNCTION
Vector& normalize()
{
assert( ( *this )( 0 ) != 0.0 );

( *this )( 0 ) = ( *this )( 0 ) > 0 ? 1.0 : -1.0;
return *this;
}

// Strides.
KOKKOS_INLINE_FUNCTION
int stride_0() const { return 1; }
Expand Down Expand Up @@ -1898,6 +1912,8 @@ struct VectorView
#pragma unroll
#endif
auto norm2 = Kokkos::sqrt( ~( *this ) * ( *this ) );
assert( norm2 != 0.0 );

for ( int i = 0; i < N; ++i )
( *this )( i ) /= norm2;
return *this;
Expand Down
5 changes: 5 additions & 0 deletions unit_test/tstBatchedLinearAlgebra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,11 @@ void vectorTest()
for ( int i = 0; i < 3; ++i )
EXPECT_DOUBLE_EQ( w( i ), 32.3 );

// Size 1 vector test
LinearAlgebra::Vector<double, 1> vec1 = { 4.7 };
vec1.normalize();
EXPECT_DOUBLE_EQ( vec1, 1.0 );

// Size 1 vector test.
// FIXME: construction of length 1 vector fails with NVCC.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this test pass? We commented this out below because of issues with cuda

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it passed on V100

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the commented code below pass?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh maybe it's trying to construct from a scalar that fails

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, commented code also get passed on V100

/*
Expand Down