运行Ctest时:“ ValueError:具有多个元素的数组的真值不明确。请使用a.any()或a.all()”

时间:2019-02-21 17:07:57

标签: python c++ ctest

我正在尝试安装BoostNumpy库[1],它将带我到ctest执行的 ./ configure make test 。在终端中弹出以下错误消息:

Test project /home/miquel/Desktop/Uni/KaluzaKleinDM/BoostNumpy-master/build
Start 1: dtype_test
1/4 Test #1: dtype_test .......................   Passed    0.13 sec
Start 2: ndarray_test
2/4 Test #2: ndarray_test .....................   Passed    0.10 sec
Start 3: indexing_test
3/4 Test #3: indexing_test ....................   Passed    0.07 sec
Start 4: dstream_test
4/4 Test #4: dstream_test .....................***Failed  Error regular            expression found in output. Regex=[ERROR\:]  0.19 sec

75% tests passed, 1 tests failed out of 4

Total Test time (real) =   0.49 sec

The following tests FAILED:
  4 - dstream_test (Failed)
Errors while running CTest
Makefile:85: recipe for target 'test' failed
make: *** [test] Error 8

显然,第四项测试存在问题。按照[2]中的建议,我在终端中使用了(ctest -r dstream_test -VV)来完整显示错误。以下消息会弹出几次:

ERROR: test_binary_functions (__main__.TestDstream)
4: ----------------------------------------------------------------------
4: Traceback (most recent call last):
4:   File "/home/miquel/Desktop/Uni/KaluzaKleinDM/BoostNumpy-master/test/dstream_test.py", line 90, in test_binary_functions
4:     dstream_test_module.binary_to_T_mult__double(a1, a2, out=o)
4: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

dstream_test.py是一个python文件。我已经看过了,上面满是这样的线条(在这里,我特别显示了88、89、90和91行):

88        # Test the out keyword argument.
89        o = np.empty((self.N,), dtype=np.float64)
90        dstream_test_module.binary_to_T_mult__double(a1, a2, out=o)
91        self.assertTrue((o == r).all())

我不能把头缠住它。这段代码不是我的,但是您可以在[1]中找到它,这让我想知道应该修改什么。第90行在程序内部的(dstream_test_module)模块中调用一个函数。模块文件是dstream_test_module.cpp,它是一个C ++文件。我不熟悉C ++,但是在文件中我找到了调用例程(第90行中的函数):

// Binary non-void-return functions.
ds::def("binary_to_T_mult__double", &test::binary_to_T_mult<double>, (bp::args("v1"),"v2"));
ds::def("binary_to_T_mult__explmapping__double", &test::binary_to_T_mult<double>, (bp::args("v1"),"v2")
    , ((ds::scalar(), ds::scalar()) >> ds::scalar()));
ds::def("binary_to_T_mult__allow_threads__double", &test::binary_to_T_mult<double>, (bp::args("v1"),"v2")
    , ds::allow_threads());
ds::def("binary_to_T_mult__min_thread_size__double", &test::binary_to_T_mult<double>, (bp::args("v1"),"v2")
    , ds::min_thread_size<32>());
ds::def("binary_to_vectorT__tuple__double", &test::binary_to_vectorT<double>, (bp::args("v1"),"v2")
    , ((ds::scalar(), ds::scalar()) >> (ds::scalar(), ds::scalar())));
ds::def("binary_to_vectorT__array__double", &test::binary_to_vectorT<double>, (bp::args("v1"),"v2")
    , ((ds::scalar(), ds::scalar()) >> ds::array<2>()));

在这里,我们看不到 out = o 参数被采用。实际上,如果我删除了 out = o 参数,错误消息就会消失,但这绝不能成为解决方案,因为这样我们就可以跳过测试。所有其他错误消息都遵循类似的模式。有人知道该怎么做吗?

[1] [https://github.com/martwo/BoostNumpy] [2] [How to find where the error is while running ctest

0 个答案:

没有答案