-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from wolfv/fix_qr_lstsq
fixes for lstsq and qr + more and generated tests
- Loading branch information
Showing
8 changed files
with
1,069 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/*************************************************************************** | ||
* Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht * | ||
* * | ||
* Distributed under the terms of the BSD 3-Clause License. * | ||
* * | ||
* The full license is in the file LICENSE, distributed with this software. * | ||
****************************************************************************/ | ||
|
||
#include <algorithm> | ||
|
||
#include "gtest/gtest.h" | ||
#include "xtensor/xarray.hpp" | ||
#include "xtensor/xfixed.hpp" | ||
#include "xtensor/xnoalias.hpp" | ||
#include "xtensor/xstrided_view.hpp" | ||
#include "xtensor/xtensor.hpp" | ||
#include "xtensor/xview.hpp" | ||
|
||
#include "xtensor-blas/xlinalg.hpp" | ||
|
||
namespace xt | ||
{ | ||
using namespace xt::placeholders; | ||
|
||
/*py | ||
a = np.random.random((6, 3)) | ||
b = np.ones((6)) | ||
*/ | ||
TEST(xtest_extended, lstsq1) | ||
{ | ||
// py_a | ||
// py_b | ||
// py_res0 = np.linalg.lstsq(a, b)[0] | ||
// py_res1 = np.linalg.lstsq(a, b)[1] | ||
// py_res2 = np.linalg.lstsq(a, b)[2] | ||
// py_res3 = np.linalg.lstsq(a, b)[3] | ||
|
||
auto xres = xt::linalg::lstsq(py_a, py_b); | ||
EXPECT_TRUE(xt::allclose(std::get<0>(xres), py_res0)); | ||
EXPECT_TRUE(xt::allclose(std::get<1>(xres), py_res1)); | ||
EXPECT_EQ(std::get<2>(xres), py_res2); | ||
EXPECT_TRUE(xt::allclose(std::get<3>(xres), py_res3)); | ||
} | ||
|
||
/*py | ||
a = np.random.random((3, 3)) | ||
b = np.ones((3)) | ||
*/ | ||
TEST(xtest_extended, lstsq20) | ||
{ | ||
// py_a | ||
// py_b | ||
// py_res0 = np.linalg.lstsq(a, b)[0] | ||
// py_res1 = np.linalg.lstsq(a, b)[1] | ||
// py_res2 = np.linalg.lstsq(a, b)[2] | ||
// py_res3 = np.linalg.lstsq(a, b)[3] | ||
|
||
auto xres = xt::linalg::lstsq(py_a, py_b); | ||
|
||
EXPECT_TRUE(xt::allclose(std::get<0>(xres), py_res0)); | ||
EXPECT_TRUE(xt::allclose(std::get<1>(xres), py_res1)); | ||
EXPECT_EQ(std::get<2>(xres), py_res2); | ||
EXPECT_TRUE(xt::allclose(std::get<3>(xres), py_res3)); | ||
} | ||
|
||
/*py | ||
a = np.random.random((3, 3)) | ||
b = np.ones((3, 3)) | ||
*/ | ||
TEST(xtest_extended, lstsq21) | ||
{ | ||
// py_a | ||
// py_b | ||
// py_res0 = np.linalg.lstsq(a, b)[0] | ||
// py_res1 = np.linalg.lstsq(a, b)[1] | ||
// py_res2 = np.linalg.lstsq(a, b)[2] | ||
// py_res3 = np.linalg.lstsq(a, b)[3] | ||
|
||
auto xres = xt::linalg::lstsq(py_a, py_b); | ||
|
||
EXPECT_TRUE(xt::allclose(std::get<0>(xres), py_res0)); | ||
EXPECT_TRUE(xt::allclose(std::get<1>(xres), py_res1)); | ||
EXPECT_EQ(std::get<2>(xres), py_res2); | ||
EXPECT_TRUE(xt::allclose(std::get<3>(xres), py_res3)); | ||
} | ||
|
||
/*py | ||
a = np.random.random((2, 5)) | ||
b = np.ones((2)) | ||
*/ | ||
TEST(xtest_extended, lstsq3) | ||
{ | ||
// py_a | ||
// py_b | ||
// py_res0 = np.linalg.lstsq(a, b)[0] | ||
// py_res1 = np.linalg.lstsq(a, b)[1] | ||
// py_res2 = np.linalg.lstsq(a, b)[2] | ||
// py_res3 = np.linalg.lstsq(a, b)[3] | ||
|
||
auto xres = xt::linalg::lstsq(py_a, py_b); | ||
EXPECT_TRUE(xt::allclose(std::get<0>(xres), py_res0)); | ||
EXPECT_TRUE(xt::allclose(std::get<1>(xres), py_res1)); | ||
EXPECT_EQ(std::get<2>(xres), py_res2); | ||
EXPECT_TRUE(xt::allclose(std::get<3>(xres), py_res3)); | ||
} | ||
|
||
/*py | ||
a = np.random.random((2, 5)) | ||
b = np.ones((2, 10)) | ||
*/ | ||
TEST(xtest_extended, lstsq4) | ||
{ | ||
// py_a | ||
// py_b | ||
// py_res0 = np.linalg.lstsq(a, b)[0] | ||
// py_res1 = np.linalg.lstsq(a, b)[1] | ||
// py_res2 = np.linalg.lstsq(a, b)[2] | ||
// py_res3 = np.linalg.lstsq(a, b)[3] | ||
|
||
auto xres = xt::linalg::lstsq(py_a, py_b); | ||
EXPECT_TRUE(xt::allclose(std::get<0>(xres), py_res0)); | ||
EXPECT_TRUE(xt::allclose(std::get<1>(xres), py_res1)); | ||
EXPECT_EQ(std::get<2>(xres), py_res2); | ||
EXPECT_TRUE(xt::allclose(std::get<3>(xres), py_res3)); | ||
} | ||
|
||
/*py | ||
a = np.random.random((10, 5)) | ||
b = np.ones((10, 20)) | ||
*/ | ||
TEST(xtest_extended, lstsq5) | ||
{ | ||
// py_a | ||
// py_b | ||
// py_res0 = np.linalg.lstsq(a, b)[0] | ||
// py_res1 = np.linalg.lstsq(a, b)[1] | ||
// py_res2 = np.linalg.lstsq(a, b)[2] | ||
// py_res3 = np.linalg.lstsq(a, b)[3] | ||
|
||
auto xres = xt::linalg::lstsq(py_a, py_b); | ||
EXPECT_TRUE(xt::allclose(std::get<0>(xres), py_res0)); | ||
EXPECT_TRUE(xt::allclose(std::get<1>(xres), py_res1)); | ||
EXPECT_EQ(std::get<2>(xres), py_res2); | ||
EXPECT_TRUE(xt::allclose(std::get<3>(xres), py_res3)); | ||
} | ||
|
||
/*py | ||
a = np.array([[0., 1.]]) | ||
b = np.array([1.]) | ||
*/ | ||
TEST(xtest_extended, lstsq6) | ||
{ | ||
// py_a | ||
// py_b | ||
// py_res0 = np.linalg.lstsq(a, b)[0] | ||
// py_res1 = np.linalg.lstsq(a, b)[1] | ||
// py_res2 = np.linalg.lstsq(a, b)[2] | ||
// py_res3 = np.linalg.lstsq(a, b)[3] | ||
|
||
auto xres = xt::linalg::lstsq(py_a, py_b); | ||
EXPECT_TRUE(xt::allclose(std::get<0>(xres), py_res0)); | ||
EXPECT_TRUE(xt::allclose(std::get<1>(xres), py_res1)); | ||
EXPECT_EQ(std::get<2>(xres), py_res2); | ||
EXPECT_TRUE(xt::allclose(std::get<3>(xres), py_res3)); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.