Skip to content

Commit 711847e

Browse files
committed
Copying from prework_no_rst branch (PR pybind#3087): test_numpy_array.cpp, test_stl.cpp
1 parent 0f4761b commit 711847e

File tree

2 files changed

+51
-87
lines changed

2 files changed

+51
-87
lines changed

tests/test_numpy_array.cpp

Lines changed: 45 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ TEST_SUBMODULE(numpy_array, sm) {
226226
return py::isinstance<py::array>(std::move(yes))
227227
&& !py::isinstance<py::array>(std::move(no));
228228
});
229-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
230-
sm.def("isinstance_typed", [](py::object o) {
229+
sm.def("isinstance_typed", [](const py::object &o) {
231230
return py::isinstance<py::array_t<double>>(o) && !py::isinstance<py::array_t<int>>(o);
232231
});
233232

@@ -248,60 +247,47 @@ TEST_SUBMODULE(numpy_array, sm) {
248247
});
249248

250249
// test_overload_resolution
251-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
252-
sm.def("overloaded", [](py::array_t<double>) { return "double"; });
253-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
254-
sm.def("overloaded", [](py::array_t<float>) { return "float"; });
255-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
256-
sm.def("overloaded", [](py::array_t<int>) { return "int"; });
257-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
258-
sm.def("overloaded", [](py::array_t<unsigned short>) { return "unsigned short"; });
259-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
260-
sm.def("overloaded", [](py::array_t<long long>) { return "long long"; });
261-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
262-
sm.def("overloaded", [](py::array_t<std::complex<double>>) { return "double complex"; });
263-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
264-
sm.def("overloaded", [](py::array_t<std::complex<float>>) { return "float complex"; });
265-
266-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
267-
sm.def("overloaded2", [](py::array_t<std::complex<double>>) { return "double complex"; });
268-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
269-
sm.def("overloaded2", [](py::array_t<double>) { return "double"; });
270-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
271-
sm.def("overloaded2", [](py::array_t<std::complex<float>>) { return "float complex"; });
272-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
273-
sm.def("overloaded2", [](py::array_t<float>) { return "float"; });
250+
sm.def("overloaded", [](const py::array_t<double> &) { return "double"; });
251+
sm.def("overloaded", [](const py::array_t<float> &) { return "float"; });
252+
sm.def("overloaded", [](const py::array_t<int> &) { return "int"; });
253+
sm.def("overloaded", [](const py::array_t<unsigned short> &) { return "unsigned short"; });
254+
sm.def("overloaded", [](const py::array_t<long long> &) { return "long long"; });
255+
sm.def("overloaded",
256+
[](const py::array_t<std::complex<double>> &) { return "double complex"; });
257+
sm.def("overloaded", [](const py::array_t<std::complex<float>> &) { return "float complex"; });
258+
259+
sm.def("overloaded2",
260+
[](const py::array_t<std::complex<double>> &) { return "double complex"; });
261+
sm.def("overloaded2", [](const py::array_t<double> &) { return "double"; });
262+
sm.def("overloaded2",
263+
[](const py::array_t<std::complex<float>> &) { return "float complex"; });
264+
sm.def("overloaded2", [](const py::array_t<float> &) { return "float"; });
274265

275266
// [workaround(intel)] ICC 20/21 breaks with py::arg().stuff, using py::arg{}.stuff works.
276267

277268
// Only accept the exact types:
278-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
279-
sm.def("overloaded3", [](py::array_t<int>) { return "int"; }, py::arg{}.noconvert());
280-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
281-
sm.def("overloaded3", [](py::array_t<double>) { return "double"; }, py::arg{}.noconvert());
269+
sm.def(
270+
"overloaded3", [](const py::array_t<int> &) { return "int"; }, py::arg{}.noconvert());
271+
sm.def(
272+
"overloaded3",
273+
[](const py::array_t<double> &) { return "double"; },
274+
py::arg{}.noconvert());
282275

283276
// Make sure we don't do unsafe coercion (e.g. float to int) when not using forcecast, but
284277
// rather that float gets converted via the safe (conversion to double) overload:
285-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
286-
sm.def("overloaded4", [](py::array_t<long long, 0>) { return "long long"; });
287-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
288-
sm.def("overloaded4", [](py::array_t<double, 0>) { return "double"; });
278+
sm.def("overloaded4", [](const py::array_t<long long, 0> &) { return "long long"; });
279+
sm.def("overloaded4", [](const py::array_t<double, 0> &) { return "double"; });
289280

290281
// But we do allow conversion to int if forcecast is enabled (but only if no overload matches
291282
// without conversion)
292-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
293-
sm.def("overloaded5", [](py::array_t<unsigned int>) { return "unsigned int"; });
294-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
295-
sm.def("overloaded5", [](py::array_t<double>) { return "double"; });
283+
sm.def("overloaded5", [](const py::array_t<unsigned int> &) { return "unsigned int"; });
284+
sm.def("overloaded5", [](const py::array_t<double> &) { return "double"; });
296285

297286
// test_greedy_string_overload
298287
// Issue 685: ndarray shouldn't go to std::string overload
299-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
300-
sm.def("issue685", [](std::string) { return "string"; });
301-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
302-
sm.def("issue685", [](py::array) { return "array"; });
303-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
304-
sm.def("issue685", [](py::object) { return "other"; });
288+
sm.def("issue685", [](const std::string &) { return "string"; });
289+
sm.def("issue685", [](const py::array &) { return "array"; });
290+
sm.def("issue685", [](const py::object &) { return "other"; });
305291

306292
// test_array_unchecked_fixed_dims
307293
sm.def("proxy_add2", [](py::array_t<double> a, double v) {
@@ -424,73 +410,53 @@ TEST_SUBMODULE(numpy_array, sm) {
424410

425411
// test_argument_conversions
426412
sm.def(
427-
"accept_double",
428-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
429-
[](py::array_t<double, 0>) {},
430-
py::arg("a"));
413+
"accept_double", [](const py::array_t<double, 0> &) {}, py::arg("a"));
431414
sm.def(
432415
"accept_double_forcecast",
433-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
434-
[](py::array_t<double, py::array::forcecast>) {},
416+
[](const py::array_t<double, py::array::forcecast> &) {},
435417
py::arg("a"));
436418
sm.def(
437419
"accept_double_c_style",
438-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
439-
[](py::array_t<double, py::array::c_style>) {},
420+
[](const py::array_t<double, py::array::c_style> &) {},
440421
py::arg("a"));
441422
sm.def(
442423
"accept_double_c_style_forcecast",
443-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
444-
[](py::array_t<double, py::array::forcecast | py::array::c_style>) {},
424+
[](const py::array_t<double, py::array::forcecast | py::array::c_style> &) {},
445425
py::arg("a"));
446426
sm.def(
447427
"accept_double_f_style",
448-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
449-
[](py::array_t<double, py::array::f_style>) {},
428+
[](const py::array_t<double, py::array::f_style> &) {},
450429
py::arg("a"));
451430
sm.def(
452431
"accept_double_f_style_forcecast",
453-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
454-
[](py::array_t<double, py::array::forcecast | py::array::f_style>) {},
432+
[](const py::array_t<double, py::array::forcecast | py::array::f_style> &) {},
455433
py::arg("a"));
456434
sm.def(
457-
"accept_double_noconvert",
458-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
459-
[](py::array_t<double, 0>) {},
460-
"a"_a.noconvert());
435+
"accept_double_noconvert", [](const py::array_t<double, 0> &) {}, "a"_a.noconvert());
461436
sm.def(
462437
"accept_double_forcecast_noconvert",
463-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
464-
[](py::array_t<double, py::array::forcecast>) {},
438+
[](const py::array_t<double, py::array::forcecast> &) {},
465439
"a"_a.noconvert());
466440
sm.def(
467441
"accept_double_c_style_noconvert",
468-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
469-
[](py::array_t<double, py::array::c_style>) {},
442+
[](const py::array_t<double, py::array::c_style> &) {},
470443
"a"_a.noconvert());
471444
sm.def(
472445
"accept_double_c_style_forcecast_noconvert",
473-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
474-
[](py::array_t<double, py::array::forcecast | py::array::c_style>) {},
446+
[](const py::array_t<double, py::array::forcecast | py::array::c_style> &) {},
475447
"a"_a.noconvert());
476448
sm.def(
477449
"accept_double_f_style_noconvert",
478-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
479-
[](py::array_t<double, py::array::f_style>) {},
450+
[](const py::array_t<double, py::array::f_style> &) {},
480451
"a"_a.noconvert());
481452
sm.def(
482453
"accept_double_f_style_forcecast_noconvert",
483-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
484-
[](py::array_t<double, py::array::forcecast | py::array::f_style>) {},
454+
[](const py::array_t<double, py::array::forcecast | py::array::f_style> &) {},
485455
"a"_a.noconvert());
486456

487457
// Check that types returns correct npy format descriptor
488-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
489-
sm.def("test_fmt_desc_float", [](py::array_t<float>) {});
490-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
491-
sm.def("test_fmt_desc_double", [](py::array_t<double>) {});
492-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
493-
sm.def("test_fmt_desc_const_float", [](py::array_t<const float>) {});
494-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
495-
sm.def("test_fmt_desc_const_double", [](py::array_t<const double>) {});
458+
sm.def("test_fmt_desc_float", [](const py::array_t<float> &) {});
459+
sm.def("test_fmt_desc_double", [](const py::array_t<double> &) {});
460+
sm.def("test_fmt_desc_const_float", [](const py::array_t<const float> &) {});
461+
sm.def("test_fmt_desc_const_double", [](const py::array_t<const double> &) {});
496462
}

tests/test_stl.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ TEST_SUBMODULE(stl, m) {
207207
}, py::arg_v("x", std::nullopt, "None"));
208208

209209
m.def("nodefer_none_optional", [](std::optional<int>) { return true; });
210-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
211-
m.def("nodefer_none_optional", [](py::none) { return false; });
210+
m.def("nodefer_none_optional", [](const py::none &) { return false; });
212211

213212
using opt_holder = OptionalHolder<std::optional, MoveOutDetector>;
214213
py::class_<opt_holder>(m, "OptionalHolder", "Class with optional member")
@@ -299,12 +298,11 @@ TEST_SUBMODULE(stl, m) {
299298
m.def("stl_pass_by_pointer", [](std::vector<int>* v) { return *v; }, "v"_a=nullptr);
300299

301300
// #1258: pybind11/stl.h converts string to vector<string>
302-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
303-
m.def("func_with_string_or_vector_string_arg_overload", [](std::vector<std::string>) { return 1; });
304-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
305-
m.def("func_with_string_or_vector_string_arg_overload", [](std::list<std::string>) { return 2; });
306-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
307-
m.def("func_with_string_or_vector_string_arg_overload", [](std::string) { return 3; });
301+
m.def("func_with_string_or_vector_string_arg_overload",
302+
[](const std::vector<std::string> &) { return 1; });
303+
m.def("func_with_string_or_vector_string_arg_overload",
304+
[](const std::list<std::string> &) { return 2; });
305+
m.def("func_with_string_or_vector_string_arg_overload", [](const std::string &) { return 3; });
308306

309307
class Placeholder {
310308
public:

0 commit comments

Comments
 (0)