Skip to content

Error upon casting load_npy during compilation #1070

@OneRaynyDay

Description

@OneRaynyDay

Reproducible code:

#define XTENSOR_USE_XSIMD

#include <iostream>
#include <xtensor/xarray.hpp>
#include <xtensor/xio.hpp>
#include <xtensor/xview.hpp>
#include <xtensor/xexpression.hpp>
#include <xtensor/xnpy.hpp>
#include <xtensor/xsort.hpp>
#include <xtensor-blas/xlinalg.hpp>
#include <unordered_map>
#include <sys/stat.h>
#include <unistd.h>
#include <chrono>


bool exists (const std::string& name) {
  struct stat buffer;
  return (stat (name.c_str(), &buffer) == 0);
}

template <typename T>
xt::xarray<T> getParameter(const std::string& path){
    if(!exists(path))
        throw std::runtime_error("The parameter on path : " + path + " does not exist.");
    return xt::cast<T>(xt::load_npy<double>(path));
}

extern "C" {
auto&& Block__0Dense__weight = getParameter<double>("weight");
auto&& Block__0Dense__bias = getParameter<double>("bias");
}

My Makefile:

make:
	g++-8 -fopenmp -fPIC -std=c++14 -I$CONDA_PREFIX/include -shared -Wl,-undefined,dynamic_lookup -xc++ -I/usr/local/include -o binary main.cpp

Error:

In file included from /usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0/functional:54,
                 from /Users/ray_zhang/anaconda3/envs/idp3/include/xtensor/xbuffer_adaptor.hpp:13,
                 from /Users/ray_zhang/anaconda3/envs/idp3/include/xtensor/xarray.hpp:18,
                 from main.cpp:4:
/usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0/tuple: In instantiation of 'constexpr std::_Head_base<_Idx, _Head, false>::_Head_base(_UHead&&) [with _UHead = const xt::xarray_adaptor<xt::xbuffer_adaptor<double*, xt::acquire_ownership, std::allocator<double> >, (xt::layout_type)0, std::vector<long unsigned int>, xt::xtensor_expression_tag>; long unsigned int _Idx = 0; _Head = const xt::xarray_adaptor<xt::xbuffer_adaptor<double*, xt::acquire_ownership, std::allocator<double> >, (xt::layout_type)0, std::vector<long unsigned int>, xt::xtensor_expression_tag>]':
/usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0/tuple:373:49:   required from 'constexpr std::_Tuple_impl<_Idx, _Head>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head>&&) [with long unsigned int _Idx = 0; _Head = const xt::xarray_adaptor<xt::xbuffer_adaptor<double*, xt::acquire_ownership, std::allocator<double> >, (xt::layout_type)0, std::vector<long unsigned int>, xt::xtensor_expression_tag>]'
/usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0/tuple:662:17:   required from 'auto xt::detail::make_xfunction(E&& ...) [with F = xt::detail::cast<float>::functor; E = {xt::xarray_adaptor<xt::xbuffer_adaptor<double*, xt::acquire_ownership, std::allocator<double> >, (xt::layout_type)0, std::vector<long unsigned int, std::allocator<long unsigned int> >, xt::xtensor_expression_tag>}]'
/Users/ray_zhang/anaconda3/envs/idp3/include/xtensor/xoperation.hpp:836:73:   required from 'xt::detail::xfunction_type_t<xt::detail::cast<R>::template functor, E> xt::cast(E&&) [with R = float; E = xt::xarray_adaptor<xt::xbuffer_adaptor<double*, xt::acquire_ownership, std::allocator<double> >, (xt::layout_type)0, std::vector<long unsigned int>, xt::xtensor_expression_tag>; xt::detail::xfunction_type_t<xt::detail::cast<R>::template functor, E> = xt::xfunction<xt::detail::cast<float>::functor<double>, float, const xt::xarray_adaptor<xt::xbuffer_adaptor<double*, xt::acquire_ownership, std::allocator<double> >, (xt::layout_type)0, std::vector<long unsigned int, std::allocator<long unsigned int> >, xt::xtensor_expression_tag> >]'
main.cpp:26:23:   required from 'xt::xarray<T> getParameter(const string&) [with T = float; xt::xarray<T> = xt::xarray_container<xt::uvector<float, xsimd::aligned_allocator<float, 16> >, (xt::layout_type)1, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>; typename std::vector<T, xsimd::aligned_allocator<T, 16> >::size_type = long unsigned int; typename xt::uvector<T, xsimd::aligned_allocator<T, 16> >::size_type = long unsigned int; std::__cxx11::string = std::__cxx11::basic_string<char>]'
main.cpp:30:136:   required from here
/usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0/tuple:133:42: error: use of deleted function 'xt::xarray_adaptor<EC, L, SC, Tag>::xarray_adaptor(const xt::xarray_adaptor<EC, L, SC, Tag>&) [with EC = xt::xbuffer_adaptor<double*, xt::acquire_ownership, std::allocator<double> >; xt::layout_type L = (xt::layout_type)0; SC = std::vector<long unsigned int>; Tag = xt::xtensor_expression_tag]'
  : _M_head_impl(std::forward<_UHead>(__h)) { }
                                          ^
In file included from main.cpp:4:
/Users/ray_zhang/anaconda3/envs/idp3/include/xtensor/xarray.hpp:196:9: note: 'xt::xarray_adaptor<EC, L, SC, Tag>::xarray_adaptor(const xt::xarray_adaptor<EC, L, SC, Tag>&) [with EC = xt::xbuffer_adaptor<double*, xt::acquire_ownership, std::allocator<double> >; xt::layout_type L = (xt::layout_type)0; SC = std::vector<long unsigned int>; Tag = xt::xtensor_expression_tag]' is implicitly deleted because the default definition would be ill-formed:
         xarray_adaptor(const xarray_adaptor&) = default;
         ^~~~~~~~~~~~~~
/Users/ray_zhang/anaconda3/envs/idp3/include/xtensor/xarray.hpp:196:9: error: use of deleted function 'xt::xbuffer_adaptor<CP, O, A>::xbuffer_adaptor(const self_type&) [with CP = double*; O = xt::acquire_ownership; A = std::allocator<double>; xt::xbuffer_adaptor<CP, O, A>::self_type = xt::xbuffer_adaptor<double*, xt::acquire_ownership, std::allocator<double> >]'
In file included from /Users/ray_zhang/anaconda3/envs/idp3/include/xtensor/xarray.hpp:18,
                 from main.cpp:4:
/Users/ray_zhang/anaconda3/envs/idp3/include/xtensor/xbuffer_adaptor.hpp:179:9: note: 'xt::xbuffer_adaptor<CP, O, A>::xbuffer_adaptor(const self_type&) [with CP = double*; O = xt::acquire_ownership; A = std::allocator<double>; xt::xbuffer_adaptor<CP, O, A>::self_type = xt::xbuffer_adaptor<double*, xt::acquire_ownership, std::allocator<double> >]' is implicitly deleted because the default definition would be ill-formed:
         xbuffer_adaptor(const self_type&) = default;
         ^~~~~~~~~~~~~~~
/Users/ray_zhang/anaconda3/envs/idp3/include/xtensor/xbuffer_adaptor.hpp:179:9: error: use of deleted function 'xt::detail::xbuffer_owner_storage<CP, A>::xbuffer_owner_storage(const self_type&) [with CP = double*; A = std::allocator<double>; xt::detail::xbuffer_owner_storage<CP, A>::self_type = xt::detail::xbuffer_owner_storage<double*, std::allocator<double> >]'
/Users/ray_zhang/anaconda3/envs/idp3/include/xtensor/xbuffer_adaptor.hpp:109:13: note: declared here
             xbuffer_owner_storage(const self_type&) = delete;
             ^~~~~~~~~~~~~~~~~~~~~
make: *** [make] Error 1

GCC version 8.2.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions