Skip to content

Commit

Permalink
Merge pull request #129 from wolfv/fix_norm_type
Browse files Browse the repository at this point in the history
Fix norm type
  • Loading branch information
wolfv committed Jul 28, 2019
2 parents a743e89 + ee08bc4 commit a57164e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/xtensor-blas/xlinalg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ namespace linalg
{
if (ord == normorder::frob)
{
return std::sqrt(sum(pow(abs(v), 2))());
return static_cast<value_type>(std::sqrt(sum(pow(abs(v), 2))()));
}
if (ord == normorder::nuc)
{
Expand Down
12 changes: 12 additions & 0 deletions test/test_blas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ namespace xt
EXPECT_NEAR(res, 7.5498344352707498, 1e-6);
}

TEST(xblas, normFloat)
{
auto a = linalg::norm(xt::arange<float>(15), 1);
auto b = linalg::norm(xt::arange<float>(15), 2);
xarray<float> c = {6, 4, 2, 1};
auto res = linalg::norm(c);

EXPECT_EQ(a, 105.0);
EXPECT_NEAR(b, 31.859064644147981, 1e-6);
EXPECT_NEAR(res, 7.5498344352707498, 1e-6);
}

TEST(xblas, outer)
{
xarray<double> a = {1, 1, 1};
Expand Down

0 comments on commit a57164e

Please sign in to comment.