Skip to content

Commit

Permalink
Merge pull request #2642 from tdegeus/style
Browse files Browse the repository at this point in the history
Manule style fixes
  • Loading branch information
JohanMabille authored Jan 17, 2023
2 parents a5cd738 + 87020f9 commit 284d536
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand Down Expand Up @@ -31,7 +31,7 @@ repos:
hooks:
- id: cpp_comment_format
- repo: https://github.com/tdegeus/conda_envfile
rev: v0.4.1
rev: v0.4.2
hooks:
- id: conda_envfile_parse
files: environment.yaml
Expand Down
10 changes: 8 additions & 2 deletions benchmark/benchmark_view_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,16 @@ namespace xt
{
dofval.fill(0.0);
for (size_t e = 0; e < M_NELEM; ++e)
{
for (size_t m = 0; m < M_NNE; ++m)
{
for (size_t i = 0; i < M_NDIM; ++i)
dofval.unchecked(m_dofs.unchecked(m_conn.unchecked(e, m), i)
) += elemvec.unchecked(e, m, i);
{
auto d = m_dofs.unchecked(m_conn.unchecked(e, m), i);
dofval.unchecked(d) += elemvec.unchecked(e, m, i);
}
}
}
}

X m_dofs, m_conn;
Expand Down
32 changes: 13 additions & 19 deletions include/xtensor/xaccumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,20 @@ namespace xt

using return_type = std::decay_t<decltype(std::declval<accumulate_functor_type>(
)(std::declval<init_type>(), std::declval<expr_value_type>()))>;

using result_type = xaccumulator_return_type_t<std::decay_t<E>, return_type>;

if (axis >= e.dimension())
{
XTENSOR_THROW(std::runtime_error, "Axis larger than expression dimension in accumulator.");
}

result_type result = e; // assign + make a copy, we need it anyways
result_type res = e; // assign + make a copy, we need it anyways

if (result.shape(axis) != std::size_t(0))
if (res.shape(axis) != std::size_t(0))
{
std::size_t inner_stride = static_cast<std::size_t>(result.strides()[axis]);
std::size_t outer_stride = 1; // this is either going row- or column-wise (strides.back /
// strides.front)
std::size_t inner_stride = static_cast<std::size_t>(res.strides()[axis]);
std::size_t outer_stride = 1; // either row- or column-wise (strides.back / strides.front)
std::size_t outer_loop_size = 0;
std::size_t inner_loop_size = 0;
std::size_t init_size = e.shape()[axis] != std::size_t(1) ? std::size_t(1) : std::size_t(0);
Expand All @@ -256,19 +256,11 @@ namespace xt

if (result_type::static_layout == layout_type::row_major)
{
set_loop_sizes(
result.shape().cbegin(),
result.shape().cend(),
static_cast<std::ptrdiff_t>(axis)
);
set_loop_sizes(res.shape().cbegin(), res.shape().cend(), static_cast<std::ptrdiff_t>(axis));
}
else
{
set_loop_sizes(
result.shape().cbegin(),
result.shape().cend(),
static_cast<std::ptrdiff_t>(axis + 1)
);
set_loop_sizes(res.shape().cbegin(), res.shape().cend(), static_cast<std::ptrdiff_t>(axis + 1));
std::swap(inner_loop_size, outer_loop_size);
}

Expand All @@ -281,22 +273,23 @@ namespace xt
std::decay_t<typename F::init_functor_type>,
typename detail::accumulator_identity<init_type>>::value)
{
accumulator_init_with_f(xt::get<1>(f), result, axis);
accumulator_init_with_f(xt::get<1>(f), res, axis);
}

pos = 0;
for (std::size_t i = 0; i < outer_loop_size; ++i)
{
for (std::size_t j = 0; j < inner_loop_size; ++j)
{
result.storage()[pos + inner_stride] = xt::get<0>(f
)(result.storage()[pos], result.storage()[pos + inner_stride]);
res.storage()[pos + inner_stride] = xt::get<0>(f
)(res.storage()[pos], res.storage()[pos + inner_stride]);

pos += outer_stride;
}
pos += inner_stride;
}
}
return result;
return res;
}

template <class F, class E>
Expand All @@ -309,6 +302,7 @@ namespace xt
)(std::declval<init_type>(), std::declval<expr_value_type>()))>;
// using return_type = std::conditional_t<std::is_same<init_type, void>::value, typename
// std::decay_t<E>::value_type, init_type>;

using result_type = xaccumulator_return_type_t<std::decay_t<E>, return_type>;

std::size_t sz = e.size();
Expand Down
24 changes: 17 additions & 7 deletions include/xtensor/xeval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace xt
* Force evaluation of xexpression.
*
* \code{.cpp}
* xt::xarray<double> a = {1,2,3,4};
* xt::xarray<double> a = {1, 2, 3, 4};
* auto&& b = xt::eval(a); // b is a reference to a, no copy!
* auto&& c = xt::eval(a + b); // c is xarray<double>, not an xexpression
* \endcode
Expand Down Expand Up @@ -121,12 +121,22 @@ namespace xt
* and convert to the required layout.
*
* \code{.cpp}
* xt::xarray<double, xt::layout_type::row_major> a = {1,2,3,4};
* auto&& b = xt::as_strided(a); // b is a reference to a, no copy!
* auto&& c = xt::as_strided<xt::layout_type::column_major>(a); // b is xarray<double> with the required
* layout auto&& a_cast = xt::cast<int>(a); // a_cast is an xexpression auto&& d = xt::as_strided(a_cast);
* // d is xarray<int>, not an xexpression auto&& e =
* xt::as_strided<xt::layout_type::column_major>(a_cast); // d is xarray<int> with the required layout
* xt::xarray<double, xt::layout_type::row_major> a = {1, 2, 3, 4};
*
* // take reference to a (no copy!)
* auto&& b = xt::as_strided(a);
*
* // xarray<double> with the required layout
* auto&& c = xt::as_strided<xt::layout_type::column_major>(a);
*
* // xexpression
* auto&& a_cast = xt::cast<int>(a);
*
* // xarray<int>, not an xexpression
* auto&& d = xt::as_strided(a_cast);
*
* // xarray<int> with the required layout
* auto&& e = xt::as_strided<xt::layout_type::column_major>(a_cast);
* \endcode
*
* @warning This function should be used in a local context only.
Expand Down
6 changes: 3 additions & 3 deletions include/xtensor/xfixed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,9 +633,9 @@ namespace xt

/**
* Allocates an xfixed_container with shape S with values from a C array.
* The type returned by get_init_type_t is raw C array ``value_type[X][Y][Z]`` for ``xt::xshape<X, Y,
* Z>``. C arrays can be initialized with the initializer list syntax, but the size is checked at compile
* time to prevent errors.
* The type returned by get_init_type_t is raw C array ``value_type[X][Y][Z]`` for
* ``xt::xshape<X, Y, Z>``. C arrays can be initialized with the initializer list syntax,
* but the size is checked at compile time to prevent errors.
* Note: for clang < 3.8 this is an initializer_list and the size is not checked at compile-or runtime.
*/
template <class ET, class S, layout_type L, bool SH, class Tag>
Expand Down
5 changes: 3 additions & 2 deletions include/xtensor/xfunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,9 @@ namespace xt
using difference_type = common_difference_type_t<std::decay_t<CT>...>;

using simd_value_type = xt_simd::simd_type<value_type>;
using bool_load_type = detail::xfunction_bool_load_type_t<CT...>; // xtl::promote_type_t<typename
// std::decay_t<CT>::bool_load_type...>;

// xtl::promote_type_t<typename std::decay_t<CT>::bool_load_type...>;
using bool_load_type = detail::xfunction_bool_load_type_t<CT...>;

template <class requested_type>
using simd_return_type = xt_simd::simd_return_type<value_type, requested_type>;
Expand Down

0 comments on commit 284d536

Please sign in to comment.