Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ library:
| `xtensor` | `xtl` |`xsimd` (optional) |
|-----------|---------|-------------------|
| master | ^0.8.0 | ^13.2.0 |
| 0.27.2 | ^0.8.0 | ^13.2.0 |
| 0.27.1 | ^0.8.0 | ^13.2.0 |
| 0.27.0 | ^0.8.0 | ^13.2.0 |
| 0.26.0 | ^0.8.0 | ^13.2.0 |
Expand Down
5 changes: 5 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
Changelog
=========

0.27.2
------

- Fixed xexpression_holder generic constructor

0.27.1
------

Expand Down
2 changes: 1 addition & 1 deletion include/xtensor/core/xtensor_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#define XTENSOR_VERSION_MAJOR 0
#define XTENSOR_VERSION_MINOR 27
#define XTENSOR_VERSION_PATCH 1
#define XTENSOR_VERSION_PATCH 2


// Define if the library is going to be using exceptions.
Expand Down
23 changes: 13 additions & 10 deletions include/xtensor/misc/xexpression_holder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#ifndef XTENSOR_XEXPRESSION_HOLDER_HPP
#define XTENSOR_XEXPRESSION_HOLDER_HPP

#include <concepts>
#include <memory>
#include <type_traits>

#include <nlohmann/json.hpp>

Expand Down Expand Up @@ -38,6 +40,7 @@ namespace xt
xexpression_holder() = default;

template <class E>
requires(!std::same_as<std::decay_t<E>, xexpression_holder>)
xexpression_holder(E&& expr);

xexpression_holder(implementation_type* holder);
Expand Down Expand Up @@ -118,6 +121,7 @@ namespace xt
}

template <class E>
requires(!std::same_as<std::decay_t<E>, xexpression_holder>)
inline xexpression_holder::xexpression_holder(E&& expr)
: p_holder(new detail::xexpression_wrapper<E>(std::forward<E>(expr)))
{
Expand Down Expand Up @@ -181,30 +185,29 @@ namespace xt

inline void xexpression_holder::init_pointer_from_json(const nlohmann::json& j)
{
if (j.is_array())
if (j.is_array() && !j.empty())
{
return init_pointer_from_json(j[0]);
init_pointer_from_json(j[0]);
}

if (j.is_number())
else if (j.is_number())
{
xt::xarray<double> empty_arr;
p_holder.reset(new detail::xexpression_wrapper<xt::xarray<double>>(std::move(empty_arr)));
}

if (j.is_boolean())
else if (j.is_boolean())
{
xt::xarray<bool> empty_arr;
p_holder.reset(new detail::xexpression_wrapper<xt::xarray<bool>>(std::move(empty_arr)));
}

if (j.is_string())
else if (j.is_string())
{
xt::xarray<std::string> empty_arr;
p_holder.reset(new detail::xexpression_wrapper<xt::xarray<std::string>>(std::move(empty_arr)));
}

XTENSOR_THROW(std::runtime_error, "Received a JSON with a tensor that contains unsupported data type");
else
{
XTENSOR_THROW(std::runtime_error, "Received a JSON with a tensor that contains unsupported data type");
}
}

inline void xexpression_holder::check_holder() const
Expand Down
Loading