GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #202 from zhujun98/fix_pytensor_overload_resolution · willp552/xtensor-python@719b9d1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • include/xtensor-python
    • pytensor.hpp
  • test_python
    • main.cpp
    • test_pyarray.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎include/xtensor-python/pytensor.hpp‎

Copy file name to clipboardExpand all lines: include/xtensor-python/pytensor.hpp
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ namespace pybind11
5959
}
6060
}
6161

62-
value = type::ensure(src);
62+
try
63+
{
64+
value = type::ensure(src);
65+
}
66+
catch (const std::runtime_error&)
67+
{
68+
return false;
69+
}
6370
return static_cast<bool>(value);
6471
}
6572

Collapse file

‎test_python/main.cpp‎

Copy file name to clipboardExpand all lines: test_python/main.cpp
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,7 @@ PYBIND11_MODULE(xtensor_python_test, m)
254254

255255
m.def("simple_array", [](xt::pyarray<int>) { return 1; } );
256256
m.def("simple_tensor", [](xt::pytensor<int, 1>) { return 2; } );
257+
258+
m.def("diff_shape_overload", [](xt::pytensor<int, 1> a) { return 1; });
259+
m.def("diff_shape_overload", [](xt::pytensor<int, 2> a) { return 2; });
257260
}
Collapse file

‎test_python/test_pyarray.py‎

Copy file name to clipboardExpand all lines: test_python/test_pyarray.py
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ def test_col_row_major(self):
136136
with self.assertRaises(RuntimeError):
137137
xt.col_major_array(var)
138138

139-
with self.assertRaises(RuntimeError):
139+
with self.assertRaises(TypeError):
140140
xt.row_major_tensor(var.T)
141141

142-
with self.assertRaises(RuntimeError):
142+
with self.assertRaises(TypeError):
143143
xt.row_major_tensor(var[:, ::2, ::2])
144144

145-
with self.assertRaises(RuntimeError):
145+
with self.assertRaises(TypeError):
146146
# raise for wrong dimension
147147
xt.row_major_tensor(var[0, 0, :])
148148

@@ -158,6 +158,15 @@ def test_bad_argument_call(self):
158158
with self.assertRaises(TypeError):
159159
xt.simple_tensor("foo")
160160

161+
def test_diff_shape_overload(self):
162+
self.assertEqual(1, xt.diff_shape_overload(np.ones(2)))
163+
self.assertEqual(2, xt.diff_shape_overload(np.ones((2, 2))))
164+
165+
with self.assertRaises(TypeError):
166+
# FIXME: the TypeError information is not informative
167+
xt.diff_shape_overload(np.ones((2, 2, 2)))
168+
169+
161170
class AttributeTest(TestCase):
162171

163172
def setUp(self):

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.