diff --git a/.gitmodules b/.gitmodules index e47b08fd82..e27e6fdf61 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "vendor/gsl-lite"] path = vendor/gsl-lite url = https://github.com/martinmoene/gsl-lite.git +[submodule "vendor/xtensor"] + path = vendor/xtensor + url = https://github.com/xtensor-stack/xtensor.git diff --git a/vendor/xtensor b/vendor/xtensor new file mode 160000 index 0000000000..ef091807f7 --- /dev/null +++ b/vendor/xtensor @@ -0,0 +1 @@ +Subproject commit ef091807f7ed0e5ba7e251a6c46f4af7bba79e2e diff --git a/vendor/xtensor/CMakeLists.txt b/vendor/xtensor/CMakeLists.txt deleted file mode 100644 index ce5fe9e6a5..0000000000 --- a/vendor/xtensor/CMakeLists.txt +++ /dev/null @@ -1,252 +0,0 @@ -############################################################################ -# Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht # -# Copyright (c) QuantStack # -# # -# Distributed under the terms of the BSD 3-Clause License. # -# # -# The full license is in the file LICENSE, distributed with this software. # -############################################################################ - -cmake_minimum_required(VERSION 3.1) -project(xtensor) - -set(XTENSOR_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) - -# Versionning -# =========== - -file(STRINGS "${XTENSOR_INCLUDE_DIR}/xtensor/xtensor_config.hpp" xtensor_version_defines - REGEX "#define XTENSOR_VERSION_(MAJOR|MINOR|PATCH)") -foreach(ver ${xtensor_version_defines}) - if(ver MATCHES "#define XTENSOR_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$") - set(XTENSOR_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") - endif() -endforeach() -set(${PROJECT_NAME}_VERSION - ${XTENSOR_VERSION_MAJOR}.${XTENSOR_VERSION_MINOR}.${XTENSOR_VERSION_PATCH}) -message(STATUS "Building xtensor v${${PROJECT_NAME}_VERSION}") - -# Dependencies -# ============ - -set(xtl_REQUIRED_VERSION 0.6.7) -find_package(xtl ${xtl_REQUIRED_VERSION} REQUIRED) -message(STATUS "Found xtl: ${xtl_INCLUDE_DIRS}/xtl") - -find_package(nlohmann_json 3.1.1 QUIET) - -# Optional dependencies -# ===================== - -OPTION(XTENSOR_USE_XSIMD "simd acceleration for xtensor" OFF) -OPTION(XTENSOR_USE_TBB "enable parallelization using intel TBB" OFF) -OPTION(XTENSOR_USE_OPENMP "enable parallelization using OpenMP" OFF) -if(XTENSOR_USE_TBB AND XTENSOR_USE_OPENMP) - message( - FATAL - "XTENSOR_USE_TBB and XTENSOR_USE_OPENMP cannot both be active at once" - ) -endif() - -if(XTENSOR_USE_XSIMD) - set(xsimd_REQUIRED_VERSION 7.4.0) - find_package(xsimd ${xsimd_REQUIRED_VERSION} REQUIRED) - message(STATUS "Found xsimd: ${xsimd_INCLUDE_DIRS}/xsimd") -endif() - -if(XTENSOR_USE_TBB) - set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") - find_package(TBB REQUIRED) - message(STATUS "Found intel TBB: ${TBB_INCLUDE_DIRS}") -endif() - -if(XTENSOR_USE_OPENMP) - find_package(OpenMP REQUIRED) - if (OPENMP_FOUND) - # Set openmp variables now - - # Create private target just for this lib - # https://cliutils.gitlab.io/modern-cmake/chapters/packages/OpenMP.html - # Probably not safe for cmake < 3.4 .. - find_package(Threads REQUIRED) - add_library(OpenMP::OpenMP_CXX_xtensor IMPORTED INTERFACE) - set_property( - TARGET - OpenMP::OpenMP_CXX_xtensor - PROPERTY - INTERFACE_COMPILE_OPTIONS ${OpenMP_CXX_FLAGS} - ) - # Only works if the same flag is passed to the linker; use CMake 3.9+ otherwise (Intel, AppleClang) - set_property( - TARGET - OpenMP::OpenMP_CXX_xtensor - PROPERTY - INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS} Threads::Threads) - - message(STATUS "OpenMP Found") - else() - message(FATAL "Failed to locate OpenMP") - endif() -endif() - -# Build -# ===== - -set(XTENSOR_HEADERS - ${XTENSOR_INCLUDE_DIR}/xtensor/xaccessible.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xaccumulator.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xadapt.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xarray.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xassign.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xaxis_iterator.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xbroadcast.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xbuffer_adaptor.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xbuilder.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xcomplex.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xcontainer.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xcsv.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xdynamic_view.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xeval.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xexception.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xexpression.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xexpression_holder.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xexpression_traits.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xfixed.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xfunction.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xfunctor_view.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xgenerator.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xhistogram.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xindex_view.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xinfo.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xio.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xiterable.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xiterator.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xjson.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xlayout.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xmanipulation.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xmasked_view.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xmath.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xmime.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xnoalias.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xnorm.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xnpy.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xoffset_view.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xoperation.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xoptional.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xoptional_assembly.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xoptional_assembly_base.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xoptional_assembly_storage.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xpad.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xrandom.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xreducer.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xscalar.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xsemantic.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xshape.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xslice.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xsort.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xstorage.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xstrided_view.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xstrided_view_base.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xstrides.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xtensor.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xtensor_config.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xtensor_forward.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xtensor_simd.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xutils.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xvectorize.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xview.hpp - ${XTENSOR_INCLUDE_DIR}/xtensor/xview_utils.hpp -) - -add_library(xtensor INTERFACE) -target_include_directories(xtensor INTERFACE $ - $) -target_link_libraries(xtensor INTERFACE xtl) - -OPTION(XTENSOR_ENABLE_ASSERT "xtensor bound check" OFF) -OPTION(XTENSOR_CHECK_DIMENSION "xtensor dimension check" OFF) -OPTION(BUILD_TESTS "xtensor test suite" OFF) -OPTION(BUILD_BENCHMARK "xtensor benchmark" OFF) -OPTION(DOWNLOAD_GTEST "build gtest from downloaded sources" OFF) -OPTION(DOWNLOAD_GBENCHMARK "download google benchmark and build from source" ON) -OPTION(DEFAULT_COLUMN_MAJOR "set default layout to column major" OFF) -OPTION(DISABLE_VS2017 "disables the compilation of some test with Visual Studio 2017" OFF) -OPTION(CPP17 "enables C++17" OFF) - -if(DOWNLOAD_GTEST OR GTEST_SRC_DIR) - set(BUILD_TESTS ON) -endif() - -if(XTENSOR_ENABLE_ASSERT OR XTENSOR_CHECK_DIMENSION) - add_definitions(-DXTENSOR_ENABLE_ASSERT) -endif() - -if(XTENSOR_CHECK_DIMENSION) - add_definitions(-DXTENSOR_ENABLE_CHECK_DIMENSION) -endif() - -if(DEFAULT_COLUMN_MAJOR) - add_definitions(-DXTENSOR_DEFAULT_LAYOUT=layout_type::column_major) -endif() - -if(DISABLE_VS2017) - add_definitions(-DDISABLE_VS2017) -endif() - -if(BUILD_TESTS) - add_subdirectory(test) -endif() - -if(BUILD_BENCHMARK) - add_subdirectory(benchmark) -endif() - -if(XTENSOR_USE_OPENMP) - # Link xtensor itself to OpenMP to propagate to user projects - target_link_libraries(xtensor INTERFACE OpenMP::OpenMP_CXX_xtensor) -endif() - -# Installation -# ============ - -include(GNUInstallDirs) -include(CMakePackageConfigHelpers) - -install(TARGETS xtensor - EXPORT ${PROJECT_NAME}-targets) - -# Makes the project importable from the build directory -export(EXPORT ${PROJECT_NAME}-targets - FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake") - -install(FILES ${XTENSOR_HEADERS} - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/xtensor) - -set(XTENSOR_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE - STRING "install path for xtensorConfig.cmake") - -configure_package_config_file(${PROJECT_NAME}Config.cmake.in - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - INSTALL_DESTINATION ${XTENSOR_CMAKECONFIG_INSTALL_DIR}) - -# xtensor is header-only and does not depend on the architecture. -# Remove CMAKE_SIZEOF_VOID_P from xtensorConfigVersion.cmake so that an xtensorConfig.cmake -# generated for a 64 bit target can be used for 32 bit targets and vice versa. -set(_XTENSOR_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) -unset(CMAKE_SIZEOF_VOID_P) -write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake - VERSION ${${PROJECT_NAME}_VERSION} - COMPATIBILITY AnyNewerVersion) -set(CMAKE_SIZEOF_VOID_P ${_XTENSOR_CMAKE_SIZEOF_VOID_P}) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake - ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake - DESTINATION ${XTENSOR_CMAKECONFIG_INSTALL_DIR}) -install(EXPORT ${PROJECT_NAME}-targets - FILE ${PROJECT_NAME}Targets.cmake - DESTINATION ${XTENSOR_CMAKECONFIG_INSTALL_DIR}) - -configure_file(${PROJECT_NAME}.pc.in - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" - @ONLY) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") diff --git a/vendor/xtensor/include/xtensor/xaccessible.hpp b/vendor/xtensor/include/xtensor/xaccessible.hpp deleted file mode 100644 index 8d8c6b3b27..0000000000 --- a/vendor/xtensor/include/xtensor/xaccessible.hpp +++ /dev/null @@ -1,307 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_ACCESSIBLE_HPP -#define XTENSOR_ACCESSIBLE_HPP - -#include "xexception.hpp" -#include "xstrides.hpp" -#include "xtensor_forward.hpp" - -namespace xt -{ - /** - * @class xconst_accessible - * @brief Base class for implementation of common expression constant access methods. - * - * The xaccessible class implements constant access methods common to all expressions. - * - * @tparam D The derived type, i.e. the inheriting class for which xconst_accessible - * - * - */ - template - class xconst_accessible - { - public: - - using derived_type = D; - using inner_types = xcontainer_inner_types; - using reference = typename inner_types::reference; - using const_reference = typename inner_types::const_reference; - using size_type = typename inner_types::size_type; - - size_type size() const noexcept; - size_type dimension() const noexcept; - size_type shape(size_type index) const; - - template - const_reference at(Args... args) const; - - template - disable_integral_t operator[](const S& index) const; - template - const_reference operator[](std::initializer_list index) const; - const_reference operator[](size_type i) const; - - template - const_reference periodic(Args... args) const; - - template - bool in_bounds(Args... args) const; - - protected: - - xconst_accessible() = default; - ~xconst_accessible() = default; - - xconst_accessible(const xconst_accessible&) = default; - xconst_accessible& operator=(const xconst_accessible&) = default; - - xconst_accessible(xconst_accessible&&) = default; - xconst_accessible& operator=(xconst_accessible&&) = default; - - private: - - const derived_type& derived_cast() const noexcept; - }; - - /** - * @class xaccessible - * @brief Base class for implementation of common expression access methods. - * - * The xaccessible class implements access methods common to all expressions. - * - * @tparam D The derived type, i.e. the inheriting class for which xaccessible - * provides the interface. - */ - template - class xaccessible : public xconst_accessible - { - public: - - using base_type = xconst_accessible; - using derived_type = typename base_type::derived_type; - using reference = typename base_type::reference; - using size_type = typename base_type::size_type; - - template - reference at(Args... args); - - template - disable_integral_t operator[](const S& index); - template - reference operator[](std::initializer_list index); - reference operator[](size_type i); - - template - reference periodic(Args... args); - - using base_type::at; - using base_type::operator[]; - using base_type::periodic; - - protected: - - xaccessible() = default; - ~xaccessible() = default; - - xaccessible(const xaccessible&) = default; - xaccessible& operator=(const xaccessible&) = default; - - xaccessible(xaccessible&&) = default; - xaccessible& operator=(xaccessible&&) = default; - - private: - - derived_type& derived_cast() noexcept; - }; - - /************************************ - * xconst_accessible implementation * - ************************************/ - - /** - * Returns the size of the expression. - */ - template - inline auto xconst_accessible::size() const noexcept -> size_type - { - return compute_size(derived_cast().shape()); - } - - /** - * Returns the number of dimensions of the expression. - */ - template - inline auto xconst_accessible::dimension() const noexcept -> size_type - { - return derived_cast().shape().size(); - } - - /** - * Returns the i-th dimension of the expression. - */ - template - inline auto xconst_accessible::shape(size_type index) const -> size_type - { - return derived_cast().shape()[index]; - } - - /** - * Returns a constant reference to the element at the specified position in the expression, - * after dimension and bounds checking. - * @param args a list of indices specifying the position in the expression. Indices - * must be unsigned integers, the number of indices should be equal to the number of dimensions - * of the expression. - * @exception std::out_of_range if the number of argument is greater than the number of dimensions - * or if indices are out of bounds. - */ - template - template - inline auto xconst_accessible::at(Args... args) const -> const_reference - { - check_access(derived_cast().shape(), static_cast(args)...); - return derived_cast().operator()(args...); - } - - /** - * Returns a constant reference to the element at the specified position in the expression. - * @param index a sequence of indices specifying the position in the expression. Indices - * must be unsigned integers, the number of indices in the list should be equal or greater - * than the number of dimensions of the expression. - */ - template - template - inline auto xconst_accessible::operator[](const S& index) const - -> disable_integral_t - { - return derived_cast().element(index.cbegin(), index.cend()); - } - - template - template - inline auto xconst_accessible::operator[](std::initializer_list index) const -> const_reference - { - return derived_cast().element(index.begin(), index.end()); - } - - template - inline auto xconst_accessible::operator[](size_type i) const -> const_reference - { - return derived_cast().operator()(i); - } - - /** - * Returns a constant reference to the element at the specified position in the expression, - * after applying periodicity to the indices (negative and 'overflowing' indices are changed). - * @param args a list of indices specifying the position in the expression. Indices - * must be integers, the number of indices should be equal to the number of dimensions - * of the expression. - */ - template - template - inline auto xconst_accessible::periodic(Args... args) const -> const_reference - { - normalize_periodic(derived_cast().shape(), args...); - return derived_cast()(static_cast(args)...); - } - - /** - * Returns ``true`` only if the the specified position is a valid entry in the expression. - * @param args a list of indices specifying the position in the expression. - * @return bool - */ - template - template - inline bool xconst_accessible::in_bounds(Args... args) const - { - return check_in_bounds(derived_cast().shape(), args...); - } - - template - inline auto xconst_accessible::derived_cast() const noexcept -> const derived_type& - { - return *static_cast(this); - } - - /****************************** - * xaccessible implementation * - ******************************/ - - /** - * Returns a reference to the element at the specified position in the expression, - * after dimension and bounds checking. - * @param args a list of indices specifying the position in the expression. Indices - * must be unsigned integers, the number of indices should be equal to the number of dimensions - * of the expression. - * @exception std::out_of_range if the number of argument is greater than the number of dimensions - * or if indices are out of bounds. - */ - template - template - inline auto xaccessible::at(Args... args) -> reference - { - check_access(derived_cast().shape(), static_cast(args)...); - return derived_cast().operator()(args...); - } - - /** - * Returns a reference to the element at the specified position in the expression. - * @param index a sequence of indices specifying the position in the expression. Indices - * must be unsigned integers, the number of indices in the list should be equal or greater - * than the number of dimensions of the expression. - */ - template - template - inline auto xaccessible::operator[](const S& index) - -> disable_integral_t - { - return derived_cast().element(index.cbegin(), index.cend()); - } - - template - template - inline auto xaccessible::operator[](std::initializer_list index) -> reference - { - return derived_cast().element(index.begin(), index.end()); - } - - template - inline auto xaccessible::operator[](size_type i) -> reference - { - return derived_cast().operator()(i); - } - - /** - * Returns a reference to the element at the specified position in the expression, - * after applying periodicity to the indices (negative and 'overflowing' indices are changed). - * @param args a list of indices specifying the position in the expression. Indices - * must be integers, the number of indices should be equal to the number of dimensions - * of the expression. - */ - template - template - inline auto xaccessible::periodic(Args... args) -> reference - { - normalize_periodic(derived_cast().shape(), args...); - return derived_cast()(static_cast(args)...); - } - - - template - inline auto xaccessible::derived_cast() noexcept -> derived_type& - { - return *static_cast(this); - } - -} - -#endif - diff --git a/vendor/xtensor/include/xtensor/xaccumulator.hpp b/vendor/xtensor/include/xtensor/xaccumulator.hpp deleted file mode 100644 index 7bba8a5ae6..0000000000 --- a/vendor/xtensor/include/xtensor/xaccumulator.hpp +++ /dev/null @@ -1,318 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_ACCUMULATOR_HPP -#define XTENSOR_ACCUMULATOR_HPP - -#include -#include -#include -#include - -#include "xexpression.hpp" -#include "xstrides.hpp" -#include "xtensor_forward.hpp" - -namespace xt -{ - -#define DEFAULT_STRATEGY_ACCUMULATORS evaluation_strategy::immediate_type - - /************** - * accumulate * - **************/ - - template - struct xaccumulator_functor - : public std::tuple - { - using self_type = xaccumulator_functor; - using base_type = std::tuple; - using accumulate_functor_type = ACCUMULATE_FUNC; - using init_functor_type = INIT_FUNC; - - xaccumulator_functor() - : base_type() - { - } - - template - xaccumulator_functor(RF&& accumulate_func) - : base_type(std::forward(accumulate_func), INIT_FUNC()) - { - } - - template - xaccumulator_functor(RF&& accumulate_func, IF&& init_func) - : base_type(std::forward(accumulate_func), std::forward(init_func)) - { - } - }; - - template - auto make_xaccumulator_functor(RF&& accumulate_func) - { - using accumulator_type = xaccumulator_functor>; - return accumulator_type(std::forward(accumulate_func)); - } - - template - auto make_xaccumulator_functor(RF&& accumulate_func, IF&& init_func) - { - using accumulator_type = xaccumulator_functor, std::remove_reference_t>; - return accumulator_type(std::forward(accumulate_func), std::forward(init_func)); - } - - namespace detail - { - template - xarray::value_type> accumulator_impl(F&&, E&&, std::size_t, EVS) - { - static_assert(!std::is_same::value, "Lazy accumulators not yet implemented."); - } - - template - xarray::value_type> accumulator_impl(F&&, E&&, EVS) - { - static_assert(!std::is_same::value, "Lazy accumulators not yet implemented."); - } - - template - struct xaccumulator_return_type - { - using type = xarray; - }; - - template - struct xaccumulator_return_type, R> - { - using type = xarray; - }; - - template - struct xaccumulator_return_type, R> - { - using type = xtensor; - }; - - template - struct xaccumulator_return_type, L>, R> - { - using type = xtensor_fixed, L>; - }; - - template - using xaccumulator_return_type_t = typename xaccumulator_return_type::type; - - template - struct fixed_compute_size; - - template - struct xaccumulator_linear_return_type - { - using type = xtensor; - }; - - template - struct xaccumulator_linear_return_type, R> - { - using type = xtensor; - }; - - template - struct xaccumulator_linear_return_type, R> - { - using type = xtensor; - }; - - template - struct xaccumulator_linear_return_type, L>, R> - { - using type = xtensor_fixed>::value>, L>; - }; - - template - using xaccumulator_linear_return_type_t = typename xaccumulator_linear_return_type::type; - - template - inline auto accumulator_init_with_f(F&& f, E& e, std::size_t axis) - { - // this function is the equivalent (but hopefully faster) to (if axis == 1) - // e[:, 0, :, :, ...] = f(e[:, 0, :, :, ...]) - // so that all "first" values are initialized in a first pass - - std::size_t outer_loop_size, inner_loop_size, pos = 0; - std::size_t outer_stride, inner_stride; - - auto set_loop_sizes = [&outer_loop_size, &inner_loop_size](auto first, auto last, std::ptrdiff_t ax) { - outer_loop_size = std::accumulate(first, first + ax, - std::size_t(1), std::multiplies()); - inner_loop_size = std::accumulate(first + ax + 1, last, - std::size_t(1), std::multiplies()); - }; - - // Note: add check that strides > 0 - auto set_loop_strides = [&outer_stride, &inner_stride](auto first, auto last, std::ptrdiff_t ax) { - outer_stride = static_cast(ax == 0 ? 1 : *std::min_element(first, first + ax)); - inner_stride = static_cast((ax == std::distance(first, last) - 1) ? 1 : *std::min_element(first + ax + 1, last)); - }; - - set_loop_sizes(e.shape().begin(), e.shape().end(), static_cast(axis)); - set_loop_strides(e.strides().begin(), e.strides().end(), static_cast(axis)); - - if (e.layout() == layout_type::column_major) - { - // swap for better memory locality (smaller stride in the inner loop) - std::swap(outer_loop_size, inner_loop_size); - std::swap(outer_stride, inner_stride); - } - - for (std::size_t i = 0; i < outer_loop_size; ++i) - { - pos = i * outer_stride; - for (std::size_t j = 0; j < inner_loop_size; ++j) - { - e.storage()[pos] = f(e.storage()[pos]); - pos += inner_stride; - } - } - } - - template - inline auto accumulator_impl(F&& f, E&& e, std::size_t axis, evaluation_strategy::immediate_type) - { - using accumulate_functor = std::decay_t(f))>; - using function_return_type = typename accumulate_functor::result_type; - using result_type = xaccumulator_return_type_t, function_return_type>; - - if (axis >= e.dimension()) - { - throw std::runtime_error("Axis larger than expression dimension in accumulator."); - } - - result_type result = e; // assign + make a copy, we need it anyways - - if(result.shape(axis) != std::size_t(0)) - { - std::size_t inner_stride = static_cast(result.strides()[axis]); - std::size_t outer_stride = 1; // this is either going 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); - - auto set_loop_sizes = [&outer_loop_size, &inner_loop_size, init_size](auto first, auto last, std::ptrdiff_t ax) { - outer_loop_size = std::accumulate(first, - first + ax, - init_size, std::multiplies()); - - inner_loop_size = std::accumulate(first + ax, - last, - std::size_t(1), std::multiplies()); - }; - - if (result_type::static_layout == layout_type::row_major) - { - set_loop_sizes(result.shape().cbegin(), result.shape().cend(), static_cast(axis)); - } - else - { - set_loop_sizes(result.shape().cbegin(), result.shape().cend(), static_cast(axis + 1)); - std::swap(inner_loop_size, outer_loop_size); - } - - std::size_t pos = 0; - - inner_loop_size = inner_loop_size - inner_stride; - - // activate the init loop if we have an init function other than identity - if (!std::is_same(f))>, xtl::identity>::value) - { - accumulator_init_with_f(xt::get<1>(f), result, 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]); - pos += outer_stride; - } - pos += inner_stride; - } - } - return result; - } - - template - inline auto accumulator_impl(F&& f, E&& e, evaluation_strategy::immediate_type) - { - using accumulate_functor = std::decay_t(f))>; - using T = typename accumulate_functor::result_type; - - using result_type = xaccumulator_linear_return_type_t, T>; - std::size_t sz = e.size(); - auto result = result_type::from_shape({sz}); - - if(sz != std::size_t(0)) - { - auto it = e.template begin(); - result.storage()[0] = xt::get<1>(f)(*it); - ++it; - - for (std::size_t idx = 0; it != e.template end(); ++it) - { - result.storage()[idx + 1] = xt::get<0>(f)(result.storage()[idx], *it); - ++idx; - } - } - return result; - } - } - - /** - * Accumulate and flatten array - * **NOTE** This function is not lazy! - * - * @param f functor to use for accumulation - * @param e xexpression to be accumulated - * @param evaluation_strategy evaluation strategy of the accumulation - * - * @return returns xarray filled with accumulated values - */ - template )> - inline auto accumulate(F&& f, E&& e, EVS evaluation_strategy = EVS()) - { - // Note we need to check is_integral above in order to prohibit EVS = int, and not taking the std::size_t - // overload below! - return detail::accumulator_impl(std::forward(f), std::forward(e), evaluation_strategy); - } - - /** - * Accumulate over axis - * **NOTE** This function is not lazy! - * - * @param f Functor to use for accumulation - * @param e xexpression to accumulate - * @param axis Axis to perform accumulation over - * @param evaluation_strategy evaluation strategy of the accumulation - * - * @return returns xarray filled with accumulated values - */ - template - inline auto accumulate(F&& f, E&& e, std::ptrdiff_t axis, EVS evaluation_strategy = EVS()) - { - std::size_t ax = normalize_axis(e.dimension(), axis); - return detail::accumulator_impl(std::forward(f), std::forward(e), ax, evaluation_strategy); - } -} - -#endif diff --git a/vendor/xtensor/include/xtensor/xadapt.hpp b/vendor/xtensor/include/xtensor/xadapt.hpp deleted file mode 100644 index 5dac517a2d..0000000000 --- a/vendor/xtensor/include/xtensor/xadapt.hpp +++ /dev/null @@ -1,498 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_ADAPT_HPP -#define XTENSOR_ADAPT_HPP - -#include -#include -#include -#include - -#include - -#include "xarray.hpp" -#include "xtensor.hpp" -#include "xfixed.hpp" -#include "xbuffer_adaptor.hpp" - -namespace xt -{ - namespace detail - { - template - struct array_size_impl; - - template - struct array_size_impl> - { - static constexpr std::size_t value = N; - }; - - template - using array_size = array_size_impl>; - - template - struct default_allocator_for_ptr - { - using type = std::allocator>>>; - }; - - template - using default_allocator_for_ptr_t = typename default_allocator_for_ptr

::type; - - template - using not_an_array = xtl::negation>; - - template - using not_a_pointer = xtl::negation>; - - template - using not_a_layout = xtl::negation>; - } - - /************************** - * xarray_adaptor builder * - **************************/ - - /** - * Constructs an xarray_adaptor of the given stl-like container, - * with the specified shape and layout. - * @param container the container to adapt - * @param shape the shape of the xarray_adaptor - * @param l the layout_type of the xarray_adaptor - */ - template >, - detail::not_a_pointer)> - inline xarray_adaptor, L, std::decay_t> - adapt(C&& container, const SC& shape, layout_type l = L) - { - using return_type = xarray_adaptor, L, std::decay_t>; - return return_type(std::forward(container), shape, l); - } - - /** - * Constructs an non-owning xarray_adaptor from a pointer with the specified shape and layout. - * @param pointer the container to adapt - * @param shape the shape of the xarray_adaptor - * @param l the layout_type of the xarray_adaptor - */ - template >, - std::is_pointer)> - inline auto adapt(C&& pointer, const SC& shape, layout_type l = L) - { - using buffer_type = xbuffer_adaptor>; - using return_type = xarray_adaptor>; - std::size_t size = compute_size(shape); - return return_type(buffer_type(pointer, size), shape, l); - } - - /** - * Constructs an xarray_adaptor of the given stl-like container, - * with the specified shape and strides. - * @param container the container to adapt - * @param shape the shape of the xarray_adaptor - * @param strides the strides of the xarray_adaptor - */ - template >, - detail::not_a_layout>)> - inline xarray_adaptor, layout_type::dynamic, std::decay_t> - adapt(C&& container, SC&& shape, SS&& strides) - { - using return_type = xarray_adaptor, layout_type::dynamic, std::decay_t>; - return return_type(std::forward(container), - xtl::forward_sequence(shape), - xtl::forward_sequence(strides)); - } - - /** - * Constructs an xarray_adaptor of the given dynamically allocated C array, - * with the specified shape and layout. - * @param pointer the pointer to the beginning of the dynamic array - * @param size the size of the dynamic array - * @param ownership indicates whether the adaptor takes ownership of the array. - * Possible values are ``no_ownership()`` or ``acquire_ownership()`` - * @param shape the shape of the xarray_adaptor - * @param l the layout_type of the xarray_adaptor - * @param alloc the allocator used for allocating / deallocating the dynamic array - */ - template , - XTL_REQUIRES(detail::not_an_array>)> - inline xarray_adaptor, O, A>, L, SC> - adapt(P&& pointer, typename A::size_type size, O ownership, const SC& shape, layout_type l = L, const A& alloc = A()) - { - (void)ownership; - using buffer_type = xbuffer_adaptor, O, A>; - using return_type = xarray_adaptor; - buffer_type buf(std::forward

(pointer), size, alloc); - return return_type(std::move(buf), shape, l); - } - - /** - * Constructs an xarray_adaptor of the given dynamically allocated C array, - * with the specified shape and strides. - * @param pointer the pointer to the beginning of the dynamic array - * @param size the size of the dynamic array - * @param ownership indicates whether the adaptor takes ownership of the array. - * Possible values are ``no_ownership()`` or ``acquire_ownership()`` - * @param shape the shape of the xarray_adaptor - * @param strides the strides of the xarray_adaptor - * @param alloc the allocator used for allocating / deallocating the dynamic array - */ - template , - XTL_REQUIRES(detail::not_an_array>, - detail::not_a_layout>)> - inline xarray_adaptor, O, A>, layout_type::dynamic, std::decay_t> - adapt(P&& pointer, typename A::size_type size, O ownership, SC&& shape, SS&& strides, const A& alloc = A()) - { - (void)ownership; - using buffer_type = xbuffer_adaptor, O, A>; - using return_type = xarray_adaptor>; - buffer_type buf(std::forward

(pointer), size, alloc); - return return_type(std::move(buf), - xtl::forward_sequence(shape), - xtl::forward_sequence(strides)); - } - - /** - * Contructs an xarray_adaptor of the given C array allocated on the stack, with the - * specified shape and layout. - * @param c_array the C array allocated on the stack - * @param shape the shape of the xarray_adaptor - * @param l the layout_type of the xarray_adaptor - */ - template >)> - inline auto adapt(T (&c_array)[N], const SC& shape, layout_type l = L) - { - return adapt(&c_array[0], N, xt::no_ownership(), shape, l); - } - - /** - * Contructs an xarray_adaptor of the given C array allocated on the stack, with the - * specified shape and stirdes. - * @param c_array the C array allocated on the stack - * @param shape the shape of the xarray_adaptor - * @param strides the strides of the xarray_adaptor - */ - template >, - detail::not_a_layout>)> - inline auto adapt(T (&c_array)[N], SC&& shape, SS&& strides) - { - return adapt(&c_array[0], N, xt::no_ownership(), - std::forward(shape), - std::forward(strides)); - } - - /*************************** - * xtensor_adaptor builder * - ***************************/ - - /** - * Constructs a 1-D xtensor_adaptor of the given stl-like container, - * with the specified layout_type. - * @param container the container to adapt - * @param l the layout_type of the xtensor_adaptor - */ - template - inline xtensor_adaptor - adapt(C&& container, layout_type l = L) - { - const std::array::size_type, 1> shape{container.size()}; - using return_type = xtensor_adaptor, 1, L>; - return return_type(std::forward(container), shape, l); - } - - /** - * Constructs an xtensor_adaptor of the given stl-like container, - * with the specified shape and layout_type. - * @param container the container to adapt - * @param shape the shape of the xtensor_adaptor - * @param l the layout_type of the xtensor_adaptor - */ - template >, - detail::not_a_pointer)> - inline xtensor_adaptor::value, L> - adapt(C&& container, const SC& shape, layout_type l = L) - { - constexpr std::size_t N = detail::array_size::value; - using return_type = xtensor_adaptor, N, L>; - return return_type(std::forward(container), shape, l); - } - - /** - * Constructs an non-owning xtensor_adaptor from a pointer with the specified shape and layout. - * @param pointer the pointer to adapt - * @param shape the shape of the xtensor_adaptor - * @param l the layout_type of the xtensor_adaptor - */ - template >, - std::is_pointer)> - inline auto adapt(C&& pointer, const SC& shape, layout_type l = L) - { - using buffer_type = xbuffer_adaptor>; - constexpr std::size_t N = detail::array_size::value; - using return_type = xtensor_adaptor; - return return_type(buffer_type(pointer, compute_size(shape)), shape, l); - } - - /** - * Constructs an xtensor_adaptor of the given stl-like container, - * with the specified shape and strides. - * @param container the container to adapt - * @param shape the shape of the xtensor_adaptor - * @param strides the strides of the xtensor_adaptor - */ - template >, - detail::not_a_layout>)> - inline xtensor_adaptor::value, layout_type::dynamic> - adapt(C&& container, SC&& shape, SS&& strides) - { - constexpr std::size_t N = detail::array_size::value; - using return_type = xtensor_adaptor, N, layout_type::dynamic>; - return return_type(std::forward(container), - xtl::forward_sequence(shape), - xtl::forward_sequence(strides)); - } - - /** - * Constructs a 1-D xtensor_adaptor of the given dynamically allocated C array, - * with the specified layout. - * @param pointer the pointer to the beginning of the dynamic array - * @param size the size of the dynamic array - * @param ownership indicates whether the adaptor takes ownership of the array. - * Possible values are ``no_ownership()`` or ``acquire_ownership()`` - * @param l the layout_type of the xtensor_adaptor - * @param alloc the allocator used for allocating / deallocating the dynamic array - */ - template > - inline xtensor_adaptor, O, A>, 1, L> - adapt(P&& pointer, typename A::size_type size, O ownership, layout_type l = L, const A& alloc = A()) - { - (void)ownership; - using buffer_type = xbuffer_adaptor, O, A>; - using return_type = xtensor_adaptor; - buffer_type buf(std::forward

(pointer), size, alloc); - const std::array shape{size}; - return return_type(std::move(buf), shape, l); - } - - /** - * Constructs an xtensor_adaptor of the given dynamically allocated C array, - * with the specified shape and layout. - * @param pointer the pointer to the beginning of the dynamic array - * @param size the size of the dynamic array - * @param ownership indicates whether the adaptor takes ownership of the array. - * Possible values are ``no_ownership()`` or ``acquire_ownership()`` - * @param shape the shape of the xtensor_adaptor - * @param l the layout_type of the xtensor_adaptor - * @param alloc the allocator used for allocating / deallocating the dynamic array - */ - template , - XTL_REQUIRES(detail::is_array>)> - inline xtensor_adaptor, O, A>, detail::array_size::value, L> - adapt(P&& pointer, typename A::size_type size, O ownership, const SC& shape, layout_type l = L, const A& alloc = A()) - { - (void)ownership; - using buffer_type = xbuffer_adaptor, O, A>; - constexpr std::size_t N = detail::array_size::value; - using return_type = xtensor_adaptor; - buffer_type buf(std::forward

(pointer), size, alloc); - return return_type(std::move(buf), shape, l); - } - - /** - * Constructs an xtensor_adaptor of the given dynamically allocated C array, - * with the specified shape and strides. - * @param pointer the pointer to the beginning of the dynamic array - * @param size the size of the dynamic array - * @param ownership indicates whether the adaptor takes ownership of the array. - * Possible values are ``no_ownership()`` or ``acquire_ownership()`` - * @param shape the shape of the xtensor_adaptor - * @param strides the strides of the xtensor_adaptor - * @param alloc the allocator used for allocating / deallocating the dynamic array - */ - template , - XTL_REQUIRES(detail::is_array>, - detail::not_a_layout>)> - inline xtensor_adaptor, O, A>, detail::array_size::value, layout_type::dynamic> - adapt(P&& pointer, typename A::size_type size, O ownership, SC&& shape, SS&& strides, const A& alloc = A()) - { - (void)ownership; - using buffer_type = xbuffer_adaptor, O, A>; - constexpr std::size_t N = detail::array_size::value; - using return_type = xtensor_adaptor; - buffer_type buf(std::forward

(pointer), size, alloc); - return return_type(std::move(buf), - xtl::forward_sequence(shape), - xtl::forward_sequence(strides)); - } - - /** - * Contructs an xtensor_adaptor of the given C array allocated on the stack, with the - * specified shape and layout. - * @param c_array the C array allocated on the stack - * @param shape the shape of the xarray_adaptor - * @param l the layout_type of the xarray_adaptor - */ - template >)> - inline auto adapt(T (&c_array)[N], const SC& shape, layout_type l = L) - { - return adapt(&c_array[0], N, xt::no_ownership(), shape, l); - } - - /** - * Contructs an xtensor_adaptor of the given C array allocated on the stack, with the - * specified shape and stirdes. - * @param c_array the C array allocated on the stack - * @param shape the shape of the xarray_adaptor - * @param strides the strides of the xarray_adaptor - */ - template >, - detail::not_a_layout>)> - inline auto adapt(T (&c_array)[N], SC&& shape, SS&& strides) - { - return adapt(&c_array[0], N, xt::no_ownership(), - std::forward(shape), - std::forward(strides)); - } - /** - * Constructs an non-owning xtensor_fixed_adaptor from a pointer with the - * specified shape and layout. - * @param pointer the pointer to adapt - * @param shape the shape of the xtensor_fixed_adaptor - */ - template )> - inline auto adapt(C&& ptr, const fixed_shape& /*shape*/) - { - using buffer_type = xbuffer_adaptor>; - using return_type = xfixed_adaptor, L>; - return return_type(buffer_type(ptr, detail::fixed_compute_size>::value)); - } - -#ifndef X_OLD_CLANG - template - inline auto adapt(C&& ptr, const T(&shape)[N]) - { - using shape_type = std::array; - return adapt(std::forward(ptr), xtl::forward_sequence(shape)); - } -#else - template - inline auto adapt(C&& ptr, std::initializer_list shape) - { - using shape_type = xt::dynamic_shape; - return adapt(std::forward(ptr), xtl::forward_sequence(shape)); - } -#endif - -#ifndef X_OLD_CLANG - /** - * Adapt a smart pointer to a typed memory block (unique_ptr or shared_ptr) - * - * \code{.cpp} - * #include - * #include - * - * std::shared_ptr sptr(new double[8], std::default_delete()); - * sptr.get()[2] = 321.; - * auto xptr = adapt_smart_ptr(sptr, {4, 2}); - * xptr(1, 3) = 123.; - * std::cout << xptr; - * \endcode - * - * @param smart_ptr a smart pointer to a memory block of T[] - * @param shape The desired shape - * - * @return xtensor_adaptor for memory - */ - template - auto adapt_smart_ptr(P&& smart_ptr, const I(&shape)[N]) - { - using buffer_adaptor = xbuffer_adaptor>; - std::array fshape = xtl::forward_sequence, decltype(shape)>(shape); - return xtensor_adaptor( - buffer_adaptor(smart_ptr.get(), compute_size(fshape), - std::forward

(smart_ptr)), - std::move(fshape) - ); - } - - /** - * Adapt a smart pointer (shared_ptr or unique_ptr) - * - * This function allows to automatically adapt a shared or unique pointer to - * a given shape and operate naturally on it. Memory will be automatically - * handled by the smart pointer implementation. - * - * \code{.cpp} - * #include - * #include - * - * struct Buffer { - * Buffer(std::vector& buf) : m_buf(buf) {} - * ~Buffer() { std::cout << "deleted" << std::endl; } - * std::vector m_buf; - * }; - * - * auto data = std::vector{1,2,3,4,5,6,7,8}; - * auto shared_buf = std::make_shared(data); - * auto unique_buf = std::make_unique(data); - * - * std::cout << shared_buf.use_count() << std::endl; - * { - * auto obj = adapt_smart_ptr(shared_buf.get()->m_buf.data(), - * {2, 4}, shared_buf); - * // Use count increased to 2 - * std::cout << shared_buf.use_count() << std::endl; - * std::cout << obj << std::endl; - * } - * // Use count reset to 1 - * std::cout << shared_buf.use_count() << std::endl; - * - * { - * auto obj = adapt_smart_ptr(unique_buf.get()->m_buf.data(), - * {2, 4}, std::move(unique_buf)); - * std::cout << obj << std::endl; - * } - * \endcode - * - * @param data_ptr A pointer to a typed data block (e.g. double*) - * @param shape The desired shape - * @param smart_ptr A smart pointer to move or copy, in order to manage memory - * - * @return xtensor_adaptor on the memory - */ - template - auto adapt_smart_ptr(P&& data_ptr, const I(&shape)[N], D&& smart_ptr) - { - using buffer_adaptor = xbuffer_adaptor>; - std::array fshape = xtl::forward_sequence, decltype(shape)>(shape); - - return xtensor_adaptor( - buffer_adaptor(data_ptr, compute_size(fshape), std::forward(smart_ptr)), - std::move(fshape) - ); - } -#endif -} - -#endif diff --git a/vendor/xtensor/include/xtensor/xarray.hpp b/vendor/xtensor/include/xtensor/xarray.hpp deleted file mode 100644 index 69bdb474e8..0000000000 --- a/vendor/xtensor/include/xtensor/xarray.hpp +++ /dev/null @@ -1,620 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_ARRAY_HPP -#define XTENSOR_ARRAY_HPP - -#include -#include -#include - -#include - -#include "xbuffer_adaptor.hpp" -#include "xcontainer.hpp" -#include "xsemantic.hpp" - -namespace xt -{ - - /******************************** - * xarray_container declaration * - ********************************/ - - namespace extension - { - template - struct xarray_container_base; - - template - struct xarray_container_base - { - using type = xtensor_empty_base; - }; - - template - using xarray_container_base_t = typename xarray_container_base::type; - } - - template - struct xcontainer_inner_types> - { - using storage_type = EC; - using reference = inner_reference_t; - using const_reference = typename storage_type::const_reference; - using size_type = typename storage_type::size_type; - using shape_type = SC; - using strides_type = get_strides_t; - using backstrides_type = get_strides_t; - using inner_shape_type = shape_type; - using inner_strides_type = strides_type; - using inner_backstrides_type = backstrides_type; - using temporary_type = xarray_container; - static constexpr layout_type layout = L; - }; - - template - struct xiterable_inner_types> - : xcontainer_iterable_types> - { - }; - - /** - * @class xarray_container - * @brief Dense multidimensional container with tensor semantic. - * - * The xarray_container class implements a dense multidimensional container - * with tensor semantic. - * - * @tparam EC The type of the container holding the elements. - * @tparam L The layout_type of the container. - * @tparam SC The type of the containers holding the shape and the strides. - * @tparam Tag The expression tag. - * @sa xarray, xstrided_container, xcontainer - */ - template - class xarray_container : public xstrided_container>, - public xcontainer_semantic>, - public extension::xarray_container_base_t - { - public: - - using self_type = xarray_container; - using base_type = xstrided_container; - using semantic_base = xcontainer_semantic; - using extension_base = extension::xarray_container_base_t; - using storage_type = typename base_type::storage_type; - using allocator_type = typename base_type::allocator_type; - using value_type = typename base_type::value_type; - using reference = typename base_type::reference; - using const_reference = typename base_type::const_reference; - using pointer = typename base_type::pointer; - using const_pointer = typename base_type::const_pointer; - using shape_type = typename base_type::shape_type; - using inner_shape_type = typename base_type::inner_shape_type; - using strides_type = typename base_type::strides_type; - using backstrides_type = typename base_type::backstrides_type; - using inner_strides_type = typename base_type::inner_strides_type; - using inner_backstrides_type = typename base_type::inner_backstrides_type; - using temporary_type = typename semantic_base::temporary_type; - using expression_tag = Tag; - - xarray_container(); - explicit xarray_container(const shape_type& shape, layout_type l = L); - explicit xarray_container(const shape_type& shape, const_reference value, layout_type l = L); - explicit xarray_container(const shape_type& shape, const strides_type& strides); - explicit xarray_container(const shape_type& shape, const strides_type& strides, const_reference value); - explicit xarray_container(storage_type&& storage, inner_shape_type&& shape, inner_strides_type&& strides); - - xarray_container(const value_type& t); - xarray_container(nested_initializer_list_t t); - xarray_container(nested_initializer_list_t t); - xarray_container(nested_initializer_list_t t); - xarray_container(nested_initializer_list_t t); - xarray_container(nested_initializer_list_t t); - - template - static xarray_container from_shape(S&& s); - - ~xarray_container() = default; - - xarray_container(const xarray_container&) = default; - xarray_container& operator=(const xarray_container&) = default; - - xarray_container(xarray_container&&) = default; - xarray_container& operator=(xarray_container&&) = default; - - template - explicit xarray_container(xtensor_container&& rhs); - template - xarray_container& operator=(xtensor_container&& rhs); - - template - xarray_container(const xexpression& e); - - template - xarray_container& operator=(const xexpression& e); - - private: - - storage_type m_storage; - - storage_type& storage_impl() noexcept; - const storage_type& storage_impl() const noexcept; - - friend class xcontainer>; - }; - - /****************************** - * xarray_adaptor declaration * - ******************************/ - - namespace extension - { - template - struct xarray_adaptor_base; - - template - struct xarray_adaptor_base - { - using type = xtensor_empty_base; - }; - - template - using xarray_adaptor_base_t = typename xarray_adaptor_base::type; - } - - template - struct xcontainer_inner_types> - { - using storage_type = std::remove_reference_t; - using reference = inner_reference_t; - using const_reference = typename storage_type::const_reference; - using size_type = typename storage_type::size_type; - using shape_type = SC; - using strides_type = get_strides_t; - using backstrides_type = get_strides_t; - using inner_shape_type = shape_type; - using inner_strides_type = strides_type; - using inner_backstrides_type = backstrides_type; - using temporary_type = xarray_container, L, SC, Tag>; - static constexpr layout_type layout = L; - }; - - template - struct xiterable_inner_types> - : xcontainer_iterable_types> - { - }; - - /** - * @class xarray_adaptor - * @brief Dense multidimensional container adaptor with - * tensor semantic. - * - * The xarray_adaptor class implements a dense multidimensional - * container adaptor with tensor semantic. It is used to provide - * a multidimensional container semantic and a tensor semantic to - * stl-like containers. - * - * @tparam EC The closure for the container type to adapt. - * @tparam L The layout_type of the adaptor. - * @tparam SC The type of the containers holding the shape and the strides. - * @tparam Tag The expression tag. - * @sa xstrided_container, xcontainer - */ - template - class xarray_adaptor : public xstrided_container>, - public xcontainer_semantic>, - public extension::xarray_adaptor_base_t - { - public: - - using container_closure_type = EC; - - using self_type = xarray_adaptor; - using base_type = xstrided_container; - using semantic_base = xcontainer_semantic; - using extension_base = extension::xarray_adaptor_base_t; - using storage_type = typename base_type::storage_type; - using allocator_type = typename base_type::allocator_type; - using shape_type = typename base_type::shape_type; - using strides_type = typename base_type::strides_type; - using backstrides_type = typename base_type::backstrides_type; - using temporary_type = typename semantic_base::temporary_type; - using expression_tag = Tag; - - xarray_adaptor(storage_type&& storage); - xarray_adaptor(const storage_type& storage); - - template - xarray_adaptor(D&& storage, const shape_type& shape, layout_type l = L); - - template - xarray_adaptor(D&& storage, const shape_type& shape, const strides_type& strides); - - ~xarray_adaptor() = default; - - xarray_adaptor(const xarray_adaptor&) = default; - xarray_adaptor& operator=(const xarray_adaptor&); - - xarray_adaptor(xarray_adaptor&&) = default; - xarray_adaptor& operator=(xarray_adaptor&&); - xarray_adaptor& operator=(temporary_type&&); - - template - xarray_adaptor& operator=(const xexpression& e); - - private: - - container_closure_type m_storage; - - storage_type& storage_impl() noexcept; - const storage_type& storage_impl() const noexcept; - - friend class xcontainer>; - }; - - /*********************************** - * xarray_container implementation * - ***********************************/ - - /** - * @name Constructors - */ - //@{ - /** - * Allocates an uninitialized xarray_container that holds 0 element. - */ - template - inline xarray_container::xarray_container() - : base_type(), m_storage(1, value_type()) - { - } - - /** - * Allocates an uninitialized xarray_container with the specified shape and - * layout_type. - * @param shape the shape of the xarray_container - * @param l the layout_type of the xarray_container - */ - template - inline xarray_container::xarray_container(const shape_type& shape, layout_type l) - : base_type() - { - base_type::resize(shape, l); - } - - /** - * Allocates an xarray_container with the specified shape and layout_type. Elements - * are initialized to the specified value. - * @param shape the shape of the xarray_container - * @param value the value of the elements - * @param l the layout_type of the xarray_container - */ - template - inline xarray_container::xarray_container(const shape_type& shape, const_reference value, layout_type l) - : base_type() - { - base_type::resize(shape, l); - std::fill(m_storage.begin(), m_storage.end(), value); - } - - /** - * Allocates an uninitialized xarray_container with the specified shape and strides. - * @param shape the shape of the xarray_container - * @param strides the strides of the xarray_container - */ - template - inline xarray_container::xarray_container(const shape_type& shape, const strides_type& strides) - : base_type() - { - base_type::resize(shape, strides); - } - - /** - * Allocates an uninitialized xarray_container with the specified shape and strides. - * Elements are initialized to the specified value. - * @param shape the shape of the xarray_container - * @param strides the strides of the xarray_container - * @param value the value of the elements - */ - template - inline xarray_container::xarray_container(const shape_type& shape, const strides_type& strides, const_reference value) - : base_type() - { - base_type::resize(shape, strides); - std::fill(m_storage.begin(), m_storage.end(), value); - } - - /** - * Allocates an xarray_container that holds a single element initialized to the - * specified value. - * @param t the value of the element - */ - template - inline xarray_container::xarray_container(const value_type& t) - : base_type() - { - base_type::resize(xt::shape(t), true); - nested_copy(m_storage.begin(), t); - } - - /** - * Allocates an xarray_container by moving specified data, shape and strides - * - * @param storage the data for the xarray_container - * @param shape the shape of the xarray_container - * @param strides the strides of the xarray_container - */ - template - inline xarray_container::xarray_container(storage_type&& storage, inner_shape_type&& shape, inner_strides_type&& strides) - : base_type(std::move(shape), std::move(strides)), m_storage(std::move(storage)) - { - } - //@} - - /** - * @name Constructors from initializer list - */ - //@{ - /** - * Allocates a one-dimensional xarray_container. - * @param t the elements of the xarray_container - */ - template - inline xarray_container::xarray_container(nested_initializer_list_t t) - : base_type() - { - base_type::resize(xt::shape(t)); - L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin(), t); - } - - /** - * Allocates a two-dimensional xarray_container. - * @param t the elements of the xarray_container - */ - template - inline xarray_container::xarray_container(nested_initializer_list_t t) - : base_type() - { - base_type::resize(xt::shape(t)); - L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin(), t); - } - - /** - * Allocates a three-dimensional xarray_container. - * @param t the elements of the xarray_container - */ - template - inline xarray_container::xarray_container(nested_initializer_list_t t) - : base_type() - { - base_type::resize(xt::shape(t)); - L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin(), t); - } - - /** - * Allocates a four-dimensional xarray_container. - * @param t the elements of the xarray_container - */ - template - inline xarray_container::xarray_container(nested_initializer_list_t t) - : base_type() - { - base_type::resize(xt::shape(t)); - L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin(), t); - } - - /** - * Allocates a five-dimensional xarray_container. - * @param t the elements of the xarray_container - */ - template - inline xarray_container::xarray_container(nested_initializer_list_t t) - : base_type() - { - base_type::resize(xt::shape(t)); - L == layout_type::row_major ? nested_copy(m_storage.begin(), t) : nested_copy(this->template begin(), t); - } - //@} - - /** - * Allocates and returns an xarray_container with the specified shape. - * @param s the shape of the xarray_container - */ - template - template - inline xarray_container xarray_container::from_shape(S&& s) - { - shape_type shape = xtl::forward_sequence(s); - return self_type(shape); - } - - template - template - inline xarray_container::xarray_container(xtensor_container&& rhs) - : base_type(inner_shape_type(rhs.shape().cbegin(), rhs.shape().cend()), - inner_strides_type(rhs.strides().cbegin(), rhs.strides().cend()), - inner_backstrides_type(rhs.backstrides().cbegin(), rhs.backstrides().cend()), - std::move(rhs.layout())), - m_storage(std::move(rhs.storage())) - { - } - - template - template - inline xarray_container& xarray_container::operator=(xtensor_container&& rhs) - { - this->shape_impl().assign(rhs.shape().cbegin(), rhs.shape().cend()); - this->strides_impl().assign(rhs.strides().cbegin(), rhs.strides().cend()); - this->backstrides_impl().assign(rhs.backstrides().cbegin(), rhs.backstrides().cend()); - this->mutable_layout() = rhs.layout(); - m_storage = std::move(rhs.storage()); - return *this; - } - - /** - * @name Extended copy semantic - */ - //@{ - /** - * The extended copy constructor. - */ - template - template - inline xarray_container::xarray_container(const xexpression& e) - : base_type() - { - // Avoids unintialized data because of (m_shape == shape) condition - // in resize (called by assign), which is always true when dimension == 0. - if (e.derived_cast().dimension() == 0) - { - detail::resize_data_container(m_storage, std::size_t(1)); - } - semantic_base::assign(e); - } - - /** - * The extended assignment operator. - */ - template - template - inline auto xarray_container::operator=(const xexpression& e) -> self_type& - { - return semantic_base::operator=(e); - } - //@} - - template - inline auto xarray_container::storage_impl() noexcept -> storage_type& - { - return m_storage; - } - - template - inline auto xarray_container::storage_impl() const noexcept -> const storage_type& - { - return m_storage; - } - - /****************** - * xarray_adaptor * - ******************/ - - /** - * @name Constructors - */ - //@{ - /** - * Constructs an xarray_adaptor of the given stl-like container. - * @param storage the container to adapt - */ - template - inline xarray_adaptor::xarray_adaptor(storage_type&& storage) - : base_type(), m_storage(std::move(storage)) - { - } - - /** - * Constructs an xarray_adaptor of the given stl-like container. - * @param storage the container to adapt - */ - template - inline xarray_adaptor::xarray_adaptor(const storage_type& storage) - : base_type(), m_storage(storage) - { - } - - /** - * Constructs an xarray_adaptor of the given stl-like container, - * with the specified shape and layout_type. - * @param storage the container to adapt - * @param shape the shape of the xarray_adaptor - * @param l the layout_type of the xarray_adaptor - */ - template - template - inline xarray_adaptor::xarray_adaptor(D&& storage, const shape_type& shape, layout_type l) - : base_type(), m_storage(std::forward(storage)) - { - base_type::resize(shape, l); - } - - /** - * Constructs an xarray_adaptor of the given stl-like container, - * with the specified shape and strides. - * @param storage the container to adapt - * @param shape the shape of the xarray_adaptor - * @param strides the strides of the xarray_adaptor - */ - template - template - inline xarray_adaptor::xarray_adaptor(D&& storage, const shape_type& shape, const strides_type& strides) - : base_type(), m_storage(std::forward(storage)) - { - base_type::resize(shape, strides); - } - //@} - - template - inline auto xarray_adaptor::operator=(const xarray_adaptor& rhs) -> self_type& - { - base_type::operator=(rhs); - m_storage = rhs.m_storage; - return *this; - } - - template - inline auto xarray_adaptor::operator=(xarray_adaptor&& rhs) -> self_type& - { - base_type::operator=(std::move(rhs)); - m_storage = rhs.m_storage; - return *this; - } - - template - inline auto xarray_adaptor::operator=(temporary_type&& rhs) -> self_type& - { - base_type::shape_impl() = std::move(const_cast(rhs.shape())); - base_type::strides_impl() = std::move(const_cast(rhs.strides())); - base_type::backstrides_impl() = std::move(const_cast(rhs.backstrides())); - m_storage = std::move(rhs.storage()); - return *this; - } - - /** - * @name Extended copy semantic - */ - //@{ - /** - * The extended assignment operator. - */ - template - template - inline auto xarray_adaptor::operator=(const xexpression& e) -> self_type& - { - return semantic_base::operator=(e); - } - //@} - - template - inline auto xarray_adaptor::storage_impl() noexcept -> storage_type& - { - return m_storage; - } - - template - inline auto xarray_adaptor::storage_impl() const noexcept -> const storage_type& - { - return m_storage; - } -} - -#endif diff --git a/vendor/xtensor/include/xtensor/xassign.hpp b/vendor/xtensor/include/xtensor/xassign.hpp deleted file mode 100644 index 86ea51ff30..0000000000 --- a/vendor/xtensor/include/xtensor/xassign.hpp +++ /dev/null @@ -1,922 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_ASSIGN_HPP -#define XTENSOR_ASSIGN_HPP - -#include -#include -#include - -#include - -#include "xexpression.hpp" -#include "xiterator.hpp" -#include "xstrides.hpp" -#include "xtensor_forward.hpp" -#include "xutils.hpp" -#include "xfunction.hpp" - -#if defined(XTENSOR_USE_TBB) -#include -#endif - -namespace xt -{ - - /******************** - * Assign functions * - ********************/ - - template - void assign_data(xexpression& e1, const xexpression& e2, bool trivial); - - template - void assign_xexpression(xexpression& e1, const xexpression& e2); - - template - void computed_assign(xexpression& e1, const xexpression& e2); - - template - void scalar_computed_assign(xexpression& e1, const E2& e2, F&& f); - - template - void assert_compatible_shape(const xexpression& e1, const xexpression& e2); - - template - void strided_assign(E1& e1, const E2& e2, std::false_type /*disable*/); - - template - void strided_assign(E1& e1, const E2& e2, std::true_type /*enable*/); - - /************************ - * xexpression_assigner * - ************************/ - - template - class xexpression_assigner_base; - - template <> - class xexpression_assigner_base - { - public: - - template - static void assign_data(xexpression& e1, const xexpression& e2, bool trivial); - }; - - template - class xexpression_assigner : public xexpression_assigner_base - { - public: - - using base_type = xexpression_assigner_base; - - template - static void assign_xexpression(E1& e1, const E2& e2); - - template - static void computed_assign(xexpression& e1, const xexpression& e2); - - template - static void scalar_computed_assign(xexpression& e1, const E2& e2, F&& f); - - template - static void assert_compatible_shape(const xexpression& e1, const xexpression& e2); - - private: - - template - static bool resize(E1& e1, const E2& e2); - - template - static bool resize(E1& e1, const xfunction& e2); - - }; - - /******************** - * stepper_assigner * - ********************/ - - template - class stepper_assigner - { - public: - - using lhs_iterator = typename E1::stepper; - using rhs_iterator = typename E2::const_stepper; - using shape_type = typename E1::shape_type; - using index_type = xindex_type_t; - using size_type = typename lhs_iterator::size_type; - using difference_type = typename lhs_iterator::difference_type; - - stepper_assigner(E1& e1, const E2& e2); - - void run(); - - void step(size_type i); - void step(size_type i, size_type n); - void reset(size_type i); - - void to_end(layout_type); - - private: - - E1& m_e1; - - lhs_iterator m_lhs; - rhs_iterator m_rhs; - - index_type m_index; - }; - - /******************* - * linear_assigner * - *******************/ - - template - class linear_assigner - { - public: - - template - static void run(E1& e1, const E2& e2); - }; - - template <> - class linear_assigner - { - public: - - template - static void run(E1& e1, const E2& e2); - - private: - - template - static void run_impl(E1& e1, const E2& e2, std::true_type); - - template - static void run_impl(E1& e1, const E2& e2, std::false_type); - }; - - /************************* - * strided_loop_assigner * - *************************/ - - template - class strided_loop_assigner - { - public: - - template - static void run(E1& e1, const E2& e2); - }; - - /*********************************** - * Assign functions implementation * - ***********************************/ - - template - inline void assign_data(xexpression& e1, const xexpression& e2, bool trivial) - { - using tag = xexpression_tag_t; - xexpression_assigner::assign_data(e1, e2, trivial); - } - - template - inline void assign_xexpression(xexpression& e1, const xexpression& e2) - { - xtl::mpl::static_if::value>([&](auto self) - { - self(e2).derived_cast().assign_to(e1); - }, /*else*/ [&](auto /*self*/) - { - using tag = xexpression_tag_t; - xexpression_assigner::assign_xexpression(e1, e2); - }); - } - - template - inline void computed_assign(xexpression& e1, const xexpression& e2) - { - using tag = xexpression_tag_t; - xexpression_assigner::computed_assign(e1, e2); - } - - template - inline void scalar_computed_assign(xexpression& e1, const E2& e2, F&& f) - { - using tag = xexpression_tag_t; - xexpression_assigner::scalar_computed_assign(e1, e2, std::forward(f)); - } - - template - inline void assert_compatible_shape(const xexpression& e1, const xexpression& e2) - { - using tag = xexpression_tag_t; - xexpression_assigner::assert_compatible_shape(e1, e2); - } - - /*************************************** - * xexpression_assigner implementation * - ***************************************/ - - namespace detail - { - template - constexpr bool linear_static_layout() - { - // A row_major or column_major container with a dimension <= 1 is computed as - // layout any, leading to some performance improvements, for example when - // assigning a col-major vector to a row-major vector etc - return compute_layout(select_layout::value, - select_layout::value) != layout_type::dynamic; - } - - template - inline auto is_linear_assign(const E1& e1, const E2& e2) -> std::enable_if_t::value, bool> - { - return (E1::contiguous_layout && E2::contiguous_layout && linear_static_layout()) || - (e1.layout() != layout_type::dynamic && e2.has_linear_assign(e1.strides())); - } - - template - inline auto is_linear_assign(const E1&, const E2&) -> std::enable_if_t::value, bool> - { - return false; - } - - template - struct has_step_leading : std::false_type - { - }; - - template - struct has_step_leading().step_leading())>> - : std::true_type - { - }; - - template - struct use_strided_loop - { - static constexpr bool stepper_deref() { return std::is_reference::value; } - static constexpr bool value = has_strides::value && has_step_leading::value && stepper_deref(); - }; - - template - struct use_strided_loop> - { - static constexpr bool value = true; - }; - - template - struct use_strided_loop> - { - static constexpr bool value = xtl::conjunction>...>::value; - }; - } - - template - class xassign_traits - { - private: - - using e1_value_type = typename E1::value_type; - using e2_value_type = typename E2::value_type; - - template - using is_bool = std::is_same; - - static constexpr bool contiguous_layout() { return E1::contiguous_layout && E2::contiguous_layout; } - static constexpr bool convertible_types() { return std::is_convertible::value; } - - static constexpr bool use_xsimd() { return xt_simd::simd_traits::size > 1; } - - template - static constexpr bool simd_size_impl() { return xt_simd::simd_traits::size > 1 || (is_bool::value && use_xsimd()); } - static constexpr bool simd_size() { return simd_size_impl() && simd_size_impl(); } - static constexpr bool simd_interface() { return has_simd_interface(); } - static constexpr bool simd_assign() { return convertible_types() && simd_size() && simd_interface(); } - - public: - - // constexpr methods instead of constexpr data members avoid the need of definitions at namespace - // scope of these data members (since they are odr-used). - - static constexpr bool linear_assign(const E1& e1, const E2& e2, bool trivial) { return trivial && detail::is_linear_assign(e1, e2); } - static constexpr bool strided_assign() { return detail::use_strided_loop::value && detail::use_strided_loop::value; } - static constexpr bool simd_linear_assign() { return contiguous_layout() && simd_assign(); } - static constexpr bool simd_strided_assign() { return strided_assign() && simd_assign(); } - - using requested_value_type = std::conditional_t::value, - typename E2::bool_load_type, - e2_value_type>; - - }; - - template - inline void xexpression_assigner_base::assign_data(xexpression& e1, const xexpression& e2, bool trivial) - { - E1& de1 = e1.derived_cast(); - const E2& de2 = e2.derived_cast(); - using traits = xassign_traits; - - bool linear_assign = traits::linear_assign(de1, de2, trivial); - constexpr bool simd_linear_assign = traits::simd_linear_assign(); - constexpr bool simd_strided_assign = traits::simd_strided_assign(); - if (linear_assign) - { - linear_assigner::run(de1, de2); - } - else if (simd_strided_assign) - { - strided_loop_assigner::run(de1, de2); - } - else - { - stepper_assigner assigner(de1, de2); - assigner.run(); - } - } - - template - template - inline void xexpression_assigner::assign_xexpression(E1& e1, const E2& e2) - { - bool trivial_broadcast = resize(e1.derived_cast(), e2.derived_cast()); - base_type::assign_data(e1, e2, trivial_broadcast); - } - - template - template - inline void xexpression_assigner::computed_assign(xexpression& e1, const xexpression& e2) - { - using shape_type = typename E1::shape_type; - using size_type = typename E1::size_type; - - E1& de1 = e1.derived_cast(); - const E2& de2 = e2.derived_cast(); - - size_type dim = de2.dimension(); - shape_type shape = uninitialized_shape(dim); - bool trivial_broadcast = de2.broadcast_shape(shape, true); - - if (dim > de1.dimension() || shape > de1.shape()) - { - typename E1::temporary_type tmp(shape); - base_type::assign_data(tmp, e2, trivial_broadcast); - de1.assign_temporary(std::move(tmp)); - } - else - { - base_type::assign_data(e1, e2, trivial_broadcast); - } - } - - template - template - inline void xexpression_assigner::scalar_computed_assign(xexpression& e1, const E2& e2, F&& f) - { - E1& d = e1.derived_cast(); - using size_type = typename E1::size_type; - auto dst = d.storage().begin(); - for (size_type i = d.size(); i > 0; --i) - { - *dst = f(*dst, e2); - ++dst; - } - } - - template - template - inline void xexpression_assigner::assert_compatible_shape(const xexpression& e1, const xexpression& e2) - { - const E1& de1 = e1.derived_cast(); - const E2& de2 = e2.derived_cast(); - if (!broadcastable(de2.shape(), de1.shape())) - { - throw_broadcast_error(de2.shape(), de1.shape()); - } - } - - namespace detail - { - template - struct static_trivial_broadcast; - - template - struct static_trivial_broadcast - { - static constexpr bool value = detail::promote_index::shape_type...>::value; - }; - - template - struct static_trivial_broadcast - { - static constexpr bool value = false; - }; - } - - template - template - inline bool xexpression_assigner::resize(E1& e1, const E2& e2) - { - // If our RHS is not a xfunction, we know that the RHS is at least potentially trivial - // We check the strides of the RHS in detail::is_trivial_broadcast to see if they match up! - // So we can skip a shape copy and a call to broadcast_shape(...) - e1.resize(e2.shape()); - return true; - } - - template - template - inline bool xexpression_assigner::resize(E1& e1, const xfunction& e2) - { - return xtl::mpl::static_if::shape_type>::value>( - [&](auto /*self*/) { - /* - * If the shape of the xfunction is statically known, we can compute the broadcast triviality - * at compile time plus we can resize right away. - */ - // resize in case LHS is not a fixed size container. If it is, this is a NOP - e1.resize(typename xfunction::shape_type{}); - return detail::static_trivial_broadcast::shape_type>::value, CT...>::value; - }, - /* else */ [&](auto /*self*/) - { - using index_type = xindex_type_t; - using size_type = typename E1::size_type; - size_type size = e2.dimension(); - index_type shape = uninitialized_shape(size); - bool trivial_broadcast = e2.broadcast_shape(shape, true); - e1.resize(std::move(shape)); - return trivial_broadcast; - } - ); - } - - /*********************************** - * stepper_assigner implementation * - ***********************************/ - - template - struct is_narrowing_conversion - { - using argument_type = std::decay_t; - using result_type = std::decay_t; - - static const bool value = std::is_arithmetic::value && - (sizeof(result_type) < sizeof(argument_type) || - (std::is_integral::value && std::is_floating_point::value)); - }; - - template - struct has_sign_conversion - { - using argument_type = std::decay_t; - using result_type = std::decay_t; - - static const bool value = std::is_signed::value != std::is_signed::value; - }; - - template - struct has_assign_conversion - { - using argument_type = std::decay_t; - using result_type = std::decay_t; - - static const bool value = is_narrowing_conversion::value || - has_sign_conversion::value; - }; - - template - inline stepper_assigner::stepper_assigner(E1& e1, const E2& e2) - : m_e1(e1), m_lhs(e1.stepper_begin(e1.shape())), - m_rhs(e2.stepper_begin(e1.shape())), - m_index(xtl::make_sequence(e1.shape().size(), size_type(0))) - { - } - - template - inline void stepper_assigner::run() - { - using size_type = typename E1::size_type; - using argument_type = std::decay_t; - using result_type = std::decay_t; - constexpr bool needs_cast = has_assign_conversion::value; - - size_type s = m_e1.size(); - for (size_type i = 0; i < s; ++i) - { - *m_lhs = conditional_cast(*m_rhs); - stepper_tools::increment_stepper(*this, m_index, m_e1.shape()); - } - } - - template - inline void stepper_assigner::step(size_type i) - { - m_lhs.step(i); - m_rhs.step(i); - } - - template - inline void stepper_assigner::step(size_type i, size_type n) - { - m_lhs.step(i, n); - m_rhs.step(i, n); - } - - template - inline void stepper_assigner::reset(size_type i) - { - m_lhs.reset(i); - m_rhs.reset(i); - } - - template - inline void stepper_assigner::to_end(layout_type l) - { - m_lhs.to_end(l); - m_rhs.to_end(l); - } - - /********************************** - * linear_assigner implementation * - **********************************/ - - template - template - inline void linear_assigner::run(E1& e1, const E2& e2) - { - using lhs_align_mode = xt_simd::container_alignment_t; - constexpr bool is_aligned = std::is_same::value; - using rhs_align_mode = std::conditional_t; - using e1_value_type = typename E1::value_type; - using e2_value_type = typename E2::value_type; - using value_type = typename xassign_traits::requested_value_type; - using simd_type = xt_simd::simd_type; - using size_type = typename E1::size_type; - size_type size = e1.size(); - constexpr size_type simd_size = simd_type::size; - constexpr bool needs_cast = has_assign_conversion::value; - - size_type align_begin = is_aligned ? 0 : xt_simd::get_alignment_offset(e1.data(), size, simd_size); - size_type align_end = align_begin + ((size - align_begin) & ~(simd_size - 1)); - - for (size_type i = 0; i < align_begin; ++i) - { - e1.data_element(i) = conditional_cast(e2.data_element(i)); - } - -#if defined(XTENSOR_USE_TBB) - tbb::parallel_for(align_begin, align_end, simd_size, [&](size_t i) - { - e1.template store_simd(i, e2.template load_simd(i)); - }); -#elif defined(XTENSOR_USE_OPENMP) - #pragma omp parallel for default(none) shared(align_begin, align_end, e1, e2) - for (size_type i = align_begin; i < align_end; i += simd_size) - { - e1.template store_simd(i, e2.template load_simd(i)); - } -#else - for (size_type i = align_begin; i < align_end; i += simd_size) - { - e1.template store_simd(i, e2.template load_simd(i)); - } -#endif - for (size_type i = align_end; i < size; ++i) - { - e1.data_element(i) = conditional_cast(e2.data_element(i)); - } - } - - template - inline void linear_assigner::run(E1& e1, const E2& e2) - { - using is_convertible = std::is_convertible::value_type, - typename std::decay_t::value_type>; - // If the types are not compatible, this function is still instantiated but never called. - // To avoid compilation problems in effectively unused code trivial_assigner_run_impl is - // empty in this case. - run_impl(e1, e2, is_convertible()); - } - - template - inline void linear_assigner::run_impl(E1& e1, const E2& e2, std::true_type /*is_convertible*/) - { - using value_type = typename E1::value_type; - using size_type = typename E1::size_type; - auto src = linear_begin(e2); - auto dst = linear_begin(e1); - size_type n = e1.size(); - -#if defined(XTENSOR_USE_TBB) - tbb::parallel_for(std::ptrdiff_t(0), static_cast(n), [&](std::ptrdiff_t i) - { - *(dst + i) = static_cast(*(src + i)); - }); -#elif defined(XTENSOR_USE_OPENMP) - #pragma omp parallel for default(none) shared(src, dst, n) - for (std::ptrdiff_t i = std::ptrdiff_t(0); i < static_cast(n) ; i++) - { - *(dst + i) = static_cast(*(src + i)); - } -#else - for (; n > size_type(0); --n) - { - *dst = static_cast(*src); - ++src; - ++dst; - } -#endif - } - - template - inline void linear_assigner::run_impl(E1&, const E2&, std::false_type /*is_convertible*/) - { - XTENSOR_PRECONDITION(false, - "Internal error: linear_assigner called with unrelated types."); - - } - - /**************************************** - * strided_loop_assigner implementation * - ****************************************/ - - namespace strided_assign_detail - { - template - struct idx_tools; - - template <> - struct idx_tools - { - template - static void next_idx(T& outer_index, T& outer_shape) - { - auto i = outer_index.size(); - for (; i > 0; --i) - { - if (outer_index[i - 1] + 1 >= outer_shape[i - 1]) - { - outer_index[i - 1] = 0; - } - else - { - outer_index[i - 1]++; - break; - } - } - } - }; - - template <> - struct idx_tools - { - template - static void next_idx(T& outer_index, T& outer_shape) - { - using size_type = typename T::size_type; - size_type i = 0; - auto sz = outer_index.size(); - for (; i < sz; ++i) - { - if (outer_index[i] + 1 >= outer_shape[i]) - { - outer_index[i] = 0; - } - else - { - outer_index[i]++; - break; - } - } - } - }; - - template - struct check_strides_functor - { - using strides_type = S; - - check_strides_functor(const S& strides) - : m_cut(L == layout_type::row_major ? 0 : strides.size()), - m_strides(strides) - { - } - - template - std::enable_if_t - operator()(const T& el) - { - auto var = check_strides_overlap::get(m_strides, el.strides()); - if (var > m_cut) - { - m_cut = var; - } - return m_cut; - } - - template - std::enable_if_t - operator()(const T& el) - { - auto var = check_strides_overlap::get(m_strides, el.strides()); - if (var < m_cut) - { - m_cut = var; - } - return m_cut; - } - - template - std::size_t operator()(const xt::xscalar& /*el*/) - { - return m_cut; - } - - template - std::size_t operator()(const xt::xfunction& xf) - { - xt::for_each(*this, xf.arguments()); - return m_cut; - } - - private: - - std::size_t m_cut; - const strides_type& m_strides; - }; - - template - auto get_loop_sizes(const E1& e1, const E2& e2, bool is_row_major) - { - std::size_t cut = 0; - - // TODO! if E1 is !contiguous --> initialize cut to sensible value! - if (E1::static_layout == layout_type::row_major || is_row_major) - { - auto csf = check_strides_functor(e1.strides()); - cut = csf(e2); - } - else if (E1::static_layout == layout_type::column_major || !is_row_major) - { - auto csf = check_strides_functor(e1.strides()); - cut = csf(e2); - } // can't reach here because this would have already triggered the fallback - - using shape_value_type = typename E1::shape_type::value_type; - std::size_t outer_loop_size = static_cast( - std::accumulate(e1.shape().begin(), e1.shape().begin() + static_cast(cut), - shape_value_type(1), std::multiplies{})); - std::size_t inner_loop_size = static_cast( - std::accumulate(e1.shape().begin() + static_cast(cut), e1.shape().end(), - shape_value_type(1), std::multiplies{})); - - if (E1::static_layout == layout_type::column_major || !is_row_major) - { - std::swap(outer_loop_size, inner_loop_size); - } - - return std::make_tuple(inner_loop_size, outer_loop_size, cut); - } - } - - template - template - inline void strided_loop_assigner::run(E1& e1, const E2& e2) - { - bool is_row_major = true; - using fallback_assigner = stepper_assigner; - - if (E1::static_layout == layout_type::dynamic) - { - layout_type dynamic_layout = e1.layout(); - switch (dynamic_layout) - { - case layout_type::row_major: - is_row_major = true; - break; - case layout_type::column_major: - is_row_major = false; - break; - default: - return fallback_assigner(e1, e2).run(); - } - } - else if (E1::static_layout == layout_type::row_major) - { - is_row_major = true; - } - else if (E1::static_layout == layout_type::column_major) - { - is_row_major = false; - } - else - { - throw std::runtime_error("Illegal layout set (layout_type::any?)."); - } - - std::size_t inner_loop_size, outer_loop_size, cut; - std::tie(inner_loop_size, outer_loop_size, cut) = strided_assign_detail::get_loop_sizes(e1, e2, is_row_major); - - if ((is_row_major && cut == e1.dimension()) || (!is_row_major && cut == 0)) - { - return fallback_assigner(e1, e2).run(); - } - - // TODO can we get rid of this and use `shape_type`? - dynamic_shape idx, max_shape; - - if (is_row_major) - { - xt::resize_container(idx, cut); - max_shape.assign(e1.shape().begin(), e1.shape().begin() + static_cast(cut)); - } - else - { - xt::resize_container(idx, e1.shape().size() - cut); - max_shape.assign(e1.shape().begin() + static_cast(cut), e1.shape().end()); - } - - // add this when we have std::array index! - // std::fill(idx.begin(), idx.end(), 0); - using e1_value_type = typename E1::value_type; - using e2_value_type = typename E2::value_type; - constexpr bool needs_cast = has_assign_conversion::value; - using value_type = typename xassign_traits::requested_value_type; - using simd_type = std::conditional_t::value, - xt_simd::simd_bool_type, - xt_simd::simd_type>; - - std::size_t simd_size = inner_loop_size / simd_type::size; - std::size_t simd_rest = inner_loop_size % simd_type::size; - - auto fct_stepper = e2.stepper_begin(e1.shape()); - auto res_stepper = e1.stepper_begin(e1.shape()); - - // TODO in 1D case this is ambigous -- could be RM or CM. - // Use default layout to make decision - std::size_t step_dim = 0; - if (!is_row_major) // row major case - { - step_dim = cut; - } - - for (std::size_t ox = 0; ox < outer_loop_size; ++ox) - { - for (std::size_t i = 0; i < simd_size; ++i) - { - res_stepper.template store_simd(fct_stepper.template step_simd()); - } - for (std::size_t i = 0; i < simd_rest; ++i) - { - *(res_stepper) = conditional_cast(*(fct_stepper)); - res_stepper.step_leading(); - fct_stepper.step_leading(); - } - - is_row_major ? - strided_assign_detail::idx_tools::next_idx(idx, max_shape) : - strided_assign_detail::idx_tools::next_idx(idx, max_shape); - - fct_stepper.to_begin(); - - // need to step E1 as well if not contigous assign (e.g. view) - if (!E1::contiguous_layout) - { - res_stepper.to_begin(); - for (std::size_t i = 0; i < idx.size(); ++i) - { - fct_stepper.step(i + step_dim, idx[i]); - res_stepper.step(i + step_dim, idx[i]); - } - } - else - { - for (std::size_t i = 0; i < idx.size(); ++i) - { - fct_stepper.step(i + step_dim, idx[i]); - } - } - } - } - - template <> - template - inline void strided_loop_assigner::run(E1& /*e1*/, const E2& /*e2*/) - { - } -} - -#endif diff --git a/vendor/xtensor/include/xtensor/xaxis_iterator.hpp b/vendor/xtensor/include/xtensor/xaxis_iterator.hpp deleted file mode 100644 index 3c3cfb6322..0000000000 --- a/vendor/xtensor/include/xtensor/xaxis_iterator.hpp +++ /dev/null @@ -1,198 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_AXIS_ITERATOR_HPP -#define XTENSOR_AXIS_ITERATOR_HPP - -#include - -#include "xview.hpp" - -namespace xt -{ - - /****************** - * xaxis_iterator * - ******************/ - - template - class xaxis_iterator - { - public: - - using self_type = xaxis_iterator; - - using xexpression_type = std::decay_t; - using size_type = typename xexpression_type::size_type; - using difference_type = typename xexpression_type::difference_type; - using value_type = xview; - using reference = std::remove_reference_t>; - using pointer = xtl::xclosure_pointer>>; - - using iterator_category = std::forward_iterator_tag; - - xaxis_iterator(); - template - xaxis_iterator(CTA&& e, size_type index); - - self_type& operator++(); - self_type operator++(int); - - reference operator*() const; - pointer operator->() const; - - bool equal(const self_type& rhs) const; - - private: - - using storing_type = xtl::ptr_closure_type_t; - mutable storing_type p_expression; - size_type m_index; - - template - std::enable_if_t::value, std::add_lvalue_reference_t>> - deref(T val) const; - - template - std::enable_if_t::value, T> - deref(T& val) const; - - template - std::enable_if_t::value, T> - get_storage_init(CTA&& e) const; - - template - std::enable_if_t::value, T> - get_storage_init(CTA&& e) const; - }; - - template - bool operator==(const xaxis_iterator& lhs, const xaxis_iterator& rhs); - - template - bool operator!=(const xaxis_iterator& lhs, const xaxis_iterator& rhs); - - template - auto axis_begin(E&& e); - - template - auto axis_end(E&& e); - - /********************************* - * xaxis_iterator implementation * - *********************************/ - - template - template - inline std::enable_if_t::value, std::add_lvalue_reference_t>> - xaxis_iterator::deref(T val) const - { - return *val; - } - - template - template - inline std::enable_if_t::value, T> - xaxis_iterator::deref(T& val) const - { - return val; - } - - template - template - inline std::enable_if_t::value, T> - xaxis_iterator::get_storage_init(CTA&& e) const - { - return &e; - } - - template - template - inline std::enable_if_t::value, T> - xaxis_iterator::get_storage_init(CTA&& e) const - { - return e; - } - - template - inline xaxis_iterator::xaxis_iterator() - : p_expression(nullptr), m_index(0) - { - } - - template - template - inline xaxis_iterator::xaxis_iterator(CTA&& e, size_type index) - : p_expression(get_storage_init(std::forward(e))), m_index(index) - { - } - - template - inline auto xaxis_iterator::operator++() -> self_type& - { - ++m_index; - return *this; - } - - template - inline auto xaxis_iterator::operator++(int) -> self_type - { - self_type tmp(*this); - ++(*this); - return tmp; - } - - template - inline auto xaxis_iterator::operator*() const -> reference - { - return view(deref(p_expression), size_type(m_index)); - } - - template - inline auto xaxis_iterator::operator->() const -> pointer - { - return xtl::closure_pointer(operator*()); - } - - template - inline bool xaxis_iterator::equal(const self_type& rhs) const - { - return p_expression == rhs.p_expression && m_index == rhs.m_index; - } - - template - inline bool operator==(const xaxis_iterator& lhs, const xaxis_iterator& rhs) - { - return lhs.equal(rhs); - } - - template - inline bool operator!=(const xaxis_iterator& lhs, const xaxis_iterator& rhs) - { - return !(lhs == rhs); - } - - template - inline auto axis_begin(E&& e) - { - using return_type = xaxis_iterator>; - using size_type = typename std::decay_t::size_type; - return return_type(std::forward(e), size_type(0)); - } - - template - inline auto axis_end(E&& e) - { - using return_type = xaxis_iterator>; - using size_type = typename std::decay_t::size_type; - return return_type(std::forward(e), size_type(e.shape()[0])); - } -} - -#endif diff --git a/vendor/xtensor/include/xtensor/xbroadcast.hpp b/vendor/xtensor/include/xtensor/xbroadcast.hpp deleted file mode 100644 index 121981dae8..0000000000 --- a/vendor/xtensor/include/xtensor/xbroadcast.hpp +++ /dev/null @@ -1,467 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_BROADCAST_HPP -#define XTENSOR_BROADCAST_HPP - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "xaccessible.hpp" -#include "xexpression.hpp" -#include "xiterable.hpp" -#include "xscalar.hpp" -#include "xstrides.hpp" -#include "xutils.hpp" - -namespace xt -{ - - /************* - * broadcast * - *************/ - - template - auto broadcast(E&& e, const S& s); - -#ifdef X_OLD_CLANG - template - auto broadcast(E&& e, std::initializer_list s); -#else - template - auto broadcast(E&& e, const I (&s)[L]); -#endif - - /************************* - * xbroadcast extensions * - *************************/ - - namespace extension - { - template - struct xbroadcast_base_impl; - - template - struct xbroadcast_base_impl - { - using type = xtensor_empty_base; - }; - - template - struct xbroadcast_base - : xbroadcast_base_impl, CT, X> - { - }; - - template - using xbroadcast_base_t = typename xbroadcast_base::type; - } - - /************** - * xbroadcast * - **************/ - - template - class xbroadcast; - - template - struct xiterable_inner_types> - { - using xexpression_type = std::decay_t; - using inner_shape_type = promote_shape_t; - using const_stepper = typename xexpression_type::const_stepper; - using stepper = const_stepper; - }; - - template - struct xcontainer_inner_types> - { - using xexpression_type = std::decay_t; - using reference = typename xexpression_type::const_reference; - using const_reference = typename xexpression_type::const_reference; - using size_type = typename xexpression_type::size_type; - }; - - /***************************** - * linear_begin / linear_end * - *****************************/ - - template - XTENSOR_CONSTEXPR_RETURN auto linear_begin(xbroadcast& c) noexcept - { - return linear_begin(c.expression()); - } - - template - XTENSOR_CONSTEXPR_RETURN auto linear_end(xbroadcast& c) noexcept - { - return linear_end(c.expression()); - } - - template - XTENSOR_CONSTEXPR_RETURN auto linear_begin(const xbroadcast& c) noexcept - { - return linear_begin(c.expression()); - } - - template - XTENSOR_CONSTEXPR_RETURN auto linear_end(const xbroadcast& c) noexcept - { - return linear_end(c.expression()); - } - - /** - * @class xbroadcast - * @brief Broadcasted xexpression to a specified shape. - * - * The xbroadcast class implements the broadcasting of an \ref xexpression - * to a specified shape. xbroadcast is not meant to be used directly, but - * only with the \ref broadcast helper functions. - * - * @tparam CT the closure type of the \ref xexpression to broadcast - * @tparam X the type of the specified shape. - * - * @sa broadcast - */ - template - class xbroadcast : public xsharable_expression>, - public xconst_iterable>, - public xconst_accessible>, - public extension::xbroadcast_base_t - { - public: - - using self_type = xbroadcast; - using xexpression_type = std::decay_t; - using extension_base = extension::xbroadcast_base_t; - using expression_tag = typename extension_base::expression_tag; - - using inner_types = xcontainer_inner_types; - using value_type = typename xexpression_type::value_type; - using reference = typename inner_types::reference; - using const_reference = typename inner_types::const_reference; - using pointer = typename xexpression_type::const_pointer; - using const_pointer = typename xexpression_type::const_pointer; - using size_type = typename inner_types::size_type; - using difference_type = typename xexpression_type::difference_type; - - using iterable_base = xconst_iterable; - using inner_shape_type = typename iterable_base::inner_shape_type; - using shape_type = inner_shape_type; - - using stepper = typename iterable_base::stepper; - using const_stepper = typename iterable_base::const_stepper; - - using bool_load_type = typename xexpression_type::bool_load_type; - - static constexpr layout_type static_layout = layout_type::dynamic; - static constexpr bool contiguous_layout = false; - - template - xbroadcast(CTA&& e, const S& s); - - template - xbroadcast(CTA&& e, shape_type&& s); - - const inner_shape_type& shape() const noexcept; - size_type shape(size_type i) const noexcept; - layout_type layout() const noexcept; - - template - const_reference operator()(Args... args) const; - - template - const_reference unchecked(Args... args) const; - - template - const_reference element(It first, It last) const; - - const xexpression_type& expression() const noexcept; - - template - bool broadcast_shape(S& shape, bool reuse_cache = false) const; - - template - bool has_linear_assign(const S& strides) const noexcept; - - template - const_stepper stepper_begin(const S& shape) const noexcept; - template - const_stepper stepper_end(const S& shape, layout_type l) const noexcept; - - template ::value>> - void assign_to(xexpression& e) const; - - template - using rebind_t = xbroadcast; - - template - rebind_t build_broadcast(E&& e) const; - - private: - - CT m_e; - inner_shape_type m_shape; - }; - - /**************************** - * broadcast implementation * - ****************************/ - - /** - * @brief Returns an \ref xexpression broadcasting the given expression to - * a specified shape. - * - * @tparam e the \ref xexpression to broadcast - * @tparam s the specified shape to broadcast. - * - * The returned expression either hold a const reference to \p e or a copy - * depending on whether \p e is an lvalue or an rvalue. - */ - template - inline auto broadcast(E&& e, const S& s) - { - using broadcast_type = xbroadcast, S>; - return broadcast_type(std::forward(e), s); - } - -#ifdef X_OLD_CLANG - template - inline auto broadcast(E&& e, std::initializer_list s) - { - using broadcast_type = xbroadcast, std::vector>; - using shape_type = typename broadcast_type::shape_type; - return broadcast_type(std::forward(e), xtl::forward_sequence(s)); - } -#else - template - inline auto broadcast(E&& e, const I (&s)[L]) - { - using broadcast_type = xbroadcast, std::array>; - using shape_type = typename broadcast_type::shape_type; - return broadcast_type(std::forward(e), xtl::forward_sequence(s)); - } -#endif - - /***************************** - * xbroadcast implementation * - *****************************/ - - /** - * @name Constructor - */ - //@{ - /** - * Constructs an xbroadcast expression broadcasting the specified - * \ref xexpression to the given shape - * - * @param e the expression to broadcast - * @param s the shape to apply - */ - template - template - inline xbroadcast::xbroadcast(CTA&& e, const S& s) - : m_e(std::forward(e)) - { - if (s.size() < m_e.dimension()) - { - throw xt::broadcast_error("Broadcast shape has fewer elements than original expression."); - } - xt::resize_container(m_shape, s.size()); - std::copy(s.begin(), s.end(), m_shape.begin()); - xt::broadcast_shape(m_e.shape(), m_shape); - } - - /** - * Constructs an xbroadcast expression broadcasting the specified - * \ref xexpression to the given shape - * - * @param e the expression to broadcast - * @param s the shape to apply - */ - template - template - inline xbroadcast::xbroadcast(CTA&& e, shape_type&& s) - : m_e(std::forward(e)), m_shape(std::move(s)) - { - xt::broadcast_shape(m_e.shape(), m_shape); - } - //@} - - /** - * @name Size and shape - */ - //@{ - /** - * Returns the shape of the expression. - */ - template - inline auto xbroadcast::shape() const noexcept -> const inner_shape_type& - { - return m_shape; - } - - /** - * Returns the shape of the expression. - */ - template - inline auto xbroadcast::shape(size_type i) const noexcept -> size_type - { - return m_shape[i]; - } - - /** - * Returns the layout_type of the expression. - */ - template - inline layout_type xbroadcast::layout() const noexcept - { - return m_e.layout(); - } - //@} - - /** - * @name Data - */ - /** - * Returns a constant reference to the element at the specified position in the expression. - * @param args a list of indices specifying the position in the function. Indices - * must be unsigned integers, the number of indices should be equal or greater than - * the number of dimensions of the expression. - */ - template - template - inline auto xbroadcast::operator()(Args... args) const -> const_reference - { - return m_e(args...); - } - - /** - * Returns a constant reference to the element at the specified position in the expression. - * @param args a list of indices specifying the position in the expression. Indices - * must be unsigned integers, the number of indices must be equal to the number of - * dimensions of the expression, else the behavior is undefined. - * - * @warning This method is meant for performance, for expressions with a dynamic - * number of dimensions (i.e. not known at compile time). Since it may have - * undefined behavior (see parameters), operator() should be prefered whenever - * it is possible. - * @warning This method is NOT compatible with broadcasting, meaning the following - * code has undefined behavior: - * \code{.cpp} - * xt::xarray a = {{0, 1}, {2, 3}}; - * xt::xarray b = {0, 1}; - * auto fd = a + b; - * double res = fd.uncheked(0, 1); - * \endcode - */ - template - template - inline auto xbroadcast::unchecked(Args... args) const -> const_reference - { - return this->operator()(args...); - } - - /** - * Returns a constant reference to the element at the specified position in the expression. - * @param first iterator starting the sequence of indices - * @param last iterator ending the sequence of indices - * The number of indices in the sequence should be equal to or greater - * than the number of dimensions of the function. - */ - template - template - inline auto xbroadcast::element(It, It last) const -> const_reference - { - return m_e.element(last - this->dimension(), last); - } - - /** - * Returns a constant reference to the underlying expression of the broadcast expression. - */ - template - inline auto xbroadcast::expression() const noexcept -> const xexpression_type& - { - return m_e; - } - //@} - - /** - * @name Broadcasting - */ - //@{ - /** - * Broadcast the shape of the function to the specified parameter. - * @param shape the result shape - * @param reuse_cache parameter for internal optimization - * @return a boolean indicating whether the broadcasting is trivial - */ - template - template - inline bool xbroadcast::broadcast_shape(S& shape, bool) const - { - return xt::broadcast_shape(m_shape, shape); - } - - /** - * Checks whether the xbroadcast can be linearly assigned to an expression - * with the specified strides. - * @return a boolean indicating whether a linear assign is possible - */ - template - template - inline bool xbroadcast::has_linear_assign(const S& strides) const noexcept - { - return this->dimension() == m_e.dimension() && - std::equal(m_shape.cbegin(), m_shape.cend(), m_e.shape().cbegin()) && - m_e.has_linear_assign(strides); - } - //@} - - template - template - inline auto xbroadcast::stepper_begin(const S& shape) const noexcept -> const_stepper - { - // Could check if (broadcastable(shape, m_shape) - return m_e.stepper_begin(shape); - } - - template - template - inline auto xbroadcast::stepper_end(const S& shape, layout_type l) const noexcept -> const_stepper - { - // Could check if (broadcastable(shape, m_shape) - return m_e.stepper_end(shape, l); - } - - template - template - inline void xbroadcast::assign_to(xexpression& e) const - { - auto& ed = e.derived_cast(); - ed.resize(m_shape); - std::fill(ed.begin(), ed.end(), m_e()); - } - - template - template - inline auto xbroadcast::build_broadcast(E&& e) const -> rebind_t - { - return rebind_t(std::forward(e), inner_shape_type(m_shape)); - } -} - -#endif diff --git a/vendor/xtensor/include/xtensor/xbuffer_adaptor.hpp b/vendor/xtensor/include/xtensor/xbuffer_adaptor.hpp deleted file mode 100644 index 6bec4f3bef..0000000000 --- a/vendor/xtensor/include/xtensor/xbuffer_adaptor.hpp +++ /dev/null @@ -1,980 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_BUFFER_ADAPTOR_HPP -#define XTENSOR_BUFFER_ADAPTOR_HPP - -#include -#include -#include -#include -#include - -#include - -#include "xstorage.hpp" - -namespace xt -{ - - struct no_ownership - { - }; - - using smart_ownership = no_ownership; - - struct acquire_ownership - { - }; - - template >>> - class xbuffer_adaptor; - - /******************** - * buffer_storage_t * - ********************/ - - namespace detail - { - template - class xbuffer_storage - { - public: - - using self_type = xbuffer_storage; - using allocator_type = A; - using destructor_type = allocator_type; - using value_type = typename allocator_type::value_type; - using reference = std::conditional_t>>::value, - typename allocator_type::const_reference, - typename allocator_type::reference>; - using const_reference = typename allocator_type::const_reference; - using pointer = std::conditional_t>>::value, - typename allocator_type::const_pointer, - typename allocator_type::pointer>; - using const_pointer = typename allocator_type::const_pointer; - using size_type = typename allocator_type::size_type; - using difference_type = typename allocator_type::difference_type; - - xbuffer_storage(); - - template - xbuffer_storage(P&& data, size_type size, const allocator_type& alloc = allocator_type()); - - size_type size() const noexcept; - void resize(size_type size); - - pointer data() noexcept; - const_pointer data() const noexcept; - - void swap(self_type& rhs) noexcept; - - private: - - pointer p_data; - size_type m_size; - }; - - template - class xbuffer_smart_pointer - { - public: - - using self_type = xbuffer_storage; - using destructor_type = D; - using value_type = std::remove_const_t>>; - using allocator_type = std::allocator; - using reference = std::conditional_t>>::value, - typename allocator_type::const_reference, - typename allocator_type::reference>; - using const_reference = typename allocator_type::const_reference; - using pointer = std::conditional_t>>::value, - typename allocator_type::const_pointer, - typename allocator_type::pointer>; - using const_pointer = typename allocator_type::const_pointer; - using size_type = typename allocator_type::size_type; - using difference_type = typename allocator_type::difference_type; - - xbuffer_smart_pointer(); - - template - xbuffer_smart_pointer(P&& data_ptr, size_type size, DT&& destruct); - - size_type size() const noexcept; - void resize(size_type size); - - pointer data() noexcept; - const_pointer data() const noexcept; - - void swap(self_type& rhs) noexcept; - - private: - - pointer p_data; - size_type m_size; - destructor_type m_destruct; - }; - - template - class xbuffer_owner_storage - { - public: - - using self_type = xbuffer_owner_storage; - using allocator_type = A; - using destructor_type = allocator_type; - using value_type = typename allocator_type::value_type; - using reference = std::conditional_t>>::value, - typename allocator_type::const_reference, - typename allocator_type::reference>; - using const_reference = typename allocator_type::const_reference; - using pointer = std::conditional_t>>::value, - typename allocator_type::const_pointer, - typename allocator_type::pointer>; - using const_pointer = typename allocator_type::const_pointer; - using size_type = typename allocator_type::size_type; - using difference_type = typename allocator_type::difference_type; - - xbuffer_owner_storage() = default; - - template - xbuffer_owner_storage(P&& data, size_type size, const allocator_type& alloc = allocator_type()); - - ~xbuffer_owner_storage(); - - xbuffer_owner_storage(const self_type&) = delete; - self_type& operator=(const self_type&); - - xbuffer_owner_storage(self_type&&); - self_type& operator=(self_type&&); - - size_type size() const noexcept; - void resize(size_type size); - - pointer data() noexcept; - const_pointer data() const noexcept; - - allocator_type get_allocator() const noexcept; - - void swap(self_type& rhs) noexcept; - - private: - - xtl::xclosure_wrapper m_data; - size_type m_size; - bool m_moved_from; - allocator_type m_allocator; - }; - - // Workaround for MSVC2015: using void_t results in some - // template instantiation caching that leads to wrong - // type deduction later in xfunction. - template - struct msvc2015_void - { - using type = void; - }; - - template - using msvc2015_void_t = typename msvc2015_void::type; - - template - struct is_lambda_type : std::false_type - { - }; - - // check if operator() is available - template - struct is_lambda_type> - : std::true_type - { - }; - - template - struct self_type - { - using type = T; - }; - template - struct get_buffer_storage - { - using type = xtl::mpl::eval_if_t, - self_type>, - self_type>>; - }; - - template - struct get_buffer_storage - { - using type = xbuffer_owner_storage; - }; - - template - struct get_buffer_storage, no_ownership> - { - using type = xbuffer_smart_pointer>; - }; - - template - struct get_buffer_storage, no_ownership> - { - using type = xbuffer_smart_pointer>; - }; - - template - using buffer_storage_t = typename get_buffer_storage::type; - } - - /************************ - * xbuffer_adaptor_base * - ************************/ - - template - struct buffer_inner_types; - - template - class xbuffer_adaptor_base - { - public: - - using self_type = xbuffer_adaptor_base; - using derived_type = D; - using inner_types = buffer_inner_types; - using value_type = typename inner_types::value_type; - using reference = typename inner_types::reference; - using const_reference = typename inner_types::const_reference; - using pointer = typename inner_types::pointer; - using const_pointer = typename inner_types::const_pointer; - using size_type = typename inner_types::size_type; - using difference_type = typename inner_types::difference_type; - using iterator = typename inner_types::iterator; - using const_iterator = typename inner_types::const_iterator; - using reverse_iterator = typename inner_types::reverse_iterator; - using const_reverse_iterator = typename inner_types::const_reverse_iterator; - using index_type = typename inner_types::index_type; - - bool empty() const noexcept; - - reference operator[](size_type i); - const_reference operator[](size_type i) const; - - reference front(); - const_reference front() const; - - reference back(); - const_reference back() const; - - iterator begin() noexcept; - iterator end() noexcept; - - const_iterator begin() const noexcept; - const_iterator end() const noexcept; - const_iterator cbegin() const noexcept; - const_iterator cend() const noexcept; - - reverse_iterator rbegin() noexcept; - reverse_iterator rend() noexcept; - - const_reverse_iterator rbegin() const noexcept; - const_reverse_iterator rend() const noexcept; - const_reverse_iterator crbegin() const noexcept; - const_reverse_iterator crend() const noexcept; - - derived_type& derived_cast() noexcept; - const derived_type& derived_cast() const noexcept; - - protected: - - xbuffer_adaptor_base() = default; - ~xbuffer_adaptor_base() = default; - - xbuffer_adaptor_base(const self_type&) = default; - self_type& operator=(const self_type&) = default; - - xbuffer_adaptor_base(self_type&&) = default; - self_type& operator=(self_type&&) = default; - }; - - template - bool operator==(const xbuffer_adaptor_base& lhs, - const xbuffer_adaptor_base& rhs); - - template - bool operator!=(const xbuffer_adaptor_base& lhs, - const xbuffer_adaptor_base& rhs); - - template - bool operator<(const xbuffer_adaptor_base& lhs, - const xbuffer_adaptor_base& rhs); - - template - bool operator<=(const xbuffer_adaptor_base& lhs, - const xbuffer_adaptor_base& rhs); - - template - bool operator>(const xbuffer_adaptor_base& lhs, - const xbuffer_adaptor_base& rhs); - - template - bool operator>=(const xbuffer_adaptor_base& lhs, - const xbuffer_adaptor_base& rhs); - - /******************* - * xbuffer_adaptor * - *******************/ - - template - struct buffer_inner_types> - { - using base_type = detail::buffer_storage_t; - using value_type = typename base_type::value_type; - using reference = typename base_type::reference; - using const_reference = typename base_type::const_reference; - using pointer = typename base_type::pointer; - using const_pointer = typename base_type::const_pointer; - using size_type = typename base_type::size_type; - using difference_type = typename base_type::difference_type; - using iterator = pointer; - using const_iterator = const_pointer; - using reverse_iterator = std::reverse_iterator; - using const_reverse_iterator = std::reverse_iterator; - using index_type = size_type; - }; - - template - class xbuffer_adaptor : private detail::buffer_storage_t, - public xbuffer_adaptor_base> - { - public: - - using self_type = xbuffer_adaptor; - using base_type = detail::buffer_storage_t; - using buffer_base_type = xbuffer_adaptor_base; - using allocator_type = typename base_type::allocator_type; - using destructor_type = typename base_type::destructor_type; - using value_type = typename buffer_base_type::value_type; - using reference = typename buffer_base_type::reference; - using const_reference = typename buffer_base_type::const_reference; - using pointer = typename buffer_base_type::pointer; - using const_pointer = typename buffer_base_type::const_pointer; - using size_type = typename buffer_base_type::size_type; - using difference_type = typename buffer_base_type::difference_type; - using iterator = typename buffer_base_type::iterator; - using const_iterator = typename buffer_base_type::const_iterator; - using reverse_iterator = typename buffer_base_type::reverse_iterator; - using const_reverse_iterator = typename buffer_base_type::const_reverse_iterator; - using temporary_type = uvector; - - xbuffer_adaptor() = default; - - using base_type::base_type; - - ~xbuffer_adaptor() = default; - - xbuffer_adaptor(const self_type&) = default; - self_type& operator=(const self_type&) = default; - - xbuffer_adaptor(self_type&&) = default; - xbuffer_adaptor& operator=(self_type&&) = default; - - self_type& operator=(temporary_type&&); - - using base_type::size; - using base_type::resize; - using base_type::data; - using base_type::swap; - }; - - template - void swap(xbuffer_adaptor& lhs, - xbuffer_adaptor& rhs) noexcept; - - /********************* - * xiterator_adaptor * - *********************/ - - template - class xiterator_adaptor; - - template - struct buffer_inner_types> - { - using traits = std::iterator_traits; - using const_traits = std::iterator_traits; - - using value_type = std::common_type_t; - using reference = typename traits::reference; - using const_reference = typename const_traits::reference; - using pointer = typename traits::pointer; - using const_pointer = typename const_traits::pointer; - using difference_type = std::common_type_t; - using size_type = std::make_unsigned_t; - - using iterator = I; - using const_iterator = CI; - using reverse_iterator = std::reverse_iterator; - using const_reverse_iterator = std::reverse_iterator; - using index_type = difference_type; - }; - - template - class xiterator_adaptor : public xbuffer_adaptor_base> - { - public: - - using self_type = xiterator_adaptor; - using base_type = xbuffer_adaptor_base; - using value_type = typename base_type::value_type; - using allocator_type = std::allocator; - using size_type = typename base_type::size_type; - using iterator = typename base_type::iterator; - using const_iterator = typename base_type::const_iterator; - using temporary_type = uvector; - - xiterator_adaptor() = default; - xiterator_adaptor(I it, CI cit, size_type size); - - ~xiterator_adaptor() = default; - - xiterator_adaptor(const self_type&) = default; - xiterator_adaptor& operator=(const self_type&) = default; - - xiterator_adaptor(self_type&&) = default; - xiterator_adaptor& operator=(self_type&&) = default; - - xiterator_adaptor& operator=(const temporary_type& rhs); - xiterator_adaptor& operator=(temporary_type&& rhs); - - size_type size() const noexcept; - void resize(size_type size); - - iterator data() noexcept; - const_iterator data() const noexcept; - - void swap(self_type& rhs) noexcept; - - private: - - I m_it; - CI m_cit; - size_type m_size; - }; - - template - void swap(xiterator_adaptor& lhs, - xiterator_adaptor& rhs) noexcept; - - /************************************ - * temporary_container metafunction * - ************************************/ - - template - struct temporary_container - { - using type = C; - }; - - template - struct temporary_container> - { - using type = typename xbuffer_adaptor::temporary_type; - }; - - template - struct temporary_container> - { - using type = typename xiterator_adaptor::temporary_type; - }; - - template - using temporary_container_t = typename temporary_container::type; - - /********************************** - * xbuffer_storage implementation * - **********************************/ - - namespace detail - { - template - inline xbuffer_storage::xbuffer_storage() - : p_data(nullptr), m_size(0) - { - } - - template - template - inline xbuffer_storage::xbuffer_storage(P&& data, size_type size, const allocator_type&) - : p_data(std::forward

(data)), m_size(size) - { - } - - template - inline auto xbuffer_storage::size() const noexcept -> size_type - { - return m_size; - } - - template - inline void xbuffer_storage::resize(size_type size) - { - if (size != m_size) - { - throw std::runtime_error("xbuffer_storage not resizable"); - } - } - - template - inline auto xbuffer_storage::data() noexcept -> pointer - { - return p_data; - } - - template - inline auto xbuffer_storage::data() const noexcept -> const_pointer - { - return p_data; - } - - template - inline void xbuffer_storage::swap(self_type& rhs) noexcept - { - using std::swap; - swap(p_data, rhs.p_data); - swap(m_size, rhs.m_size); - } - } - - /**************************************** - * xbuffer_owner_storage implementation * - ****************************************/ - - namespace detail - { - template - template - inline xbuffer_owner_storage::xbuffer_owner_storage(P&& data, size_type size, const allocator_type& alloc) - : m_data(std::forward

(data)), m_size(size), m_moved_from(false), m_allocator(alloc) - { - } - - template - inline xbuffer_owner_storage::~xbuffer_owner_storage() - { - if (!m_moved_from) - { - safe_destroy_deallocate(m_allocator, m_data.get(), m_size); - m_size = 0; - } - } - - template - inline auto xbuffer_owner_storage::operator=(const self_type& rhs) -> self_type& - { - using std::swap; - if (this != &rhs) - { - allocator_type al = std::allocator_traits::select_on_container_copy_construction(rhs.get_allocator()); - pointer tmp = safe_init_allocate(al, rhs.m_size); - if (xtrivially_default_constructible::value) - { - std::uninitialized_copy(rhs.m_data.get(), rhs.m_data.get() + rhs.m_size, tmp); - } - else - { - std::copy(rhs.m_data.get(), rhs.m_data.get() + rhs.m_size, tmp); - } - swap(m_data.get(), tmp); - m_size = rhs.m_size; - swap(m_allocator, al); - safe_destroy_deallocate(al, tmp, m_size); - } - return *this; - } - - template - inline xbuffer_owner_storage::xbuffer_owner_storage(self_type&& rhs) - : m_data(std::move(rhs.m_data)), m_size(std::move(rhs.m_size)), m_moved_from(std::move(rhs.m_moved_from)), m_allocator(std::move(rhs.m_allocator)) - { - rhs.m_moved_from = true; - rhs.m_size = 0; - } - - template - inline auto xbuffer_owner_storage::operator=(self_type&& rhs) -> self_type& - { - swap(rhs); - return *this; - } - - template - inline auto xbuffer_owner_storage::size() const noexcept -> size_type - { - return m_size; - } - - template - void xbuffer_owner_storage::resize(size_type size) - { - using std::swap; - if (size != m_size) - { - pointer tmp = safe_init_allocate(m_allocator, size); - swap(m_data.get(), tmp); - swap(m_size, size); - safe_destroy_deallocate(m_allocator, tmp, size); - } - } - - template - inline auto xbuffer_owner_storage::data() noexcept -> pointer - { - return m_data.get(); - } - - template - inline auto xbuffer_owner_storage::data() const noexcept -> const_pointer - { - return m_data.get(); - } - - template - inline auto xbuffer_owner_storage::get_allocator() const noexcept -> allocator_type - { - return allocator_type(m_allocator); - } - - template - inline void xbuffer_owner_storage::swap(self_type& rhs) noexcept - { - using std::swap; - swap(m_data, rhs.m_data); - swap(m_size, rhs.m_size); - swap(m_allocator, rhs.m_allocator); - } - } - - /**************************************** - * xbuffer_smart_pointer implementation * - ****************************************/ - - namespace detail - { - template - template - xbuffer_smart_pointer::xbuffer_smart_pointer(P&& data_ptr, size_type size, DT&& destruct) - : p_data(data_ptr), m_size(size), m_destruct(std::forward

(destruct)) - { - } - - template - auto xbuffer_smart_pointer::size() const noexcept -> size_type - { - return m_size; - } - - template - void xbuffer_smart_pointer::resize(size_type size) - { - if (m_size != size) - { - throw std::runtime_error("xbuffer_storage not resizable"); - } - } - - template - auto xbuffer_smart_pointer::data() noexcept -> pointer - { - return p_data; - } - template - auto xbuffer_smart_pointer::data() const noexcept -> const_pointer - { - return p_data; - } - - template - void xbuffer_smart_pointer::swap(self_type& rhs) noexcept - { - using std::swap; - swap(p_data, rhs.p_data); - swap(m_size, rhs.m_size); - swap(m_destruct, rhs.m_destruct); - } - } - - /*************************************** - * xbuffer_adaptor_base implementation * - ***************************************/ - - template - inline bool xbuffer_adaptor_base::empty() const noexcept - { - return derived_cast().size() == size_type(0); - } - - template - inline auto xbuffer_adaptor_base::operator[](size_type i) -> reference - { - return derived_cast().data()[static_cast(i)]; - } - - template - inline auto xbuffer_adaptor_base::operator[](size_type i) const -> const_reference - { - return derived_cast().data()[static_cast(i)]; - } - - template - inline auto xbuffer_adaptor_base::front() -> reference - { - return this->operator[](0); - } - - template - inline auto xbuffer_adaptor_base::front() const -> const_reference - { - return this->operator[](0); - } - - template - inline auto xbuffer_adaptor_base::back() -> reference - { - return this->operator[](derived_cast().size() - 1); - } - - template - inline auto xbuffer_adaptor_base::back() const -> const_reference - { - return this->operator[](derived_cast().size() - 1); - } - - template - inline auto xbuffer_adaptor_base::begin() noexcept -> iterator - { - return derived_cast().data(); - } - - template - inline auto xbuffer_adaptor_base::end() noexcept-> iterator - { - return derived_cast().data() + static_cast(derived_cast().size()); - } - - template - inline auto xbuffer_adaptor_base::begin() const noexcept -> const_iterator - { - return derived_cast().data(); - } - - template - inline auto xbuffer_adaptor_base::end() const noexcept -> const_iterator - { - return derived_cast().data() + static_cast(derived_cast().size()); - } - - template - inline auto xbuffer_adaptor_base::cbegin() const noexcept -> const_iterator - { - return begin(); - } - - template - inline auto xbuffer_adaptor_base::cend() const noexcept -> const_iterator - { - return end(); - } - - template - inline auto xbuffer_adaptor_base::rbegin() noexcept-> reverse_iterator - { - return reverse_iterator(end()); - } - - template - inline auto xbuffer_adaptor_base::rend() noexcept -> reverse_iterator - { - return reverse_iterator(begin()); - } - - template - inline auto xbuffer_adaptor_base::rbegin() const noexcept -> const_reverse_iterator - { - return const_reverse_iterator(end()); - } - - template - inline auto xbuffer_adaptor_base::rend() const noexcept -> const_reverse_iterator - { - return const_reverse_iterator(begin()); - } - - template - inline auto xbuffer_adaptor_base::crbegin() const noexcept -> const_reverse_iterator - { - return rbegin(); - } - - template - inline auto xbuffer_adaptor_base::crend() const noexcept -> const_reverse_iterator - { - return rend(); - } - - template - inline auto xbuffer_adaptor_base::derived_cast() noexcept -> derived_type& - { - return *static_cast(this); - } - - template - inline auto xbuffer_adaptor_base::derived_cast() const noexcept -> const derived_type& - { - return *static_cast(this); - } - - template - inline bool operator==(const xbuffer_adaptor_base& lhs, - const xbuffer_adaptor_base& rhs) - { - return lhs.derived_cast().size() == rhs.derived_cast().size() && std::equal(lhs.begin(), lhs.end(), rhs.begin()); - } - - template - inline bool operator!=(const xbuffer_adaptor_base& lhs, - const xbuffer_adaptor_base& rhs) - { - return !(lhs == rhs); - } - - template - inline bool operator<(const xbuffer_adaptor_base& lhs, - const xbuffer_adaptor_base& rhs) - { - return std::lexicographical_compare(lhs.begin(), lhs.end(), - rhs.begin(), rhs.end(), - std::less()); - } - - template - inline bool operator<=(const xbuffer_adaptor_base& lhs, - const xbuffer_adaptor_base& rhs) - { - return std::lexicographical_compare(lhs.begin(), lhs.end(), - rhs.begin(), rhs.end(), - std::less_equal()); - } - - template - inline bool operator>(const xbuffer_adaptor_base& lhs, - const xbuffer_adaptor_base& rhs) - { - return std::lexicographical_compare(lhs.begin(), lhs.end(), - rhs.begin(), rhs.end(), - std::greater()); - } - - template - inline bool operator>=(const xbuffer_adaptor_base& lhs, - const xbuffer_adaptor_base& rhs) - { - return std::lexicographical_compare(lhs.begin(), lhs.end(), - rhs.begin(), rhs.end(), - std::greater_equal()); - } - - /********************************** - * xbuffer_adaptor implementation * - **********************************/ - - template - inline auto xbuffer_adaptor::operator=(temporary_type&& tmp) -> self_type& - { - base_type::resize(tmp.size()); - std::copy(tmp.cbegin(), tmp.cend(), this->begin()); - return *this; - } - - template - inline void swap(xbuffer_adaptor& lhs, - xbuffer_adaptor& rhs) noexcept - { - lhs.swap(rhs); - } - - /************************************ - * xiterator_adaptor implementation * - ************************************/ - - template - inline xiterator_adaptor::xiterator_adaptor(I it, CI cit, size_type size) - : m_it(it), m_cit(cit), m_size(size) - { - } - - template - inline auto xiterator_adaptor::operator=(const temporary_type& rhs) -> self_type& - { - resize(rhs.size()); - std::copy(rhs.cbegin(), rhs.cend(), m_it); - return *this; - } - - template - inline auto xiterator_adaptor::operator=(temporary_type&& rhs) -> self_type& - { - return (*this = rhs); - } - - template - inline auto xiterator_adaptor::size() const noexcept -> size_type - { - return m_size; - } - - template - inline void xiterator_adaptor::resize(size_type size) - { - if (m_size != size) - { - throw std::runtime_error("xiterator_adaptor not resizable"); - } - } - - template - inline auto xiterator_adaptor::data() noexcept -> iterator - { - return m_it; - } - - template - inline auto xiterator_adaptor::data() const noexcept -> const_iterator - { - return m_cit; - } - - template - inline void xiterator_adaptor::swap(self_type& rhs) noexcept - { - using std::swap; - swap(m_it, rhs.m_it); - swap(m_cit, rhs.m_cit); - swap(m_size, rhs.m_size); - } - - template - inline void swap(xiterator_adaptor& lhs, - xiterator_adaptor& rhs) noexcept - { - lhs.swap(rhs); - } -} - -#endif diff --git a/vendor/xtensor/include/xtensor/xbuilder.hpp b/vendor/xtensor/include/xtensor/xbuilder.hpp deleted file mode 100644 index dfbb2f3cd6..0000000000 --- a/vendor/xtensor/include/xtensor/xbuilder.hpp +++ /dev/null @@ -1,1009 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -/** - * @brief standard mathematical functions for xexpressions - */ - -#ifndef XTENSOR_BUILDER_HPP -#define XTENSOR_BUILDER_HPP - -#include -#include -#include -#include -#include -#include -#include -#ifdef X_OLD_CLANG - #include -#endif - -#include -#include -#include - -#include "xbroadcast.hpp" -#include "xfunction.hpp" -#include "xgenerator.hpp" -#include "xoperation.hpp" - -namespace xt -{ - - /******** - * ones * - ********/ - - /** - * Returns an \ref xexpression containing ones of the specified shape. - * @tparam shape the shape of the returned expression. - */ - template - inline auto ones(S shape) noexcept - { - return broadcast(T(1), std::forward(shape)); - } - -#ifdef X_OLD_CLANG - template - inline auto ones(std::initializer_list shape) noexcept - { - return broadcast(T(1), shape); - } -#else - template - inline auto ones(const I (&shape)[L]) noexcept - { - return broadcast(T(1), shape); - } -#endif - - /********* - * zeros * - *********/ - - /** - * Returns an \ref xexpression containing zeros of the specified shape. - * @tparam shape the shape of the returned expression. - */ - template - inline auto zeros(S shape) noexcept - { - return broadcast(T(0), std::forward(shape)); - } - -#ifdef X_OLD_CLANG - template - inline auto zeros(std::initializer_list shape) noexcept - { - return broadcast(T(0), shape); - } -#else - template - inline auto zeros(const I (&shape)[L]) noexcept - { - return broadcast(T(0), shape); - } -#endif - - /** - * Create a xcontainer (xarray, xtensor or xtensor_fixed) with uninitialized values of - * with value_type T and shape. Selects the best container match automatically - * from the supplied shape. - * - * - ``std::vector`` → ``xarray`` - * - ``std::array`` or ``initializer_list`` → ``xtensor`` - * - ``xshape`` → ``xtensor_fixed>`` - * - * @param shape shape of the new xcontainer - */ - template - inline xarray empty(const S& shape) - { - return xarray::from_shape(shape); - } - - template - inline xtensor empty(const std::array& shape) - { - using shape_type = typename xtensor::shape_type; - return xtensor(xtl::forward_sequence(shape)); - } - -#ifndef X_OLD_CLANG - template - inline xtensor empty(const I(&shape)[N]) - { - using shape_type = typename xtensor::shape_type; - return xtensor(xtl::forward_sequence(shape)); - } -#else - template - inline xarray empty(const std::initializer_list& init) - { - return xarray::from_shape(init); - } -#endif - - template - inline xtensor_fixed, L> empty(const fixed_shape& /*shape*/) - { - return xtensor_fixed, L>(); - } - - /** - * Create a xcontainer (xarray, xtensor or xtensor_fixed) with uninitialized values of - * the same shape, value type and layout as the input xexpression *e*. - * - * @param e the xexpression from which to extract shape, value type and layout. - */ - template - inline auto empty_like(const xexpression& e) - { - using xtype = temporary_type_t; - auto res = xtype::from_shape(e.derived_cast().shape()); - return res; - } - - /** - * Create a xcontainer (xarray, xtensor or xtensor_fixed), filled with *fill_value* and of - * the same shape, value type and layout as the input xexpression *e*. - * - * @param e the xexpression from which to extract shape, value type and layout. - * @param fill_value the value used to set each element of the returned xcontainer. - */ - template - inline auto full_like(const xexpression& e, typename E::value_type fill_value) - { - using xtype = temporary_type_t; - auto res = xtype::from_shape(e.derived_cast().shape()); - res.fill(fill_value); - return res; - } - - /** - * Create a xcontainer (xarray, xtensor or xtensor_fixed), filled with zeros and of - * the same shape, value type and layout as the input xexpression *e*. - * - * Note: contrary to zeros(shape), this function returns a non-lazy, allocated container! - * Use ``xt::zeros(e.shape());` for a lazy version. - * - * @param e the xexpression from which to extract shape, value type and layout. - */ - template - inline auto zeros_like(const xexpression& e) - { - return full_like(e, typename E::value_type(0)); - } - - /** - * Create a xcontainer (xarray, xtensor or xtensor_fixed), filled with ones and of - * the same shape, value type and layout as the input xexpression *e*. - * - * Note: contrary to ones(shape), this function returns a non-lazy, evaluated container! - * Use ``xt::ones(e.shape());`` for a lazy version. - * - * @param e the xexpression from which to extract shape, value type and layout. - */ - template - inline auto ones_like(const xexpression& e) - { - return full_like(e, typename E::value_type(1)); - } - - namespace detail - { - template - struct get_mult_type_impl - { - using type = T; - }; - - template - struct get_mult_type_impl> - { - using type = R; - }; - - template - using get_mult_type = typename get_mult_type_impl::type; - - // These methods should be private methods of arange_generator, however thi leads - // to ICE on VS2015 - template )> - inline void arange_assign_to(xexpression& e, U start, X step) noexcept - { - auto& de = e.derived_cast(); - U value = start; - - for (auto&& el : de.storage()) - { - el = static_cast(value); - value += step; - } - } - - template >)> - inline void arange_assign_to(xexpression& e, U start, X step) noexcept - { - auto& buf = e.derived_cast().storage(); - using size_type = decltype(buf.size()); - using mult_type = get_mult_type; - for(size_type i = 0; i < buf.size(); ++i) - { - buf[i] = static_cast(start + step * mult_type(i)); - } - } - - template - class arange_generator - { - public: - - using value_type = R; - using step_type = S; - - arange_generator(T start, T stop, S step) - : m_start(start), m_stop(stop), m_step(step) - { - } - - template - inline R operator()(Args... args) const - { - return access_impl(args...); - } - - template - inline R element(It first, It) const - { - // Avoids warning when T = char (because char + char => int!) - using mult_type = get_mult_type; - return static_cast(m_start + m_step * mult_type(*first)); - } - - template - inline void assign_to(xexpression& e) const noexcept - { - arange_assign_to(e, m_start, m_step); - } - - private: - - T m_start; - T m_stop; - step_type m_step; - - template - inline R access_impl(T1 t, Args...) const - { - using mult_type = get_mult_type; - return static_cast(m_start + m_step * mult_type(t)); - } - - inline R access_impl() const - { - return static_cast(m_start); - } - }; - - template - using both_integer = xtl::conjunction, std::is_integral>; - - template >)> - inline auto arange_impl(T start, T stop, S step = 1) noexcept - { - std::size_t shape = static_cast(std::ceil((stop - start) / step)); - return detail::make_xgenerator(detail::arange_generator(start, stop, step), {shape}); - } - - template )> - inline auto arange_impl(T start, T stop, S step = 1) noexcept - { - bool empty_cond = (stop - start) / step <= 0; - std::size_t shape = 0; - if(!empty_cond) - { - shape = stop > start ? static_cast((stop - start + step - S(1)) / step) - : static_cast((start - stop - step - S(1)) / -step); - } - return detail::make_xgenerator(detail::arange_generator(start, stop, step), {shape}); - } - - template - class fn_impl - { - public: - - using value_type = typename F::value_type; - using size_type = std::size_t; - - fn_impl(F&& f) - : m_ft(f) - { - } - - inline value_type operator()() const - { - size_type idx[1] = {0ul}; - return access_impl(std::begin(idx), std::end(idx)); - } - - template - inline value_type operator()(Args... args) const - { - size_type idx[sizeof...(Args)] = {static_cast(args)...}; - return access_impl(std::begin(idx), std::end(idx)); - } - - template - inline value_type element(It first, It last) const - { - return access_impl(first, last); - } - - private: - - F m_ft; - template - inline value_type access_impl(const It& begin, const It& end) const - { - return m_ft(begin, end); - } - }; - - template - class eye_fn - { - public: - - using value_type = T; - - eye_fn(int k) - : m_k(k) - { - } - - template - inline T operator()(const It& /*begin*/, const It& end) const - { - using lvalue_type = typename std::iterator_traits::value_type; - return *(end - 1) == *(end - 2) + static_cast(m_k) ? T(1) : T(0); - } - - private: - - std::ptrdiff_t m_k; - }; - } - - /** - * Generates an array with ones on the diagonal. - * @param shape shape of the resulting expression - * @param k index of the diagonal. 0 (default) refers to the main diagonal, - * a positive value refers to an upper diagonal, and a negative - * value to a lower diagonal. - * @tparam T value_type of xexpression - * @return xgenerator that generates the values on access - */ - template - inline auto eye(const std::vector& shape, int k = 0) - { - return detail::make_xgenerator(detail::fn_impl>(detail::eye_fn(k)), shape); - } - - /** - * Generates a (n x n) array with ones on the diagonal. - * @param n length of the diagonal. - * @param k index of the diagonal. 0 (default) refers to the main diagonal, - * a positive value refers to an upper diagonal, and a negative - * value to a lower diagonal. - * @tparam T value_type of xexpression - * @return xgenerator that generates the values on access - */ - template - inline auto eye(std::size_t n, int k = 0) - { - return eye({n, n}, k); - } - - /** - * Generates numbers evenly spaced within given half-open interval [start, stop). - * @param start start of the interval - * @param stop stop of the interval - * @param step stepsize - * @tparam T value_type of xexpression - * @return xgenerator that generates the values on access - */ - template - inline auto arange(T start, T stop, S step = 1) noexcept - { - return detail::arange_impl(start, stop, step); - } - - /** - * Generate numbers evenly spaced within given half-open interval [0, stop) - * with a step size of 1. - * @param stop stop of the interval - * @tparam T value_type of xexpression - * @return xgenerator that generates the values on access - */ - template - inline auto arange(T stop) noexcept - { - return arange(T(0), stop, T(1)); - } - - /** - * Generates @a num_samples evenly spaced numbers over given interval - * @param start start of interval - * @param stop stop of interval - * @param num_samples number of samples (defaults to 50) - * @param endpoint if true, include endpoint (defaults to true) - * @tparam T value_type of xexpression - * @return xgenerator that generates the values on access - */ - template - inline auto linspace(T start, T stop, std::size_t num_samples = 50, bool endpoint = true) noexcept - { - using fp_type = std::common_type_t; - fp_type step = fp_type(stop - start) / std::fmax(fp_type(1), fp_type(num_samples - (endpoint ? 1 : 0))); - return detail::make_xgenerator(detail::arange_generator(fp_type(start), fp_type(stop), step), {num_samples}); - } - - /** - * Generates @a num_samples numbers evenly spaced on a log scale over given interval - * @param start start of interval (pow(base, start) is the first value). - * @param stop stop of interval (pow(base, stop) is the final value, except if endpoint = false) - * @param num_samples number of samples (defaults to 50) - * @param base the base of the log space. - * @param endpoint if true, include endpoint (defaults to true) - * @tparam T value_type of xexpression - * @return xgenerator that generates the values on access - */ - template - inline auto logspace(T start, T stop, std::size_t num_samples, T base = 10, bool endpoint = true) noexcept - { - return pow(std::move(base), linspace(start, stop, num_samples, endpoint)); - } - - namespace detail - { - template - class concatenate_impl - { - public: - - using size_type = std::size_t; - using value_type = xtl::promote_type_t::value_type...>; - - inline concatenate_impl(std::tuple&& t, size_type axis) - : m_t(t), m_axis(axis) - { - } - - template - inline value_type operator()(Args... args) const - { - // TODO: avoid memory allocation - return access_impl(xindex({static_cast(args)...})); - } - - template - inline value_type element(It first, It last) const - { - // TODO: avoid memory allocation - return access_impl(xindex(first, last)); - } - - private: - - inline value_type access_impl(xindex idx) const - { - auto match = [this, &idx](auto& arr) { - if (idx[this->m_axis] >= arr.shape()[this->m_axis]) - { - idx[this->m_axis] -= arr.shape()[this->m_axis]; - return false; - } - return true; - }; - - auto get = [&idx](auto& arr) { - return arr[idx]; - }; - - size_type i = 0; - for (; i < sizeof...(CT); ++i) - { - if (apply(i, match, m_t)) - { - break; - } - } - return apply(i, get, m_t); - } - - std::tuple m_t; - size_type m_axis; - }; - - template - class stack_impl - { - public: - - using size_type = std::size_t; - using value_type = xtl::promote_type_t::value_type...>; - - inline stack_impl(std::tuple&& t, size_type axis) - : m_t(t), m_axis(axis) - { - } - - template - inline value_type operator()(Args... args) const - { - // TODO: avoid memory allocation - return access_impl(xindex({static_cast(args)...})); - } - - template - inline value_type element(It first, It last) const - { - // TODO: avoid memory allocation - return access_impl(xindex(first, last)); - } - - private: - - inline value_type access_impl(xindex idx) const - { - auto get_item = [&idx](auto& arr) { - return arr[idx]; - }; - size_type i = idx[m_axis]; - idx.erase(idx.begin() + std::ptrdiff_t(m_axis)); - return apply(i, get_item, m_t); - } - - const std::tuple m_t; - const size_type m_axis; - }; - - template - class repeat_impl - { - public: - - using xexpression_type = std::decay_t; - using size_type = typename xexpression_type::size_type; - using value_type = typename xexpression_type::value_type; - - template - repeat_impl(CTA&& source, size_type axis) - : m_source(std::forward(source)), m_axis(axis) - { - } - - template - value_type operator()(Args... args) const - { - std::array args_arr = {static_cast(args)...}; - return m_source(args_arr[m_axis]); - } - - template - inline value_type element(It first, It) const - { - return m_source(*(first + static_cast(m_axis))); - } - - private: - - CT m_source; - size_type m_axis; - }; - } - - /** - * @brief Creates tuples from arguments for \ref concatenate and \ref stack. - * Very similar to std::make_tuple. - */ - template - inline auto xtuple(Types&&... args) - { - return std::tuple...>(std::forward(args)...); - } - - /** - * @brief Concatenates xexpressions along \em axis. - * - * @param t \ref xtuple of xexpressions to concatenate - * @param axis axis along which elements are concatenated - * @returns xgenerator evaluating to concatenated elements - * - * \code{.cpp} - * xt::xarray a = {{1, 2, 3}}; - * xt::xarray b = {{2, 3, 4}}; - * xt::xarray c = xt::concatenate(xt::xtuple(a, b)); // => {{1, 2, 3}, - * {2, 3, 4}} - * xt::xarray d = xt::concatenate(xt::xtuple(a, b), 1); // => {{1, 2, 3, 2, 3, 4}} - * \endcode - */ - template - inline auto concatenate(std::tuple&& t, std::size_t axis = 0) - { - using shape_type = promote_shape_t::shape_type...>; - using source_shape_type = decltype(std::get<0>(t).shape()); - shape_type new_shape = xtl::forward_sequence(std::get<0>(t).shape()); - - auto check_shape = [&axis, &new_shape](auto& arr) { - std::size_t s = new_shape.size(); - bool res = s == arr.dimension(); - for(std::size_t i = 0; i < s; ++i) - { - res = res && (i == axis || new_shape[i] == arr.shape(i)); - } - if(!res) - { - throw_concatenate_error(new_shape, arr.shape()); - } - }; - for_each(check_shape, t); - - auto shape_at_axis = [&axis](std::size_t prev, auto& arr) -> std::size_t { - return prev + arr.shape()[axis]; - }; - new_shape[axis] += accumulate(shape_at_axis, std::size_t(0), t) - new_shape[axis]; - - return detail::make_xgenerator(detail::concatenate_impl(std::forward>(t), axis), new_shape); - } - - namespace detail - { - template - inline std::array add_axis(std::array arr, std::size_t axis, std::size_t value) - { - std::array temp; - std::copy(arr.begin(), arr.begin() + axis, temp.begin()); - temp[axis] = value; - std::copy(arr.begin() + axis, arr.end(), temp.begin() + axis + 1); - return temp; - } - - template - inline T add_axis(T arr, std::size_t axis, std::size_t value) - { - T temp(arr); - temp.insert(temp.begin() + std::ptrdiff_t(axis), value); - return temp; - } - } - - /** - * @brief Stack xexpressions along \em axis. - * Stacking always creates a new dimension along which elements are stacked. - * - * @param t \ref xtuple of xexpressions to concatenate - * @param axis axis along which elements are stacked - * @returns xgenerator evaluating to stacked elements - * - * \code{.cpp} - * xt::xarray a = {1, 2, 3}; - * xt::xarray b = {5, 6, 7}; - * xt::xarray s = xt::stack(xt::xtuple(a, b)); // => {{1, 2, 3}, - * {5, 6, 7}} - * xt::xarray t = xt::stack(xt::xtuple(a, b), 1); // => {{1, 5}, - * {2, 6}, - * {3, 7}} - * \endcode - */ - template - inline auto stack(std::tuple&& t, std::size_t axis = 0) - { - using shape_type = promote_shape_t::shape_type...>; - using source_shape_type = decltype(std::get<0>(t).shape()); - auto new_shape = detail::add_axis(xtl::forward_sequence(std::get<0>(t).shape()), axis, sizeof...(CT)); - return detail::make_xgenerator(detail::stack_impl(std::forward>(t), axis), new_shape); - } - - namespace detail - { - - template - inline auto meshgrid_impl(std::index_sequence, E&&... e) noexcept - { -#if defined X_OLD_CLANG || defined _MSC_VER - const std::array shape = {e.shape()[0]...}; - return std::make_tuple( - detail::make_xgenerator( - detail::repeat_impl>(std::forward(e), I), - shape - )... - ); -#else - return std::make_tuple( - detail::make_xgenerator( - detail::repeat_impl>(std::forward(e), I), - {e.shape()[0]...} - )... - ); -#endif - } - } - - /** - * @brief Return coordinate tensors from coordinate vectors. - * Make N-D coordinate tensor expressions for vectorized evaluations of N-D scalar/vector - * fields over N-D grids, given one-dimensional coordinate arrays x1, x2,..., xn. - * - * @param e xexpressions to concatenate - * @returns tuple of xgenerator expressions. - */ - template - inline auto meshgrid(E&&... e) noexcept - { - return detail::meshgrid_impl(std::make_index_sequence(), std::forward(e)...); - } - - namespace detail - { - template - class diagonal_fn - { - public: - - using xexpression_type = std::decay_t; - using value_type = typename xexpression_type::value_type; - - template - diagonal_fn(CTA&& source, int offset, std::size_t axis_1, std::size_t axis_2) - : m_source(std::forward(source)), m_offset(offset), m_axis_1(axis_1), m_axis_2(axis_2) - { - } - - template - inline value_type operator()(It begin, It) const - { - xindex idx(m_source.shape().size()); - - for (std::size_t i = 0; i < idx.size(); i++) - { - if (i != m_axis_1 && i != m_axis_2) - { - idx[i] = *begin++; - } - } - using it_vtype = typename std::iterator_traits::value_type; - it_vtype uoffset = static_cast(m_offset); - if (m_offset >= 0) - { - idx[m_axis_1] = *(begin); - idx[m_axis_2] = *(begin) + uoffset; - } - else - { - idx[m_axis_1] = *(begin) - uoffset; - idx[m_axis_2] = *(begin); - } - return m_source[idx]; - } - - private: - - CT m_source; - const int m_offset; - const std::size_t m_axis_1; - const std::size_t m_axis_2; - }; - - template - class diag_fn - { - public: - - using xexpression_type = std::decay_t; - using value_type = typename xexpression_type::value_type; - - template - diag_fn(CTA&& source, int k) - : m_source(std::forward(source)), m_k(k) - { - } - - template - inline value_type operator()(It begin, It) const - { - using it_vtype = typename std::iterator_traits::value_type; - it_vtype umk = static_cast(m_k); - if (m_k > 0) - { - return *begin + umk == *(begin + 1) ? m_source(*begin) : value_type(0); - } - else - { - return *begin + umk == *(begin + 1) ? m_source(*begin + umk) : value_type(0); - } - } - - private: - - CT m_source; - const int m_k; - }; - - template - class trilu_fn - { - public: - - using xexpression_type = std::decay_t; - using value_type = typename xexpression_type::value_type; - using signed_idx_type = long int; - - template - trilu_fn(CTA&& source, int k, Comp comp) - : m_source(std::forward(source)), m_k(k), m_comp(comp) - { - } - - template - inline value_type operator()(It begin, It end) const - { - // have to cast to signed int otherwise -1 can lead to overflow - return m_comp(signed_idx_type(*begin) + m_k, signed_idx_type(*(begin + 1))) ? m_source.element(begin, end) : value_type(0); - } - - private: - - CT m_source; - const signed_idx_type m_k; - const Comp m_comp; - }; - } - - namespace detail - { - // meta-function returning the shape type for a diagonal - template - struct diagonal_shape_type - { - using type = ST; - }; - - template - struct diagonal_shape_type> - { - using type = std::array; - }; - } - - /** - * @brief Returns the elements on the diagonal of arr - * If arr has more than two dimensions, then the axes specified by - * axis_1 and axis_2 are used to determine the 2-D sub-array whose - * diagonal is returned. The shape of the resulting array can be - * determined by removing axis1 and axis2 and appending an index - * to the right equal to the size of the resulting diagonals. - * - * @param arr the input array - * @param offset offset of the diagonal from the main diagonal. Can - * be positive or negative. - * @param axis_1 Axis to be used as the first axis of the 2-D sub-arrays - * from which the diagonals should be taken. - * @param axis_2 Axis to be used as the second axis of the 2-D sub-arrays - * from which the diagonals should be taken. - * @returns xexpression with values of the diagonal - * - * \code{.cpp} - * xt::xarray a = {{1, 2, 3}, - * {4, 5, 6} - * {7, 8, 9}}; - * auto b = xt::diagonal(a); // => {1, 5, 9} - * \endcode - */ - template - inline auto diagonal(E&& arr, int offset = 0, std::size_t axis_1 = 0, std::size_t axis_2 = 1) - { - using CT = xclosure_t; - using shape_type = typename detail::diagonal_shape_type::shape_type>::type; - - auto shape = arr.shape(); - auto dimension = arr.dimension(); - - // The following shape calculation code is an almost verbatim adaptation of numpy: - // https://github.com/numpy/numpy/blob/2aabeafb97bea4e1bfa29d946fbf31e1104e7ae0/numpy/core/src/multiarray/item_selection.c#L1799 - auto ret_shape = xtl::make_sequence(dimension - 1, 0); - int dim_1 = static_cast(shape[axis_1]); - int dim_2 = static_cast(shape[axis_2]); - - offset >= 0 ? dim_2 -= offset : dim_1 += offset; - - auto diag_size = std::size_t(dim_2 < dim_1 ? dim_2 : dim_1); - - std::size_t i = 0; - for (std::size_t idim = 0; idim < dimension; ++idim) - { - if (idim != axis_1 && idim != axis_2) - { - ret_shape[i++] = shape[idim]; - } - } - - ret_shape.back() = diag_size; - - return detail::make_xgenerator(detail::fn_impl>(detail::diagonal_fn(std::forward(arr), offset, axis_1, axis_2)), - ret_shape); - } - - /** - * @brief xexpression with values of arr on the diagonal, zeroes otherwise - * - * @param arr the 1D input array of length n - * @param k the offset of the considered diagonal - * @returns xexpression function with shape n x n and arr on the diagonal - * - * \code{.cpp} - * xt::xarray a = {1, 5, 9}; - * auto b = xt::diag(a); // => {{1, 0, 0}, - * // {0, 5, 0}, - * // {0, 0, 9}} - * \endcode - */ - template - inline auto diag(E&& arr, int k = 0) - { - using CT = xclosure_t; - std::size_t sk = std::size_t(std::abs(k)); - std::size_t s = arr.shape()[0] + sk; - return detail::make_xgenerator(detail::fn_impl>(detail::diag_fn(std::forward(arr), k)), - {s, s}); - } - - /** - * @brief Extract lower triangular matrix from xexpression. The parameter k selects the - * offset of the diagonal. - * - * @param arr the input array - * @param k the diagonal above which to zero elements. 0 (default) selects the main diagonal, - * k < 0 is below the main diagonal, k > 0 above. - * @returns xexpression containing lower triangle from arr, 0 otherwise - */ - template - inline auto tril(E&& arr, int k = 0) - { - using CT = xclosure_t; - auto shape = arr.shape(); - return detail::make_xgenerator(detail::fn_impl>>( - detail::trilu_fn>(std::forward(arr), k, std::greater_equal())), - shape); - } - - /** - * @brief Extract upper triangular matrix from xexpression. The parameter k selects the - * offset of the diagonal. - * - * @param arr the input array - * @param k the diagonal below which to zero elements. 0 (default) selects the main diagonal, - * k < 0 is below the main diagonal, k > 0 above. - * @returns xexpression containing lower triangle from arr, 0 otherwise - */ - template - inline auto triu(E&& arr, int k = 0) - { - using CT = xclosure_t; - auto shape = arr.shape(); - return detail::make_xgenerator(detail::fn_impl>>( - detail::trilu_fn>(std::forward(arr), k, std::less_equal())), - shape); - } -} -#endif diff --git a/vendor/xtensor/include/xtensor/xcomplex.hpp b/vendor/xtensor/include/xtensor/xcomplex.hpp deleted file mode 100644 index 5bae3266d6..0000000000 --- a/vendor/xtensor/include/xtensor/xcomplex.hpp +++ /dev/null @@ -1,259 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_COMPLEX_HPP -#define XTENSOR_COMPLEX_HPP - -#include -#include - -#include - -#include "xtensor/xbuilder.hpp" -#include "xtensor/xexpression.hpp" -#include "xtensor/xoffset_view.hpp" - -namespace xt -{ - /****************************** - * real and imag declarations * - ******************************/ - - template - decltype(auto) real(E&& e) noexcept; - - template - decltype(auto) imag(E&& e) noexcept; - - /******************************** - * real and imag implementation * - ********************************/ - - namespace detail - { - template - struct complex_helper - { - template - static inline auto real(E&& e) noexcept - { - using real_type = typename std::decay_t::value_type::value_type; - return xoffset_view, real_type, 0>(std::forward(e)); - } - - template - static inline auto imag(E&& e) noexcept - { - using real_type = typename std::decay_t::value_type::value_type; - return xoffset_view, real_type, sizeof(real_type)>(std::forward(e)); - } - }; - - template <> - struct complex_helper - { - template - static inline decltype(auto) real(E&& e) noexcept - { - return std::forward(e); - } - - template - static inline auto imag(E&& e) noexcept - { - return zeros::value_type>(e.shape()); - } - }; - - template - struct complex_expression_helper - { - template - static inline decltype(auto) real(E&& e) noexcept - { - return detail::complex_helper::value_type>::value>::real(std::forward(e)); - } - - template - static inline decltype(auto) imag(E&& e) noexcept - { - return detail::complex_helper::value_type>::value>::imag(std::forward(e)); - } - }; - - template <> - struct complex_expression_helper - { - template - static inline decltype(auto) real(E&& e) noexcept - { - return xtl::forward_real(std::forward(e)); - } - - template - static inline decltype(auto) imag(E&& e) noexcept - { - return xtl::forward_imag(std::forward(e)); - } - }; - } - - /** - * @brief Returns an \ref xexpression representing the real part of the given expression. - * - * @tparam e the \ref xexpression - * - * The returned expression either hold a const reference to \p e or a copy - * depending on whether \p e is an lvalue or an rvalue. - */ - template - inline decltype(auto) real(E&& e) noexcept - { - return detail::complex_expression_helper>::value>::real(std::forward(e)); - } - - /** - * @brief Returns an \ref xexpression representing the imaginary part of the given expression. - * - * @tparam e the \ref xexpression - * - * The returned expression either hold a const reference to \p e or a copy - * depending on whether \p e is an lvalue or an rvalue. - */ - template - inline decltype(auto) imag(E&& e) noexcept - { - return detail::complex_expression_helper>::value>::imag(std::forward(e)); - } - -#define UNARY_COMPLEX_FUNCTOR(NS, NAME) \ - struct NAME##_fun \ - { \ - template \ - constexpr auto operator()(const T& t) const \ - { \ - using NS::NAME; \ - return NAME(t); \ - } \ - \ - template \ - constexpr auto simd_apply(const B& t) const \ - { \ - using NS::NAME; \ - return NAME(t); \ - } \ - } - - namespace math - { - namespace detail - { - template - constexpr std::complex conj_impl(const std::complex& c) - { - return std::complex(c.real(), -c.imag()); - } - -#ifdef XTENSOR_USE_XSIMD - template - constexpr X conj_impl(const xsimd::simd_complex_batch& z) - { - return xsimd::conj(z); - } - - template - struct not_complex_batch - : xtl::negation, T>> - { - }; - - // libc++ (OSX) conj is unfortunately broken and returns - // std::complex instead of T. - // This function must be deactivated for complex batches, - // otherwise it will be a better match than the previous one. - template )> - constexpr T conj_impl(const T& c) - { - return c; - } -#else - // libc++ (OSX) conj is unfortunately broken and returns - // std::complex instead of T. - template - constexpr T conj_impl(const T& c) - { - return c; - } -#endif - } - - UNARY_COMPLEX_FUNCTOR(std, norm); - UNARY_COMPLEX_FUNCTOR(std, arg); - UNARY_COMPLEX_FUNCTOR(detail, conj_impl); - } - -#undef UNARY_COMPLEX_FUNCTOR - - /** - * @brief Returns an \ref xfunction evaluating to the complex conjugate of the given expression. - * - * @param e the \ref xexpression - */ - template - inline auto conj(E&& e) noexcept - { - using functor = math::conj_impl_fun; - using type = xfunction>; - return type(functor(), std::forward(e)); - } - - /** - * @brief Calculates the phase angle (in radians) elementwise for the complex numbers in e. - * @param e the \ref xexpression - */ - template - inline auto arg(E&& e) noexcept - { - using functor = math::arg_fun; - using type = xfunction>; - return type(functor(), std::forward(e)); - } - - /** - * @brief Calculates the phase angle elementwise for the complex numbers in e. - * Note that this function might be slightly less perfomant than \ref arg. - * @param e the \ref xexpression - * @param deg calculate angle in degrees instead of radians - */ - template - inline auto angle(E&& e, bool deg = false) noexcept - { - using value_type = xtl::complex_value_type_t::value_type>; - value_type multiplier = 1.0; - if (deg) - { - multiplier = value_type(180) / numeric_constants::PI; - } - return arg(std::forward(e)) * std::move(multiplier); - } - - /** - * Calculates the squared magnitude elementwise for the complex numbers in e. - * Equivalent to pow(real(e), 2) + pow(imag(e), 2). - * @param e the \ref xexpression - */ - template - inline auto norm(E&& e) noexcept - { - using functor = math::norm_fun; - using type = xfunction>; - return type(functor(), std::forward(e)); - } -} -#endif diff --git a/vendor/xtensor/include/xtensor/xconcepts.hpp b/vendor/xtensor/include/xtensor/xconcepts.hpp deleted file mode 100644 index 1845c6b033..0000000000 --- a/vendor/xtensor/include/xtensor/xconcepts.hpp +++ /dev/null @@ -1,113 +0,0 @@ -/*************************************************************************** -* Copyright (c) 2017, Ullrich Koethe * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_CONCEPTS_HPP -#define XTENSOR_CONCEPTS_HPP - -#include - -/***************************************************** - * concept checking and type inference functionality * - *****************************************************/ - -namespace xt -{ - - /****************************************** - * XTENSOR_REQUIRE concept checking macro * - ******************************************/ - - struct concept_check_successful - { - }; - - template - using concept_check = typename std::enable_if::type; - - /** @brief Concept checking macro (more readable than sfinae). - - The macro is used as the last argument in a template declaration. - It must be followed by a static boolean expression in angle brackets. - The template will only be included in overload resolution when - this expression evaluates to 'true'. - - Example: - \code - template ::value>> - T foo(T t) - {...} - \endcode - */ - #define XTENSOR_REQUIRE typename = concept_check - - /******************** - * iterator_concept * - ********************/ - - /** @brief Traits class to check if a type is an iterator. - - This is useful in concept checking to make sure that a given template - is only instantiated when the argument is an iterator. - Currently, we apply the simple rule that class @tparam T - is either a pointer or a C-array or has an embedded typedef - 'iterator_category'. More sophisticated checks can easily - be added when needed. - - If @tparam T is indeed an iterator, the class' value member - is true: - \code - template ::value>> - T foo(T t) - {...} - \endcode - */ - template - struct iterator_concept - { - using V = std::decay_t; - - static char test(...); - - template - static int test(U*, typename U::iterator_category* = 0); - - static const bool value = - std::is_array::value || - std::is_pointer::value || - std::is_same())), int>::value; - }; - - /** @brief Check if a conversion may loose information. - - @tparam FROM source type - @tparam TO target type - - When data is converted from a big type (e.g. int64_t or double) - to a smaller type (e.g. int32_t), most compilers issue a 'possible loss of data' - warning. This metafunction allows you to detect these situations and take appropriate - actions. - - If loss of data may occur, member is_narrowing_conversion::value is true. Currently, - the check is only implemented for built-in types, i.e. types where std::is_arithmetic - is true. - */ - template - struct is_narrowing_conversion - { - using argument_type = std::decay_t; - using result_type = std::decay_t; - - static const bool value = std::is_arithmetic::value && - (sizeof(result_type) < sizeof(argument_type) || - (std::is_integral::value && std::is_floating_point::value)); - }; -} // namespace xt - -#endif // XCONCEPTS_HPP diff --git a/vendor/xtensor/include/xtensor/xcontainer.hpp b/vendor/xtensor/include/xtensor/xcontainer.hpp deleted file mode 100644 index 129016a7b7..0000000000 --- a/vendor/xtensor/include/xtensor/xcontainer.hpp +++ /dev/null @@ -1,1047 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_CONTAINER_HPP -#define XTENSOR_CONTAINER_HPP - -#include -#include -#include -#include - -#include -#include - -#include "xaccessible.hpp" -#include "xiterable.hpp" -#include "xiterator.hpp" -#include "xmath.hpp" -#include "xoperation.hpp" -#include "xstrides.hpp" -#include "xtensor_forward.hpp" - -namespace xt -{ - template - struct xcontainer_iterable_types - { - using inner_shape_type = typename xcontainer_inner_types::inner_shape_type; - using storage_type = typename xcontainer_inner_types::storage_type; - using stepper = xstepper; - using const_stepper = xstepper; - }; - - namespace detail - { - template - struct allocator_type_impl - { - using type = typename T::allocator_type; - }; - - template - struct allocator_type_impl> - { - using type = std::allocator; // fake allocator for testing - }; - } - - template - using allocator_type_t = typename detail::allocator_type_impl::type; - - /** - * @class xcontainer - * @brief Base class for dense multidimensional containers. - * - * The xcontainer class defines the interface for dense multidimensional - * container classes. It does not embed any data container, this responsibility - * is delegated to the inheriting classes. - * - * @tparam D The derived type, i.e. the inheriting class for which xcontainer - * provides the interface. - */ - template - class xcontainer : public xcontiguous_iterable, - private xaccessible - { - public: - - using derived_type = D; - - using inner_types = xcontainer_inner_types; - using storage_type = typename inner_types::storage_type; - using allocator_type = allocator_type_t>; - using value_type = typename storage_type::value_type; - using reference = typename inner_types::reference; - using const_reference = typename inner_types::const_reference; - using pointer = typename storage_type::pointer; - using const_pointer = typename storage_type::const_pointer; - using size_type = typename inner_types::size_type; - using difference_type = typename storage_type::difference_type; - using simd_value_type = xt_simd::simd_type; - using bool_load_type = xt::bool_load_type; - - using shape_type = typename inner_types::shape_type; - using strides_type = typename inner_types::strides_type; - using backstrides_type = typename inner_types::backstrides_type; - - using inner_shape_type = typename inner_types::inner_shape_type; - using inner_strides_type = typename inner_types::inner_strides_type; - using inner_backstrides_type = typename inner_types::inner_backstrides_type; - - using iterable_base = xcontiguous_iterable; - using stepper = typename iterable_base::stepper; - using const_stepper = typename iterable_base::const_stepper; - - using accessible_base = xaccessible; - - static constexpr layout_type static_layout = inner_types::layout; - static constexpr bool contiguous_layout = static_layout != layout_type::dynamic; - using data_alignment = xt_simd::container_alignment_t; - using simd_type = xt_simd::simd_type; - - using storage_iterator = typename iterable_base::storage_iterator; - using const_storage_iterator = typename iterable_base::const_storage_iterator; - using reverse_storage_iterator = typename iterable_base::reverse_storage_iterator; - using const_reverse_storage_iterator = typename iterable_base::const_reverse_storage_iterator; - - static_assert(static_layout != layout_type::any, "Container layout can never be layout_type::any!"); - - size_type size() const noexcept; - - XTENSOR_CONSTEXPR_RETURN size_type dimension() const noexcept; - - XTENSOR_CONSTEXPR_RETURN const inner_shape_type& shape() const noexcept; - XTENSOR_CONSTEXPR_RETURN const inner_strides_type& strides() const noexcept; - XTENSOR_CONSTEXPR_RETURN const inner_backstrides_type& backstrides() const noexcept; - - template - void fill(const T& value); - - template - reference operator()(Args... args); - - template - const_reference operator()(Args... args) const; - - template - reference unchecked(Args... args); - - template - const_reference unchecked(Args... args) const; - - using accessible_base::shape; - using accessible_base::at; - using accessible_base::operator[]; - using accessible_base::periodic; - using accessible_base::in_bounds; - - template - reference element(It first, It last); - template - const_reference element(It first, It last) const; - - storage_type& storage() noexcept; - const storage_type& storage() const noexcept; - - value_type* data() noexcept; - const value_type* data() const noexcept; - const size_type data_offset() const noexcept; - - template - bool broadcast_shape(S& shape, bool reuse_cache = false) const; - - template - bool has_linear_assign(const S& strides) const noexcept; - template - stepper stepper_begin(const S& shape) noexcept; - template - stepper stepper_end(const S& shape, layout_type l) noexcept; - - template - const_stepper stepper_begin(const S& shape) const noexcept; - template - const_stepper stepper_end(const S& shape, layout_type l) const noexcept; - - reference data_element(size_type i); - const_reference data_element(size_type i) const; - - template - using simd_return_type = xt_simd::simd_return_type; - - template - void store_simd(size_type i, const simd& e); - template ::size> - container_simd_return_type_t - /*simd_return_type*/ load_simd(size_type i) const; - - storage_iterator storage_begin() noexcept; - storage_iterator storage_end() noexcept; - - const_storage_iterator storage_begin() const noexcept; - const_storage_iterator storage_end() const noexcept; - const_storage_iterator storage_cbegin() const noexcept; - const_storage_iterator storage_cend() const noexcept; - - reverse_storage_iterator storage_rbegin() noexcept; - reverse_storage_iterator storage_rend() noexcept; - - const_reverse_storage_iterator storage_rbegin() const noexcept; - const_reverse_storage_iterator storage_rend() const noexcept; - const_reverse_storage_iterator storage_crbegin() const noexcept; - const_reverse_storage_iterator storage_crend() const noexcept; - - using container_iterator = storage_iterator; - using const_container_iterator = const_storage_iterator; - - protected: - - xcontainer() = default; - ~xcontainer() = default; - - xcontainer(const xcontainer&) = default; - xcontainer& operator=(const xcontainer&) = default; - - xcontainer(xcontainer&&) = default; - xcontainer& operator=(xcontainer&&) = default; - - container_iterator data_xbegin() noexcept; - const_container_iterator data_xbegin() const noexcept; - container_iterator data_xend(layout_type l, size_type offset) noexcept; - const_container_iterator data_xend(layout_type l, size_type offset) const noexcept; - - protected: - - derived_type& derived_cast() & noexcept; - const derived_type& derived_cast() const & noexcept; - derived_type derived_cast() && noexcept; - - private: - - template - It data_xend_impl(It begin, layout_type l, size_type offset) const noexcept; - - inner_shape_type& mutable_shape(); - inner_strides_type& mutable_strides(); - inner_backstrides_type& mutable_backstrides(); - - template - friend class xstepper; - - friend class xaccessible; - friend class xconst_accessible; - }; - - /** - * @class xstrided_container - * @brief Partial implementation of xcontainer that embeds the strides and the shape - * - * The xstrided_container class is a partial implementation of the xcontainer interface - * that embed the strides and the shape of the multidimensional container. It does - * not embed the data container, this responsibility is delegated to the inheriting - * classes. - * - * @tparam D The derived type, i.e. the inheriting class for which xstrided_container - * provides the partial imlpementation of xcontainer. - */ - template - class xstrided_container : public xcontainer - { - public: - - using base_type = xcontainer; - using storage_type = typename base_type::storage_type; - using value_type = typename base_type::value_type; - using reference = typename base_type::reference; - using const_reference = typename base_type::const_reference; - using pointer = typename base_type::pointer; - using const_pointer = typename base_type::const_pointer; - using size_type = typename base_type::size_type; - using shape_type = typename base_type::shape_type; - using strides_type = typename base_type::strides_type; - using inner_shape_type = typename base_type::inner_shape_type; - using inner_strides_type = typename base_type::inner_strides_type; - using inner_backstrides_type = typename base_type::inner_backstrides_type; - - template - void resize(S&& shape, bool force = false); - template - void resize(S&& shape, layout_type l); - template - void resize(S&& shape, const strides_type& strides); - - template - void reshape(S&& shape, layout_type layout = base_type::static_layout); - - template - void reshape(std::initializer_list shape, layout_type layout = base_type::static_layout); - - layout_type layout() const noexcept; - - protected: - - xstrided_container() noexcept; - ~xstrided_container() = default; - - xstrided_container(const xstrided_container&) = default; - xstrided_container& operator=(const xstrided_container&) = default; - - xstrided_container(xstrided_container&&) = default; - xstrided_container& operator=(xstrided_container&&) = default; - - explicit xstrided_container(inner_shape_type&&, inner_strides_type&&) noexcept; - explicit xstrided_container(inner_shape_type&&, inner_strides_type&&, inner_backstrides_type&&, layout_type&&) noexcept; - - inner_shape_type& shape_impl() noexcept; - const inner_shape_type& shape_impl() const noexcept; - - inner_strides_type& strides_impl() noexcept; - const inner_strides_type& strides_impl() const noexcept; - - inner_backstrides_type& backstrides_impl() noexcept; - const inner_backstrides_type& backstrides_impl() const noexcept; - - template - void reshape_impl(S&& shape, std::true_type, layout_type layout = base_type::static_layout); - template - void reshape_impl(S&& shape, std::false_type, layout_type layout = base_type::static_layout); - - layout_type& mutable_layout() noexcept - { - return m_layout; - } - - private: - - inner_shape_type m_shape; - inner_strides_type m_strides; - inner_backstrides_type m_backstrides; - layout_type m_layout = base_type::static_layout; - }; - - /****************************** - * xcontainer implementation * - ******************************/ - - template - template - inline It xcontainer::data_xend_impl(It begin, layout_type l, size_type offset) const noexcept - { - return strided_data_end(*this, begin, l, offset); - } - - template - inline auto xcontainer::mutable_shape() -> inner_shape_type& - { - return derived_cast().shape_impl(); - } - - template - inline auto xcontainer::mutable_strides() -> inner_strides_type& - { - return derived_cast().strides_impl(); - } - - template - inline auto xcontainer::mutable_backstrides() -> inner_backstrides_type& - { - return derived_cast().backstrides_impl(); - } - - /** - * @name Size and shape - */ - //@{ - /** - * Returns the number of element in the container. - */ - template - inline auto xcontainer::size() const noexcept -> size_type - { - return contiguous_layout ? storage().size() : compute_size(shape()); - } - - /** - * Returns the number of dimensions of the container. - */ - template - XTENSOR_CONSTEXPR_RETURN auto xcontainer::dimension() const noexcept -> size_type - { - return shape().size(); - } - - /** - * Returns the shape of the container. - */ - template - XTENSOR_CONSTEXPR_RETURN auto xcontainer::shape() const noexcept -> const inner_shape_type& - { - return derived_cast().shape_impl(); - } - - /** - * Returns the strides of the container. - */ - template - XTENSOR_CONSTEXPR_RETURN auto xcontainer::strides() const noexcept -> const inner_strides_type& - { - return derived_cast().strides_impl(); - } - - /** - * Returns the backstrides of the container. - */ - template - XTENSOR_CONSTEXPR_RETURN auto xcontainer::backstrides() const noexcept -> const inner_backstrides_type& - { - return derived_cast().backstrides_impl(); - } - //@} - - /** - * @name Data - */ - //@{ - - /** - * Fills the container with the given value. - * @param value the value to fill the container with. - */ - template - template - inline void xcontainer::fill(const T& value) - { - std::fill(storage_begin(), storage_end(), value); - } - - /** - * Returns a reference to the element at the specified position in the container. - * @param args a list of indices specifying the position in the container. Indices - * must be unsigned integers, the number of indices should be equal or greater than - * the number of dimensions of the container. - */ - template - template - inline auto xcontainer::operator()(Args... args) -> reference - { - XTENSOR_TRY(check_index(shape(), args...)); - XTENSOR_CHECK_DIMENSION(shape(), args...); - size_type index = xt::data_offset(strides(), static_cast(args)...); - return storage()[index]; - } - - /** - * Returns a constant reference to the element at the specified position in the container. - * @param args a list of indices specifying the position in the container. Indices - * must be unsigned integers, the number of indices should be equal or greater than - * the number of dimensions of the container. - */ - template - template - inline auto xcontainer::operator()(Args... args) const -> const_reference - { - XTENSOR_TRY(check_index(shape(), args...)); - XTENSOR_CHECK_DIMENSION(shape(), args...); - size_type index = xt::data_offset(strides(), static_cast(args)...); - return storage()[index]; - } - - /** - * Returns a reference to the element at the specified position in the container. - * @param args a list of indices specifying the position in the container. Indices - * must be unsigned integers, the number of indices must be equal to the number of - * dimensions of the container, else the behavior is undefined. - * - * @warning This method is meant for performance, for expressions with a dynamic - * number of dimensions (i.e. not known at compile time). Since it may have - * undefined behavior (see parameters), operator() should be prefered whenever - * it is possible. - * @warning This method is NOT compatible with broadcasting, meaning the following - * code has undefined behavior: - * \code{.cpp} - * xt::xarray a = {{0, 1}, {2, 3}}; - * xt::xarray b = {0, 1}; - * auto fd = a + b; - * double res = fd.uncheked(0, 1); - * \endcode - */ - template - template - inline auto xcontainer::unchecked(Args... args) -> reference - { - size_type index = xt::unchecked_data_offset(strides(), static_cast(args)...); - return storage()[index]; - } - - /** - * Returns a constant reference to the element at the specified position in the container. - * @param args a list of indices specifying the position in the container. Indices - * must be unsigned integers, the number of indices must be equal to the number of - * dimensions of the container, else the behavior is undefined. - * - * @warning This method is meant for performance, for expressions with a dynamic - * number of dimensions (i.e. not known at compile time). Since it may have - * undefined behavior (see parameters), operator() should be prefered whenever - * it is possible. - * @warning This method is NOT compatible with broadcasting, meaning the following - * code has undefined behavior: - * \code{.cpp} - * xt::xarray a = {{0, 1}, {2, 3}}; - * xt::xarray b = {0, 1}; - * auto fd = a + b; - * double res = fd.uncheked(0, 1); - * \endcode - */ - template - template - inline auto xcontainer::unchecked(Args... args) const -> const_reference - { - size_type index = xt::unchecked_data_offset(strides(), static_cast(args)...); - return storage()[index]; - } - - /** - * Returns a reference to the element at the specified position in the container. - * @param first iterator starting the sequence of indices - * @param last iterator ending the sequence of indices - * The number of indices in the sequence should be equal to or greater - * than the number of dimensions of the container. - */ - template - template - inline auto xcontainer::element(It first, It last) -> reference - { - XTENSOR_TRY(check_element_index(shape(), first, last)); - return storage()[element_offset(strides(), first, last)]; - } - - /** - * Returns a reference to the element at the specified position in the container. - * @param first iterator starting the sequence of indices - * @param last iterator ending the sequence of indices - * The number of indices in the sequence should be equal to or greater - * than the number of dimensions of the container. - */ - template - template - inline auto xcontainer::element(It first, It last) const -> const_reference - { - XTENSOR_TRY(check_element_index(shape(), first, last)); - return storage()[element_offset(strides(), first, last)]; - } - - /** - * Returns a reference to the buffer containing the elements of the container. - */ - template - inline auto xcontainer::storage() noexcept -> storage_type& - { - return derived_cast().storage_impl(); - } - - /** - * Returns a constant reference to the buffer containing the elements of the - * container. - */ - template - inline auto xcontainer::storage() const noexcept -> const storage_type& - { - return derived_cast().storage_impl(); - } - - /** - * Returns a pointer to the underlying array serving as element storage. The pointer - * is such that range [data(); data() + size()] is always a valid range, even if the - * container is empty (data() is not is not dereferenceable in that case) - */ - template - inline auto xcontainer::data() noexcept -> value_type* - { - return storage().data(); - } - - /** - * Returns a constant pointer to the underlying array serving as element storage. The pointer - * is such that range [data(); data() + size()] is always a valid range, even if the - * container is empty (data() is not is not dereferenceable in that case) - */ - template - inline auto xcontainer::data() const noexcept -> const value_type* - { - return storage().data(); - } - - /** - * Returns the offset to the first element in the container. - */ - template - inline auto xcontainer::data_offset() const noexcept -> const size_type - { - return size_type(0); - } - //@} - - /** - * @name Broadcasting - */ - //@{ - /** - * Broadcast the shape of the container to the specified parameter. - * @param shape the result shape - * @param reuse_cache parameter for internal optimization - * @return a boolean indicating whether the broadcasting is trivial - */ - template - template - inline bool xcontainer::broadcast_shape(S& shape, bool) const - { - return xt::broadcast_shape(this->shape(), shape); - } - - /** - * Checks whether the xcontainer can be linearly assigned to an expression - * with the specified strides. - * @return a boolean indicating whether a linear assign is possible - */ - template - template - inline bool xcontainer::has_linear_assign(const S& str) const noexcept - { - return str.size() == strides().size() && - std::equal(str.cbegin(), str.cend(), strides().begin()); - } - //@} - - template - inline auto xcontainer::derived_cast() const & noexcept -> const derived_type& - { - return *static_cast(this); - } - - template - inline auto xcontainer::derived_cast() && noexcept -> derived_type - { - return *static_cast(this); - } - - template - inline auto xcontainer::data_element(size_type i) -> reference - { - return storage()[i]; - } - - template - inline auto xcontainer::data_element(size_type i) const -> const_reference - { - return storage()[i]; - } - - /*************** - * stepper api * - ***************/ - - template - template - inline auto xcontainer::stepper_begin(const S& shape) noexcept -> stepper - { - size_type offset = shape.size() - dimension(); - return stepper(static_cast(this), data_xbegin(), offset); - } - - template - template - inline auto xcontainer::stepper_end(const S& shape, layout_type l) noexcept -> stepper - { - size_type offset = shape.size() - dimension(); - return stepper(static_cast(this), data_xend(l, offset), offset); - } - - template - template - inline auto xcontainer::stepper_begin(const S& shape) const noexcept -> const_stepper - { - size_type offset = shape.size() - dimension(); - return const_stepper(static_cast(this), data_xbegin(), offset); - } - - template - template - inline auto xcontainer::stepper_end(const S& shape, layout_type l) const noexcept -> const_stepper - { - size_type offset = shape.size() - dimension(); - return const_stepper(static_cast(this), data_xend(l, offset), offset); - } - - template - inline auto xcontainer::data_xbegin() noexcept -> container_iterator - { - return storage().begin(); - } - - template - inline auto xcontainer::data_xbegin() const noexcept -> const_container_iterator - { - return storage().cbegin(); - } - - template - inline auto xcontainer::data_xend(layout_type l, size_type offset) noexcept -> container_iterator - { - return data_xend_impl(storage().begin(), l, offset); - } - - template - inline auto xcontainer::data_xend(layout_type l, size_type offset) const noexcept -> const_container_iterator - { - return data_xend_impl(storage().cbegin(), l, offset); - } - - template - template - inline void xcontainer::store_simd(size_type i, const simd& e) - { - using align_mode = driven_align_mode_t; - xt_simd::store_simd(&(storage()[i]), e, align_mode()); - } - - template - template - inline auto xcontainer::load_simd(size_type i) const - -> container_simd_return_type_t - //-> simd_return_type - { - using align_mode = driven_align_mode_t; - return xt_simd::load_simd(&(storage()[i]), align_mode()); - } - - template - inline auto xcontainer::storage_begin() noexcept -> storage_iterator - { - return storage().begin(); - } - - template - inline auto xcontainer::storage_end() noexcept -> storage_iterator - { - return storage().end(); - } - - template - inline auto xcontainer::storage_begin() const noexcept -> const_storage_iterator - { - return storage().begin(); - } - - template - inline auto xcontainer::storage_end() const noexcept -> const_storage_iterator - { - return storage().cend(); - } - - template - inline auto xcontainer::storage_cbegin() const noexcept -> const_storage_iterator - { - return storage().cbegin(); - } - - template - inline auto xcontainer::storage_cend() const noexcept -> const_storage_iterator - { - return storage().cend(); - } - - template - inline auto xcontainer::storage_rbegin() noexcept -> reverse_storage_iterator - { - return storage().rbegin(); - } - - template - inline auto xcontainer::storage_rend() noexcept -> reverse_storage_iterator - { - return storage().rend(); - } - - template - inline auto xcontainer::storage_rbegin() const noexcept -> const_reverse_storage_iterator - { - return storage().rbegin(); - } - - template - inline auto xcontainer::storage_rend() const noexcept -> const_reverse_storage_iterator - { - return storage().rend(); - } - - template - inline auto xcontainer::storage_crbegin() const noexcept -> const_reverse_storage_iterator - { - return storage().crbegin(); - } - - template - inline auto xcontainer::storage_crend() const noexcept -> const_reverse_storage_iterator - { - return storage().crend(); - } - - template - inline auto xcontainer::derived_cast() & noexcept -> derived_type& - { - return *static_cast(this); - } - - /************************************* - * xstrided_container implementation * - *************************************/ - - template - inline xstrided_container::xstrided_container() noexcept - : base_type() - { - m_shape = xtl::make_sequence(base_type::dimension(), 0); - m_strides = xtl::make_sequence(base_type::dimension(), 0); - m_backstrides = xtl::make_sequence(base_type::dimension(), 0); - } - - template - inline xstrided_container::xstrided_container(inner_shape_type&& shape, inner_strides_type&& strides) noexcept - : base_type(), m_shape(std::move(shape)), m_strides(std::move(strides)) - { - m_backstrides = xtl::make_sequence(m_shape.size(), 0); - adapt_strides(m_shape, m_strides, m_backstrides); - } - - template - inline xstrided_container::xstrided_container(inner_shape_type&& shape, inner_strides_type&& strides, inner_backstrides_type&& backstrides, layout_type&& layout) noexcept - : base_type(), m_shape(std::move(shape)), m_strides(std::move(strides)), m_backstrides(std::move(backstrides)), m_layout(std::move(layout)) - { - } - - template - inline auto xstrided_container::shape_impl() noexcept -> inner_shape_type& - { - return m_shape; - } - - template - inline auto xstrided_container::shape_impl() const noexcept -> const inner_shape_type& - { - return m_shape; - } - - template - inline auto xstrided_container::strides_impl() noexcept -> inner_strides_type& - { - return m_strides; - } - - template - inline auto xstrided_container::strides_impl() const noexcept -> const inner_strides_type& - { - return m_strides; - } - - template - inline auto xstrided_container::backstrides_impl() noexcept -> inner_backstrides_type& - { - return m_backstrides; - } - - template - inline auto xstrided_container::backstrides_impl() const noexcept -> const inner_backstrides_type& - { - return m_backstrides; - } - - /** - * Return the layout_type of the container - * @return layout_type of the container - */ - template - layout_type xstrided_container::layout() const noexcept - { - return m_layout; - } - - namespace detail - { - template - inline void resize_data_container(C& c, S size) - { - xt::resize_container(c, size); - } - - template - inline void resize_data_container(const C& c, S size) - { - (void) c; // remove unused parameter warning - (void) size; - XTENSOR_ASSERT_MSG(c.size() == size, "Trying to resize const data container with wrong size."); - } - } - - /** - * Resizes the container. - * @warning Contrary to STL containers like std::vector, resize - * does NOT preserve the container elements. - * @param shape the new shape - * @param force force reshaping, even if the shape stays the same (default: false) - */ - template - template - inline void xstrided_container::resize(S&& shape, bool force) - { - std::size_t dim = shape.size(); - if (m_shape.size() != dim || !std::equal(std::begin(shape), std::end(shape), std::begin(m_shape)) || force) - { - if (D::static_layout == layout_type::dynamic && m_layout == layout_type::dynamic) - { - m_layout = XTENSOR_DEFAULT_LAYOUT; // fall back to default layout - } - m_shape = xtl::forward_sequence(shape); - resize_container(m_strides, dim); - resize_container(m_backstrides, dim); - size_type data_size = compute_strides(m_shape, m_layout, m_strides, m_backstrides); - detail::resize_data_container(this->storage(), data_size); - } - } - - /** - * Resizes the container. - * @warning Contrary to STL containers like std::vector, resize - * does NOT preserve the container elements. - * @param shape the new shape - * @param l the new layout_type - */ - template - template - inline void xstrided_container::resize(S&& shape, layout_type l) - { - if (base_type::static_layout != layout_type::dynamic && l != base_type::static_layout) - { - throw std::runtime_error("Cannot change layout_type if template parameter not layout_type::dynamic."); - } - m_layout = l; - resize(std::forward(shape), true); - } - - /** - * Resizes the container. - * @warning Contrary to STL containers like std::vector, resize - * does NOT preserve the container elements. - * @param shape the new shape - * @param strides the new strides - */ - template - template - inline void xstrided_container::resize(S&& shape, const strides_type& strides) - { - if (base_type::static_layout != layout_type::dynamic) - { - throw std::runtime_error("Cannot resize with custom strides when layout() is != layout_type::dynamic."); - } - m_shape = xtl::forward_sequence(shape); - m_strides = strides; - resize_container(m_backstrides, m_strides.size()); - adapt_strides(m_shape, m_strides, m_backstrides); - m_layout = layout_type::dynamic; - detail::resize_data_container(this->storage(), compute_size(m_shape)); - } - - /** - * Reshapes the container and keeps old elements. The `shape` argument can have one of its value - * equal to `-1`, in this case the value is inferred from the number of elements in the container - * and the remaining values in the `shape`. - * \code{.cpp} - * xt::xarray a = { 1, 2, 3, 4, 5, 6, 7, 8 }; - * a.reshape({-1, 4}); - * //a.shape() is {2, 4} - * \endcode - * @param shape the new shape (has to have same number of elements as the original container) - * @param layout the layout to compute the strides (defaults to static layout of the container, - * or for a container with dynamic layout to XTENSOR_DEFAULT_LAYOUT) - */ - template - template - inline void xstrided_container::reshape(S&& shape, layout_type layout) - { - reshape_impl(std::forward(shape), std::is_signed::value_type>>(), std::forward(layout)); - } - - template - template - inline void xstrided_container::reshape(std::initializer_list shape, layout_type layout) - { - using sh_type = rebind_container_t; - sh_type sh = xtl::make_sequence(shape.size()); - std::copy(shape.begin(), shape.end(), sh.begin()); - reshape_impl(std::move(sh), std::is_signed(), std::forward(layout)); - } - - template - template - inline void xstrided_container::reshape_impl(S&& shape, std::false_type /* is unsigned */, layout_type layout) - { - if (compute_size(shape) != this->size()) - { - throw std::runtime_error("Cannot reshape with incorrect number of elements. Do you mean to resize?"); - } - if (D::static_layout == layout_type::dynamic && layout == layout_type::dynamic) - { - layout = XTENSOR_DEFAULT_LAYOUT; // fall back to default layout - } - if (D::static_layout != layout_type::dynamic && layout != D::static_layout) - { - throw std::runtime_error("Cannot reshape with different layout if static layout != dynamic."); - } - m_layout = layout; - m_shape = xtl::forward_sequence(shape); - resize_container(m_strides, m_shape.size()); - resize_container(m_backstrides, m_shape.size()); - compute_strides(m_shape, m_layout, m_strides, m_backstrides); - } - template - template - inline void xstrided_container::reshape_impl(S&& _shape, std::true_type /* is signed */, layout_type layout) - { - using value_type = typename std::decay_t::value_type; - if (this->size() % compute_size(_shape)) - { - throw std::runtime_error("Negative axis size cannot be inferred. Shape mismatch."); - } - std::decay_t shape = _shape; - value_type accumulator = 1; - std::size_t neg_idx = 0; - std::size_t i = 0; - for(auto it = shape.begin(); it != shape.end(); ++it, i++) - { - auto&& dim = *it; - if(dim < 0) - { - XTENSOR_ASSERT(dim == -1 && !neg_idx); - neg_idx = i; - } - accumulator *= dim; - } - if(accumulator < 0) - { - shape[neg_idx] = static_cast(this->size()) / std::abs(accumulator); - } - m_layout = layout; - m_shape = xtl::forward_sequence(shape); - resize_container(m_strides, m_shape.size()); - resize_container(m_backstrides, m_shape.size()); - compute_strides(m_shape, m_layout, m_strides, m_backstrides); - } -} - -#endif diff --git a/vendor/xtensor/include/xtensor/xcsv.hpp b/vendor/xtensor/include/xtensor/xcsv.hpp deleted file mode 100644 index 6a98fa4490..0000000000 --- a/vendor/xtensor/include/xtensor/xcsv.hpp +++ /dev/null @@ -1,198 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_CSV_HPP -#define XTENSOR_CSV_HPP - -#include -#include -#include -#include -#include -#include - -#include "xtensor.hpp" - -namespace xt -{ - - /************************************** - * load_csv and dump_csv declarations * - **************************************/ - - template > - using xcsv_tensor = xtensor_container, 2, layout_type::row_major>; - - template > - xcsv_tensor load_csv(std::istream& stream, const char delimiter = ',', const std::size_t skip_rows = 0, const ptrdiff_t max_rows = -1, const std::string comments = "#"); - - template - void dump_csv(std::ostream& stream, const xexpression& e); - - /***************************************** - * load_csv and dump_csv implementations * - *****************************************/ - - namespace detail - { - template - inline T lexical_cast(const std::string& cell) - { - T res; - std::istringstream iss(cell); - iss >> res; - return res; - } - - template <> - inline std::string lexical_cast(const std::string& cell) - { - size_t first = cell.find_first_not_of(' '); - if (first == std::string::npos) - return cell; - - size_t last = cell.find_last_not_of(' '); - return cell.substr(first, last==std::string::npos?cell.size():last+1); - } - - template <> - inline float lexical_cast(const std::string& cell) { return std::stof(cell); } - - template <> - inline double lexical_cast(const std::string& cell) { return std::stod(cell); } - - template <> - inline long double lexical_cast(const std::string& cell) { return std::stold(cell); } - - template <> - inline int lexical_cast(const std::string& cell) { return std::stoi(cell); } - - template <> - inline long lexical_cast(const std::string& cell) { return std::stol(cell); } - - template <> - inline long long lexical_cast(const std::string& cell) { return std::stoll(cell); } - - template <> - inline unsigned int lexical_cast(const std::string& cell) { return static_cast(std::stoul(cell)); } - - template <> - inline unsigned long lexical_cast(const std::string& cell) { return std::stoul(cell); } - - template <> - inline unsigned long long lexical_cast(const std::string& cell) { return std::stoull(cell); } - - template - ST load_csv_row(std::istream& row_stream, OI output, std::string cell, const char delimiter = ',') - { - ST length = 0; - while (std::getline(row_stream, cell, delimiter)) - { - *output++ = lexical_cast(cell); - ++length; - } - return length; - } - } - - /** - * @brief Load tensor from CSV. - * - * Returns an \ref xexpression for the parsed CSV - * @param stream the input stream containing the CSV encoded values - * @param delimiter the character used to separate values. [default: ','] - * @param skip the first skip_rows lines. [default: 0] - * @param read max_rows lines of content after skip_rows lines; the default is to read all the lines. [default: -1] - * @param comments the string used to indicate the start of a comment. [default: "#"] - */ - template - xcsv_tensor load_csv(std::istream& stream, const char delimiter, const std::size_t skip_rows, const std::ptrdiff_t max_rows, const std::string comments) - { - using tensor_type = xcsv_tensor; - using storage_type = typename tensor_type::storage_type; - using size_type = typename tensor_type::size_type; - using inner_shape_type = typename tensor_type::inner_shape_type; - using inner_strides_type = typename tensor_type::inner_strides_type; - using output_iterator = std::back_insert_iterator; - - storage_type data; - size_type nbrow = 0, nbcol = 0, nhead = 0; - { - output_iterator output(data); - std::string row, cell; - while (std::getline(stream, row)) - { - if (nhead < skip_rows) - { - ++nhead; - continue; - } - if (std::equal(comments.begin(), comments.end(), row.begin())) - { - continue; - } - if (0 < max_rows && max_rows <= static_cast(nbrow)) - { - break; - } - std::stringstream row_stream(row); - nbcol = detail::load_csv_row(row_stream, output, cell, delimiter); - ++nbrow; - } - } - inner_shape_type shape = {nbrow, nbcol}; - inner_strides_type strides; // no need for initializer list for stack-allocated strides_type - size_type data_size = compute_strides(shape, layout_type::row_major, strides); - // Sanity check for data size. - if (data.size() != data_size) - { - throw std::runtime_error("Inconsistent row lengths in CSV"); - } - return tensor_type(std::move(data), std::move(shape), std::move(strides)); - } - - /** - * @brief Dump tensor to CSV. - * - * @param stream the output stream to write the CSV encoded values - * @param e the tensor expression to serialize - */ - template - void dump_csv(std::ostream& stream, const xexpression& e) - { - using size_type = typename E::size_type; - const E& ex = e.derived_cast(); - if (ex.dimension() != 2) - { - throw std::runtime_error("Only 2-D expressions can be serialized to CSV"); - } - size_type nbrows = ex.shape()[0], nbcols = ex.shape()[1]; - auto st = ex.stepper_begin(ex.shape()); - for (size_type r = 0; r != nbrows; ++r) - { - for (size_type c = 0; c != nbcols; ++c) - { - stream << *st; - if (c != nbcols - 1) - { - st.step(1); - stream << ','; - } - else - { - st.reset(1); - st.step(0); - stream << std::endl; - } - } - } - } -} - -#endif diff --git a/vendor/xtensor/include/xtensor/xdynamic_view.hpp b/vendor/xtensor/include/xtensor/xdynamic_view.hpp deleted file mode 100644 index 345cb14209..0000000000 --- a/vendor/xtensor/include/xtensor/xdynamic_view.hpp +++ /dev/null @@ -1,704 +0,0 @@ -/*************************************************************************** -* Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_DYNAMIC_VIEW_HPP -#define XTENSOR_DYNAMIC_VIEW_HPP - -#include -#include - -#include "xexpression.hpp" -#include "xiterable.hpp" -#include "xlayout.hpp" -#include "xsemantic.hpp" -#include "xstrided_view_base.hpp" - -namespace xt -{ - - template - class xdynamic_view; - - template - struct xcontainer_inner_types> - { - using xexpression_type = std::decay_t; - using undecay_expression = CT; - using reference = inner_reference_t; - using const_reference = typename xexpression_type::const_reference; - using size_type = typename xexpression_type::size_type; - using shape_type = std::decay_t; - using undecay_shape = S; - using storage_getter = FST; - using inner_storage_type = typename storage_getter::type; - using temporary_type = xarray, xexpression_type::static_layout>; - static constexpr layout_type layout = L; - }; - - template - struct xiterable_inner_types> - { - using inner_shape_type = S; - using inner_strides_type = inner_shape_type; - using inner_backstrides_type = inner_shape_type; - -#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ == 8 - constexpr static auto random_instantiation_var_for_gcc8_data_iface = has_data_interface>::value; - constexpr static auto random_instantiation_var_for_gcc8_has_strides = has_strides>::value; -#endif - - // TODO: implement efficient stepper specific to the dynamic_view - using const_stepper = xindexed_stepper, true>; - using stepper = xindexed_stepper, false>; - }; - - /**************************** - * xdynamic_view extensions * - ****************************/ - - namespace extension - { - template - struct xdynamic_view_base_impl; - - template - struct xdynamic_view_base_impl - { - using type = xtensor_empty_base; - }; - - template - struct xdynamic_view_base - : xdynamic_view_base_impl, CT, S, L, FST> - { - }; - - template - using xdynamic_view_base_t = typename xdynamic_view_base::type; - } - - /***************** - * xdynamic_view * - *****************/ - - namespace detail - { - template - class xfake_slice; - } - - template > - class xdynamic_view : public xview_semantic>, - public xiterable>, - public extension::xdynamic_view_base_t, - private xstrided_view_base> - { - public: - - using self_type = xdynamic_view; - using base_type = xstrided_view_base; - using semantic_base = xview_semantic; - using extension_base = extension::xdynamic_view_base_t; - using expression_tag = typename extension_base::expression_tag; - - using xexpression_type = typename base_type::xexpression_type; - using base_type::is_const; - - using value_type = typename base_type::value_type; - using reference = typename base_type::reference; - using const_reference = typename base_type::const_reference; - using pointer = typename base_type::pointer; - using const_pointer = typename base_type::const_pointer; - using size_type = typename base_type::size_type; - using difference_type = typename base_type::difference_type; - - using inner_storage_type = typename base_type::inner_storage_type; - using storage_type = typename base_type::storage_type; - - using iterable_base = xiterable; - using inner_shape_type = typename iterable_base::inner_shape_type; - using inner_strides_type = typename base_type::inner_strides_type; - using inner_backstrides_type = typename base_type::inner_backstrides_type; - - using shape_type = typename base_type::shape_type; - using strides_type = typename base_type::strides_type; - using backstrides_type = typename base_type::backstrides_type; - - using stepper = typename iterable_base::stepper; - using const_stepper = typename iterable_base::const_stepper; - - using base_type::static_layout; - using base_type::contiguous_layout; - - using temporary_type = typename xcontainer_inner_types::temporary_type; - using base_index_type = xindex_type_t; - - using simd_value_type = typename base_type::simd_value_type; - using bool_load_type = typename base_type::bool_load_type; - - using strides_vt = typename strides_type::value_type; - using slice_type = xtl::variant, xkeep_slice, xdrop_slice>; - using slice_vector_type = std::vector; - - template - xdynamic_view(CTA&& e, SA&& shape, get_strides_t&& strides, std::size_t offset, layout_type layout, - slice_vector_type&& slices, get_strides_t&& adj_strides) noexcept; - - template - self_type& operator=(const xexpression& e); - - template - disable_xexpression& operator=(const E& e); - - using base_type::size; - using base_type::dimension; - using base_type::shape; - using base_type::layout; - - // Explicitly deleting strides method to avoid compilers complaining - // about not being able to call the strides method from xstrided_view_base - // private base - const inner_strides_type& strides() const noexcept = delete; - - reference operator()(); - const_reference operator()() const; - - template - reference operator()(Args... args); - - template - const_reference operator()(Args... args) const; - - template - reference unchecked(Args... args); - - template - const_reference unchecked(Args... args) const; - - using base_type::operator[]; - using base_type::at; - using base_type::periodic; - using base_type::in_bounds; - - template - reference element(It first, It last); - - template - const_reference element(It first, It last) const; - - size_type data_offset() const noexcept; - - // Explicitly deleting data methods so has_data_interface results - // to false instead of having compilers complaining about not being - // able to call the methods from the private base - value_type* data() noexcept = delete; - const value_type* data() const noexcept = delete; - - using base_type::storage; - using base_type::expression; - using base_type::broadcast_shape; - - template - bool has_linear_assign(const O& str) const noexcept; - - template - void fill(const T& value); - - template - stepper stepper_begin(const ST& shape); - template - stepper stepper_end(const ST& shape, layout_type l); - - template - const_stepper stepper_begin(const ST& shape) const; - template - const_stepper stepper_end(const ST& shape, layout_type l) const; - - using container_iterator = std::conditional_t; - using const_container_iterator = typename storage_type::const_iterator; - - template - using rebind_t = xdynamic_view>; - - template - rebind_t build_view(E&& e) const; - - private: - - using offset_type = typename base_type::offset_type; - - slice_vector_type m_slices; - inner_strides_type m_adj_strides; - - container_iterator data_xbegin() noexcept; - const_container_iterator data_xbegin() const noexcept; - container_iterator data_xend(layout_type l, size_type offset) noexcept; - const_container_iterator data_xend(layout_type l, size_type offset) const noexcept; - - template - It data_xbegin_impl(It begin) const noexcept; - - template - It data_xend_impl(It end, layout_type l, size_type offset) const noexcept; - - void assign_temporary_impl(temporary_type&& tmp); - - template - offset_type adjust_offset(offset_type offset, T idx, Args... args) const noexcept; - offset_type adjust_offset(offset_type offset) const noexcept; - - template - offset_type adjust_offset_impl(offset_type offset, size_type idx_offset, T idx, Args... args) const noexcept; - offset_type adjust_offset_impl(offset_type offset, size_type idx_offset) const noexcept; - - template - offset_type adjust_element_offset(offset_type offset, It first, It last) const noexcept; - - template - friend class xstepper; - friend class xview_semantic; - friend class xaccessible; - friend class xconst_accessible; - }; - - /************************** - * xdynamic_view builders * - **************************/ - - template - using xdynamic_slice = xtl::variant< - T, - - xrange_adaptor, - xrange_adaptor, - xrange_adaptor, - - xrange_adaptor, - xrange_adaptor, - xrange_adaptor, - - xrange_adaptor, - xrange_adaptor, - - xrange, - xstepped_range, - - xkeep_slice, - xdrop_slice, - - xall_tag, - xellipsis_tag, - xnewaxis_tag - >; - - using xdynamic_slice_vector = std::vector>; - - template - auto dynamic_view(E&& e, const xdynamic_slice_vector& slices); - - /****************************** - * xfake_slice implementation * - ******************************/ - - namespace detail - { - template - class xfake_slice : public xslice> - { - public: - - using size_type = T; - using self_type = xfake_slice; - - xfake_slice() = default; - - size_type operator()(size_type /*i*/) const noexcept - { - return size_type(0); - } - - size_type size() const noexcept - { - return size_type(1); - } - - size_type step_size() const noexcept - { - return size_type(0); - } - - size_type step_size(std::size_t /*i*/, std::size_t /*n*/ = 1) const noexcept - { - return size_type(0); - } - - size_type revert_index(std::size_t i) const noexcept - { - return i; - } - - bool contains(size_type /*i*/) const noexcept - { - return true; - } - - bool operator==(const self_type& /*rhs*/) const noexcept - { - return true; - } - - bool operator!=(const self_type& /*rhs*/) const noexcept - { - return false; - } - }; - } - - /******************************** - * xdynamic_view implementation * - ********************************/ - - template - template - inline xdynamic_view::xdynamic_view(CTA&& e, SA&& shape, get_strides_t&& strides, - std::size_t offset, layout_type layout, - slice_vector_type&& slices, get_strides_t&& adj_strides) noexcept - : base_type(std::forward(e), std::forward(shape), std::move(strides), offset, layout), - m_slices(std::move(slices)), m_adj_strides(std::move(adj_strides)) - { - } - - template - template - inline auto xdynamic_view::operator=(const xexpression& e) -> self_type& - { - return semantic_base::operator=(e); - } - - template - template - inline auto xdynamic_view::operator=(const E& e) -> disable_xexpression& - { - std::fill(this->begin(), this->end(), e); - return *this; - } - - template - inline auto xdynamic_view::operator()() -> reference - { - return base_type::storage()[data_offset()]; - } - - template - inline auto xdynamic_view::operator()() const -> const_reference - { - return base_type::storage()[data_offset()]; - } - - template - template - inline auto xdynamic_view::operator()(Args... args) -> reference - { - XTENSOR_TRY(check_index(base_type::shape(), args...)); - XTENSOR_CHECK_DIMENSION(base_type::shape(), args...); - offset_type offset = base_type::compute_index(args...); - offset = adjust_offset(offset, args...); - return base_type::storage()[static_cast(offset)]; - } - - template - template - inline auto xdynamic_view::operator()(Args... args) const -> const_reference - { - XTENSOR_TRY(check_index(base_type::shape(), args...)); - XTENSOR_CHECK_DIMENSION(base_type::shape(), args...); - offset_type offset = base_type::compute_index(args...); - offset = adjust_offset(offset, args...); - return base_type::storage()[static_cast(offset)]; - } - - template - template - inline bool xdynamic_view::has_linear_assign(const O&) const noexcept - { - return false; - } - - template - template - inline auto xdynamic_view::unchecked(Args... args) -> reference - { - offset_type offset = base_type::compute_unchecked_index(args...); - offset = adjust_offset(args...); - return base_type::storage()[static_cast(offset)]; - } - - template - template - inline auto xdynamic_view::unchecked(Args... args) const -> const_reference - { - offset_type offset = base_type::compute_unchecked_index(args...); - offset = adjust_offset(args...); - return base_type::storage()[static_cast(offset)]; - } - - template - template - inline auto xdynamic_view::element(It first, It last) -> reference - { - XTENSOR_TRY(check_element_index(base_type::shape(), first, last)); - offset_type offset = base_type::compute_element_index(first, last); - offset = adjust_element_offset(offset, first, last); - return base_type::storage()[static_cast(offset)]; - } - - template - template - inline auto xdynamic_view::element(It first, It last) const -> const_reference - { - XTENSOR_TRY(check_element_index(base_type::shape(), first, last)); - offset_type offset = base_type::compute_element_index(first, last); - offset = adjust_element_offset(offset, first, last); - return base_type::storage()[static_cast(offset)]; - } - - template - inline auto xdynamic_view::data_offset() const noexcept -> size_type - { - size_type offset = base_type::data_offset(); - size_type sl_offset = xtl::visit([](const auto& sl) { return sl(size_type(0)); }, m_slices[0]); - return offset + sl_offset * m_adj_strides[0]; - } - - template - template - inline void xdynamic_view::fill(const T& value) - { - return std::fill(this->storage_begin(), this->storage_end(), value); - } - - template - template - inline auto xdynamic_view::stepper_begin(const ST& shape) -> stepper - { - size_type offset = shape.size() - dimension(); - return stepper(this, offset); - } - - template - template - inline auto xdynamic_view::stepper_end(const ST& shape, layout_type /*l*/) -> stepper - { - size_type offset = shape.size() - dimension(); - return stepper(this, offset, true); - } - - template - template - inline auto xdynamic_view::stepper_begin(const ST& shape) const -> const_stepper - { - size_type offset = shape.size() - dimension(); - return const_stepper(this, offset); - } - - template - template - inline auto xdynamic_view::stepper_end(const ST& shape, layout_type /*l*/) const -> const_stepper - { - size_type offset = shape.size() - dimension(); - return const_stepper(this, offset, true); - } - - template - template - inline auto xdynamic_view::build_view(E&& e) const -> rebind_t - { - inner_shape_type sh(this->shape()); - inner_strides_type str(base_type::strides()); - slice_vector_type svt(m_slices); - inner_strides_type adj_str(m_adj_strides); - return rebind_t(std::forward(e), std::move(sh), std::move(str), - base_type::data_offset(), this->layout(), std::move(svt), std::move(adj_str)); - } - - template - inline auto xdynamic_view::data_xbegin() noexcept -> container_iterator - { - return data_xbegin_impl(this->storage().begin()); - } - - template - inline auto xdynamic_view::data_xbegin() const noexcept -> const_container_iterator - { - return data_xbegin_impl(this->storage().cbegin()); - } - - template - inline auto xdynamic_view::data_xend(layout_type l, size_type offset) noexcept -> container_iterator - { - return data_xend_impl(this->storage().begin(), l, offset); - } - - template - inline auto xdynamic_view::data_xend(layout_type l, size_type offset) const noexcept -> const_container_iterator - { - return data_xend_impl(this->storage().cbegin(), l, offset); - } - - template - template - inline It xdynamic_view::data_xbegin_impl(It begin) const noexcept - { - return begin + static_cast(data_offset()); - } - - // TODO: fix the data_xend implementation and assign_temporary_impl - - template - template - inline It xdynamic_view::data_xend_impl(It begin, layout_type l, size_type offset) const noexcept - { - return strided_data_end(*this, begin + std::ptrdiff_t(data_offset()), l, offset); - } - - template - inline void xdynamic_view::assign_temporary_impl(temporary_type&& tmp) - { - std::copy(tmp.cbegin(), tmp.cend(), this->begin()); - } - - template - template - inline auto xdynamic_view::adjust_offset(offset_type offset, T idx, Args... args) const noexcept -> offset_type - { - constexpr size_type nb_args = sizeof...(Args) + 1; - size_type dim = base_type::dimension(); - offset_type res = nb_args > dim ? adjust_offset(offset, args...) : adjust_offset_impl(offset, dim - nb_args, idx, args...); - return res; - } - - template - inline auto xdynamic_view::adjust_offset(offset_type offset) const noexcept -> offset_type - { - return offset; - } - - template - template - inline auto xdynamic_view::adjust_offset_impl(offset_type offset, size_type idx_offset, T idx, Args... args) const noexcept - -> offset_type - { - offset_type sl_offset = xtl::visit([idx](const auto& sl) { - using type = typename std::decay_t::size_type; - return sl(type(idx)); - }, m_slices[idx_offset]); - offset_type res = offset + sl_offset * m_adj_strides[idx_offset]; - return adjust_offset_impl(res, idx_offset + 1, args...); - } - - template - inline auto xdynamic_view::adjust_offset_impl(offset_type offset, size_type) const noexcept - -> offset_type - { - return offset; - } - - template - template - inline auto xdynamic_view::adjust_element_offset(offset_type offset, It first, It last) const noexcept -> offset_type - { - auto dst = std::distance(first, last); - offset_type dim = static_cast(dimension()); - offset_type loop_offset = dst < dim ? dim - dst : offset_type(0); - offset_type idx_offset = dim < dst ? dst - dim : offset_type(0); - offset_type res = offset; - for (offset_type i = loop_offset; i < dim; ++i, ++first) - { - offset_type j = static_cast(first[idx_offset]); - offset_type sl_offset = xtl::visit([j](const auto& sl) { return static_cast(sl(j)); }, m_slices[static_cast(i)]); - res += sl_offset * m_adj_strides[static_cast(i)]; - } - return res; - } - - /***************************************** - * xdynamic_view builders implementation * - *****************************************/ - - namespace detail - { - template - struct adj_strides_policy - { - using slice_vector = V; - using strides_type = dynamic_shape; - - slice_vector new_slices; - strides_type new_adj_strides; - - protected: - - inline void resize(std::size_t size) - { - new_slices.resize(size); - new_adj_strides.resize(size); - } - - inline void set_fake_slice(std::size_t idx) - { - new_slices[idx] = xfake_slice(); - new_adj_strides[idx] = std::ptrdiff_t(0); - } - - template - bool fill_args(const xdynamic_slice_vector& slices, std::size_t sl_idx, - std::size_t i, std::size_t old_shape, - const ST& old_stride, - S& shape, get_strides_t& strides) - { - return fill_args_impl>(slices, sl_idx, i, old_shape, old_stride, shape, strides) - || fill_args_impl>(slices, sl_idx, i, old_shape, old_stride, shape, strides); - } - - template - bool fill_args_impl(const xdynamic_slice_vector& slices, std::size_t sl_idx, - std::size_t i, std::size_t old_shape, - const ST& old_stride, - S& shape, get_strides_t& strides) - { - auto* sl = xtl::get_if(&slices[sl_idx]); - if (sl != nullptr) - { - new_slices[i] = *sl; - auto& ns = xtl::get(new_slices[i]); - ns.normalize(old_shape); - shape[i] = static_cast(ns.size()); - strides[i] = std::ptrdiff_t(0); - new_adj_strides[i] = static_cast(old_stride); - } - return sl != nullptr; - } - }; - } - - template - inline auto dynamic_view(E&& e, const xdynamic_slice_vector& slices) - { - using view_type = xdynamic_view, dynamic_shape>; - using slice_vector = typename view_type::slice_vector_type; - using policy = detail::adj_strides_policy; - detail::strided_view_args args; - args.fill_args(e.shape(), detail::get_strides(e), detail::get_offset(e), e.layout(), slices); - return view_type(std::forward(e), std::move(args.new_shape), std::move(args.new_strides), args.new_offset, - args.new_layout, std::move(args.new_slices), std::move(args.new_adj_strides)); - } -} - -#endif diff --git a/vendor/xtensor/include/xtensor/xeval.hpp b/vendor/xtensor/include/xtensor/xeval.hpp deleted file mode 100644 index 04fc5fd265..0000000000 --- a/vendor/xtensor/include/xtensor/xeval.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_EVAL_HPP -#define XTENSOR_EVAL_HPP - -#include "xtensor_forward.hpp" -#include "xshape.hpp" - -namespace xt -{ - - namespace detail - { - template - using is_container = std::is_base_of>, T>; - } - - /** - * Force evaluation of xexpression. - * @return xarray or xtensor depending on shape type - * - * \code{.cpp} - * xarray 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, not an xexpression - * \endcode - */ - template - inline auto eval(T&& t) - -> std::enable_if_t>::value, T&&> - { - return std::forward(t); - } - - /// @cond DOXYGEN_INCLUDE_SFINAE - template > - inline auto eval(T&& t) - -> std::enable_if_t::value && detail::is_array::value && !detail::is_fixed::value, xtensor::value>> - { - return xtensor::value>(std::forward(t)); - } - - template > - inline auto eval(T&& t) - -> std::enable_if_t::value && !detail::is_array::value && !detail::is_fixed::value, xt::xarray> - { - return xarray(std::forward(t)); - } - - template > - inline auto eval(T&& t) - -> std::enable_if_t::value && detail::is_fixed::value && !detail::is_array::value, - xt::xtensor_fixed> - { - return xtensor_fixed(std::forward(t)); - } - /// @endcond -} - -#endif diff --git a/vendor/xtensor/include/xtensor/xexception.hpp b/vendor/xtensor/include/xtensor/xexception.hpp deleted file mode 100644 index 4daa90be5b..0000000000 --- a/vendor/xtensor/include/xtensor/xexception.hpp +++ /dev/null @@ -1,283 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_EXCEPTION_HPP -#define XTENSOR_EXCEPTION_HPP - -#include -#include -#include -#include - -namespace xt -{ - - /******************* - * broadcast_error * - *******************/ - - class broadcast_error : public std::runtime_error - { - public: - - explicit broadcast_error(const char* msg) - : std::runtime_error(msg) - { - } - }; - - template - [[noreturn]] void throw_broadcast_error(const S1& lhs, const S2& rhs); - - /********************* - * concatenate_error * - *********************/ - - class concatenate_error : public std::runtime_error - { - public: - - explicit concatenate_error(const char* msg) - : std::runtime_error(msg) - { - } - }; - - template - [[noreturn]] void throw_concatenate_error(const S1& lhs, const S2& rhs); - - /********************************** - * broadcast_error implementation * - **********************************/ - - namespace detail - { - template - inline std::string shape_error_message(const S1& lhs, const S2& rhs) - { - std::ostringstream buf("Incompatible dimension of arrays:", std::ios_base::ate); - - buf << "\n LHS shape = ("; - using size_type1 = typename S1::value_type; - std::ostream_iterator iter1(buf, ", "); - std::copy(lhs.cbegin(), lhs.cend(), iter1); - - buf << ")\n RHS shape = ("; - using size_type2 = typename S2::value_type; - std::ostream_iterator iter2(buf, ", "); - std::copy(rhs.cbegin(), rhs.cend(), iter2); - buf << ")"; - - return buf.str(); - } - } - -#ifdef NDEBUG - // Do not inline this function - template - [[noreturn]] void throw_broadcast_error(const S1&, const S2&) - { - throw broadcast_error("Incompatible dimension of arrays, compile in DEBUG for more info"); - } -#else - template - [[noreturn]] void throw_broadcast_error(const S1& lhs, const S2& rhs) - { - std::string msg = detail::shape_error_message(lhs, rhs); - throw broadcast_error(msg.c_str()); - } -#endif - - /************************************ - * concatenate_error implementation * - ************************************/ - -#ifdef NDEBUG - // Do not inline this function - template - [[noreturn]] void throw_concatenate_error(const S1&, const S2&) - { - throw concatenate_error("Incompatible dimension of arrays, compile in DEBUG for more info"); - } -#else - template - [[noreturn]] void throw_concatenate_error(const S1& lhs, const S2& rhs) - { - std::string msg = detail::shape_error_message(lhs, rhs); - throw concatenate_error(msg.c_str()); - } -#endif - - /******************* - * transpose_error * - *******************/ - - class transpose_error : public std::runtime_error - { - public: - - explicit transpose_error(const char* msg) - : std::runtime_error(msg) - { - } - }; - - /*************** - * check_index * - ***************/ - - template - void check_index(const S& shape, Args... args); - - template - void check_element_index(const S& shape, It first, It last); - - namespace detail - { - template - inline void check_index_impl(const S&) - { - } - - template - inline void check_index_impl(const S& shape, T arg, Args... args) - { - if (sizeof...(Args) + 1 > shape.size()) - { - check_index_impl(shape, args...); - } - else - { - if (std::size_t(arg) >= std::size_t(shape[dim]) && shape[dim] != 1) - { - throw std::out_of_range("index " + std::to_string(arg) + " is out of bounds for axis " - + std::to_string(dim) + " with size " + std::to_string(shape[dim])); - } - check_index_impl(shape, args...); - } - } - } - - template - inline void check_index(const S& shape, Args... args) - { - using value_type = typename S::value_type; - detail::check_index_impl(shape, static_cast(args)...); - } - - template - inline void check_element_index(const S& shape, It first, It last) - { - using value_type = typename std::iterator_traits::value_type; - using size_type = typename S::size_type; - auto dst = static_cast(last - first); - It efirst = last - static_cast((std::min)(shape.size(), dst)); - std::size_t axis = 0; - - if(shape.empty()) - { - if(first != last && *(--last) != value_type(0)) - { - throw std::out_of_range("index out of bound (empty array)"); - } - else - { - return; - } - } - else - { - while (efirst != last) - { - if (*efirst >= value_type(shape[axis]) && shape[axis] != 1) - { - throw std::out_of_range("index " + std::to_string(*efirst) + " is out of bounds for axis " - + std::to_string(axis) + " with size " + std::to_string(shape[axis])); - } - ++efirst, ++axis; - } - } - } - - /******************* - * check_dimension * - *******************/ - - template - inline void check_dimension(const S& shape, Args...) - { - if (sizeof...(Args) > shape.size()) - { - throw std::out_of_range("Number of arguments (" + std::to_string(sizeof...(Args)) + ") us greater " - + "than the number of dimensions (" + std::to_string(shape.size()) + ")"); - } - } - - /**************** - * check_access * - ****************/ - - template - inline void check_access(const S& shape, Args... args) - { - check_dimension(shape, args...); - check_index(shape, args...); - } - -#ifdef XTENSOR_ENABLE_ASSERT -#define XTENSOR_TRY(expr) XTENSOR_TRY_IMPL(expr, __FILE__, __LINE__) -#define XTENSOR_TRY_IMPL(expr, file, line) \ - try \ - { \ - expr; \ - } \ - catch (std::exception& e) \ - { \ - throw std::runtime_error(std::string(file) + ':' + std::to_string(line) + ": check failed\n\t" + std::string(e.what())); \ - } -#else -#define XTENSOR_TRY(expr) -#endif - -#ifdef XTENSOR_ENABLE_ASSERT -#define XTENSOR_ASSERT(expr) XTENSOR_ASSERT_IMPL(expr, __FILE__, __LINE__) -#define XTENSOR_ASSERT_IMPL(expr, file, line) \ - if (!(expr)) \ - { \ - throw std::runtime_error(std::string(file) + ':' + std::to_string(line) + ": assertion failed (" #expr ") \n\t"); \ - } -#else -#define XTENSOR_ASSERT(expr) -#endif - -#ifdef XTENSOR_ENABLE_CHECK_DIMENSION -#define XTENSOR_CHECK_DIMENSION(S, ARGS) XTENSOR_TRY(check_dimension(S, ARGS)) -#else -#define XTENSOR_CHECK_DIMENSION(S, ARGS) -#endif - -#ifdef XTENSOR_ENABLE_ASSERT -#define XTENSOR_ASSERT_MSG(expr, msg) \ - if (!(expr)) \ - { \ - throw std::runtime_error(std::string("Assertion error!\n") + msg + \ - "\n " + __FILE__ + '(' + std::to_string(__LINE__) + ")\n"); \ - } -#else -#define XTENSOR_ASSERT_MSG(expr, msg) -#endif - -#define XTENSOR_PRECONDITION(expr, msg) \ - if (!(expr)) \ - { \ - throw std::runtime_error(std::string("Precondition violation!\n") + msg + \ - "\n " + __FILE__ + '(' + std::to_string(__LINE__) + ")\n"); \ - } -} -#endif // XEXCEPTION_HPP diff --git a/vendor/xtensor/include/xtensor/xexpression.hpp b/vendor/xtensor/include/xtensor/xexpression.hpp deleted file mode 100644 index caf914d582..0000000000 --- a/vendor/xtensor/include/xtensor/xexpression.hpp +++ /dev/null @@ -1,759 +0,0 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#ifndef XTENSOR_EXPRESSION_HPP -#define XTENSOR_EXPRESSION_HPP - -#include -#include -#include - -#include -#include -#include - -#include "xlayout.hpp" -#include "xshape.hpp" -#include "xtensor_forward.hpp" -#include "xutils.hpp" - -namespace xt -{ - - /*************************** - * xexpression declaration * - ***************************/ - - /** - * @class xexpression - * @brief Base class for xexpressions - * - * The xexpression class is the base class for all classes representing an expression - * that can be evaluated to a multidimensional container with tensor semantic. - * Functions that can apply to any xexpression regardless of its specific type should take a - * xexpression argument. - * - * \tparam E The derived type. - * - */ - template - class xexpression - { - public: - - using derived_type = D; - - derived_type& derived_cast() & noexcept; - const derived_type& derived_cast() const & noexcept; - derived_type derived_cast() && noexcept; - - protected: - - xexpression() = default; - ~xexpression() = default; - - xexpression(const xexpression&) = default; - xexpression& operator=(const xexpression&) = default; - - xexpression(xexpression&&) = default; - xexpression& operator=(xexpression&&) = default; - }; - - /************************************ - * xsharable_expression declaration * - ************************************/ - - template - class xshared_expression; - - template - class xsharable_expression; - - namespace detail - { - template - xshared_expression make_xshared_impl(xsharable_expression&&); - } - - template - class xsharable_expression : public xexpression - { - protected: - - xsharable_expression(); - ~xsharable_expression() = default; - - xsharable_expression(const xsharable_expression&) = default; - xsharable_expression& operator=(const xsharable_expression&) = default; - - xsharable_expression(xsharable_expression&&) = default; - xsharable_expression& operator=(xsharable_expression&&) = default; - - private: - - std::shared_ptr p_shared; - - friend xshared_expression detail::make_xshared_impl(xsharable_expression&&); - }; - - /****************************** - * xexpression implementation * - ******************************/ - - /** - * @name Downcast functions - */ - //@{ - /** - * Returns a reference to the actual derived type of the xexpression. - */ - template - inline auto xexpression::derived_cast() & noexcept -> derived_type& - { - return *static_cast(this); - } - - /** - * Returns a constant reference to the actual derived type of the xexpression. - */ - template - inline auto xexpression::derived_cast() const & noexcept -> const derived_type& - { - return *static_cast(this); - } - - /** - * Returns a constant reference to the actual derived type of the xexpression. - */ - template - inline auto xexpression::derived_cast() && noexcept -> derived_type - { - return *static_cast(this); - } - //@} - - /*************************************** - * xsharable_expression implementation * - ***************************************/ - - template - inline xsharable_expression::xsharable_expression() - : p_shared(nullptr) - { - } - - /** - * is_crtp_base_of - * Resembles std::is_base_of, but adresses the problem of whether _some_ instantiation - * of a CRTP templated class B is a base of class E. A CRTP templated class is correctly - * templated with the most derived type in the CRTP hierarchy. Using this assumption, - * this implementation deals with either CRTP final classes (checks for inheritance - * with E as the CRTP parameter of B) or CRTP base classes (which are singly templated - * by the most derived class, and that's pulled out to use as a templete parameter for B). - */ - - namespace detail - { - template