Skip to content

Commit f0a8635

Browse files
committed
try fix
1 parent 08699f2 commit f0a8635

7 files changed

Lines changed: 66 additions & 18 deletions

File tree

include/xtensor/core/xstrides.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ namespace xt
171171
It strided_data_end(const C& c, It begin, layout_type l, size_type offset)
172172
{
173173
using difference_type = typename std::iterator_traits<It>::difference_type;
174-
if (c.size() == 0)
174+
if (c.size() == 0 || std::find(c.shape().cbegin(), c.shape().cend(), size_type(0)) != c.shape().cend())
175175
{
176176
return begin;
177177
}

include/xtensor/misc/xfft.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ namespace xt
128128
inline auto fft(E&& e, std::ptrdiff_t axis = -1)
129129
{
130130
using value_type = typename std::decay<E>::type::value_type;
131+
if (e.dimension() == 0)
132+
{
133+
XTENSOR_THROW(std::runtime_error, "Cannot take the FFT of a scalar expression");
134+
}
131135
if constexpr (xtl::is_complex<typename std::decay<E>::type::value_type>::value)
132136
{
133137
using precision = typename value_type::value_type;
@@ -159,6 +163,10 @@ namespace xt
159163
template <class E>
160164
inline auto ifft(E&& e, std::ptrdiff_t axis = -1)
161165
{
166+
if (e.dimension() == 0)
167+
{
168+
XTENSOR_THROW(std::runtime_error, "Cannot take the iFFT of a scalar expression");
169+
}
162170
if constexpr (xtl::is_complex<typename std::decay<E>::type::value_type>::value)
163171
{
164172
// check the length of the data on that axis

test/CMakeLists.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,32 @@ endif()
289289

290290
target_compile_options(test_xtensor_lib PRIVATE $<$<BOOL:USE_SANITIZER>:${SANITIZER_COMPILE_OPTIONS}>)
291291
target_link_options(test_xtensor_lib PRIVATE $<$<BOOL:USE_SANITIZER>:${SANITIZER_LINK_OPTIONS}>)
292+
# if(USE_SANITIZER MATCHES "memory" AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
293+
# target_compile_options(test_xtensor_lib PRIVATE -ftrivial-auto-var-init=zero)
294+
# endif()
295+
# if(USE_SANITIZER MATCHES "memory")
296+
# target_compile_options(test_xtensor_lib PRIVATE -fno-sanitize=memory)
297+
# target_link_options(test_xtensor_lib PRIVATE -fno-sanitize=memory)
298+
# endif()
292299

293300
target_include_directories(test_xtensor_lib PRIVATE ${XTENSOR_INCLUDE_DIR})
294301
target_link_libraries(test_xtensor_lib PRIVATE xtensor doctest::doctest ${CMAKE_THREAD_LIBS_INIT})
295302

296-
add_custom_target(xtest COMMAND test_xtensor_lib DEPENDS test_xtensor_lib)
303+
set(XTENSOR_TEST_ENV)
304+
if(USE_SANITIZER MATCHES "memory")
305+
set(XTENSOR_MSAN_SUPPRESSIONS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/msan_suppressions.txt")
306+
set(XTENSOR_TEST_ENV "MSAN_OPTIONS=suppressions=${XTENSOR_MSAN_SUPPRESSIONS_FILE}")
307+
endif()
308+
309+
add_custom_target(
310+
xtest
311+
COMMAND ${CMAKE_COMMAND} -E env ${XTENSOR_TEST_ENV} $<TARGET_FILE:test_xtensor_lib>
312+
DEPENDS test_xtensor_lib
313+
)
297314
add_test(NAME xtest COMMAND test_xtensor_lib)
315+
if(XTENSOR_TEST_ENV)
316+
set_tests_properties(xtest PROPERTIES ENVIRONMENT "${XTENSOR_TEST_ENV}")
317+
endif()
298318

299319
# Some files will be compiled twice, however compiling common files in a static
300320
# library and linking test_xtensor_lib with it removes half of the tests at

test/msan_suppressions.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# MSan false positive: doctest reporter registration during static init
22
# doctest::String has internal padding that MSan flags as uninitialized
33
# when std::map compares keys during insert.
4-
interceptor_via_fun:doctest::detail::registerReporterImpl
4+
fun:*doctest::detail::registerReporterImpl*
5+
src:*doctest/doctest.h

test/test_xblockwise_reducer.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,24 @@ namespace xt
111111
dynamic_shape<std::size_t> chunk_shape({5, 4, 2});
112112
xarray<int> input_exp(shape);
113113

114-
// just iota is a bit boring since it will
115-
// lead to an uniform variance
116-
std::iota(input_exp.begin(), input_exp.end(), -5);
117-
for (std::size_t i = 0; i < input_exp.size(); ++i)
114+
if (std::is_same<tester_type, prod_tester>::value)
118115
{
119-
if (i % 2)
116+
for (std::size_t i = 0; i < input_exp.size(); ++i)
120117
{
121-
input_exp.flat(i) += 10;
118+
input_exp.flat(i) = (i % 2 == 0) ? 1 : -1;
119+
}
120+
}
121+
else
122+
{
123+
// just iota is a bit boring since it will
124+
// lead to an uniform variance
125+
std::iota(input_exp.begin(), input_exp.end(), -5);
126+
for (std::size_t i = 0; i < input_exp.size(); ++i)
127+
{
128+
if (i % 2)
129+
{
130+
input_exp.flat(i) += 10;
131+
}
122132
}
123133
}
124134

test/test_xfft.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ namespace xt
2727
REQUIRE(A == doctest::Approx(std::abs(res(k))).epsilon(.0001));
2828
}
2929

30+
TEST(xfft, scalar_input_throws)
31+
{
32+
auto scalar = xt::xarray<float>::from_shape({});
33+
scalar() = 1.0f;
34+
35+
XT_EXPECT_THROW(xt::fft::fft(scalar), std::runtime_error);
36+
XT_EXPECT_THROW(xt::fft::ifft(scalar), std::runtime_error);
37+
}
38+
3039
TEST(xfft, convolve_power_2)
3140
{
3241
xt::xarray<float> x = {1.0, 1.0, 1.0, 5.0};

test/test_xmath_result_type.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ namespace xt
115115
TEST(xmath, uchar_result_type)
116116
{
117117
shape_type shape = {3, 2};
118-
xarray<unsigned char> auchar(shape);
118+
auto auchar = xt::zeros<unsigned char>(shape);
119119

120120
CHECK_RESULT_TYPE(auchar + auchar, int);
121121
CHECK_RESULT_TYPE(2 * auchar, int);
@@ -131,7 +131,7 @@ namespace xt
131131
TEST(xmath, short_result_type)
132132
{
133133
shape_type shape = {3, 2};
134-
xarray<short> ashort(shape);
134+
auto ashort = xt::zeros<short>(shape);
135135

136136
CHECK_RESULT_TYPE(ashort + ashort, int);
137137
CHECK_RESULT_TYPE(2 * ashort, int);
@@ -147,7 +147,7 @@ namespace xt
147147
TEST(xmath, ushort_result_type)
148148
{
149149
shape_type shape = {3, 2};
150-
xarray<unsigned short> aushort(shape);
150+
auto aushort = xt::zeros<unsigned short>(shape);
151151

152152
CHECK_RESULT_TYPE(aushort + aushort, int);
153153
CHECK_RESULT_TYPE(2u * aushort, unsigned int);
@@ -163,7 +163,7 @@ namespace xt
163163
TEST(xmath, int_result_type)
164164
{
165165
shape_type shape = {3, 2};
166-
xarray<int> aint(shape);
166+
auto aint = xt::zeros<int>(shape);
167167

168168
CHECK_RESULT_TYPE(aint + aint, int);
169169
CHECK_RESULT_TYPE(2 * aint, int);
@@ -179,7 +179,7 @@ namespace xt
179179
TEST(xmath, uint_result_type)
180180
{
181181
shape_type shape = {3, 2};
182-
xarray<unsigned int> auint(shape);
182+
auto auint = xt::zeros<unsigned int>(shape);
183183

184184
CHECK_RESULT_TYPE(auint + auint, unsigned int);
185185
CHECK_RESULT_TYPE(2u * auint, unsigned int);
@@ -195,7 +195,7 @@ namespace xt
195195
TEST(xmath, long_result_type)
196196
{
197197
shape_type shape = {3, 2};
198-
xarray<long long> along(shape);
198+
auto along = xt::zeros<long long>(shape);
199199

200200
CHECK_RESULT_TYPE(along + along, signed long long);
201201
CHECK_RESULT_TYPE(2 * along, signed long long);
@@ -211,7 +211,7 @@ namespace xt
211211
TEST(xmath, ulong_result_type)
212212
{
213213
shape_type shape = {3, 2};
214-
xarray<unsigned long long> aulong(shape);
214+
auto aulong = xt::zeros<unsigned long long>(shape);
215215

216216
CHECK_RESULT_TYPE(aulong + aulong, unsigned long long);
217217
CHECK_RESULT_TYPE(2ul * aulong, unsigned long long);
@@ -227,7 +227,7 @@ namespace xt
227227
TEST(xmath, float_result_type)
228228
{
229229
shape_type shape = {3, 2};
230-
xarray<float> afloat(shape);
230+
auto afloat = xt::zeros<float>(shape);
231231

232232
CHECK_RESULT_TYPE(afloat + afloat, float);
233233
CHECK_RESULT_TYPE(2.0f * afloat, float);
@@ -243,7 +243,7 @@ namespace xt
243243
TEST(xmath, double_result_type)
244244
{
245245
shape_type shape = {3, 2};
246-
xarray<double> adouble(shape);
246+
auto adouble = xt::zeros<double>(shape);
247247

248248
CHECK_RESULT_TYPE(adouble + adouble, double);
249249
CHECK_RESULT_TYPE(2.0 * adouble, double);

0 commit comments

Comments
 (0)