Skip to content

Commit b97a4b1

Browse files
Merge pull request xtensor-stack#79 from JohanMabille/tensor_fix
extended copy constructor tests
2 parents f1a5d17 + db9e3c7 commit b97a4b1

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

test/test_pyarray.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "gtest/gtest.h"
1010
#include "test_common.hpp"
1111
#include "xtensor-python/pyarray.hpp"
12+
#include "xtensor/xarray.hpp"
1213

1314
namespace xt
1415
{
@@ -140,6 +141,17 @@ namespace xt
140141
}
141142
}
142143

144+
TEST(pyarray, extended_constructor)
145+
{
146+
xt::xarray<int> a1 = { { 1, 2 },{ 3, 4 } };
147+
xt::xarray<int> a2 = { { 1, 2 },{ 3, 4 } };
148+
pyarray<int> c = a1 + a2;
149+
EXPECT_EQ(c(0, 0), a1(0, 0) + a2(0, 0));
150+
EXPECT_EQ(c(0, 1), a1(0, 1) + a2(0, 1));
151+
EXPECT_EQ(c(1, 0), a1(1, 0) + a2(1, 0));
152+
EXPECT_EQ(c(1, 1), a1(1, 1) + a2(1, 1));
153+
}
154+
143155
TEST(pyarray, reshape)
144156
{
145157
pyarray<int> a;

test/test_pytensor.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "gtest/gtest.h"
1010
#include "test_common.hpp"
1111
#include "xtensor-python/pytensor.hpp"
12+
#include "xtensor/xtensor.hpp"
1213

1314
namespace xt
1415
{
@@ -139,6 +140,17 @@ namespace xt
139140
}
140141
}
141142

143+
TEST(pytensor, extended_constructor)
144+
{
145+
xt::xtensor<int, 2> a1 = { {1, 2}, {3, 4} };
146+
xt::xtensor<int, 2> a2 = { {1, 2}, {3, 4} };
147+
pytensor<int, 2> c = a1 + a2;
148+
EXPECT_EQ(c(0, 0), a1(0, 0) + a2(0, 0));
149+
EXPECT_EQ(c(0, 1), a1(0, 1) + a2(0, 1));
150+
EXPECT_EQ(c(1, 0), a1(1, 0) + a2(1, 0));
151+
EXPECT_EQ(c(1, 1), a1(1, 1) + a2(1, 1));
152+
}
153+
142154
TEST(pytensor, reshape)
143155
{
144156
pytensor<int, 3> a;
@@ -180,4 +192,5 @@ namespace xt
180192
pytensor<int, 3> a;
181193
EXPECT_EQ(0, a());
182194
}
195+
183196
}

0 commit comments

Comments
 (0)