/usr/include/xtensor/xadapt.hpp is in xtensor-dev 0.10.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | /***************************************************************************
* 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 XADAPT_HPP
#define XADAPT_HPP
#include <array>
#include <cstddef>
#include <memory>
#include <type_traits>
#include "xarray.hpp"
#include "xtensor.hpp"
namespace xt
{
/**************************
* 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 <class C, class SC, layout_type L = DEFAULT_LAYOUT>
std::enable_if_t<!detail::is_array<SC>::value, xarray_adaptor<C, L, SC>>
xadapt(C& container, const SC& shape, layout_type l = 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 <class C, class SC>
std::enable_if_t<!detail::is_array<SC>::value, xarray_adaptor<C, layout_type::dynamic, SC>>
xadapt(C& container, const SC& shape, const SC& 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_ownerhsip()`` or ``accept_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 <class P, class O, class SC, layout_type L = DEFAULT_LAYOUT, class A = std::allocator<std::remove_pointer_t<P>>>
std::enable_if_t<!detail::is_array<SC>::value, xarray_adaptor<xbuffer_adaptor<std::remove_pointer_t<P>, O, A>, L, SC>>
xadapt(P& pointer, typename A::size_type size, O ownership, const SC& shape, layout_type l = L, const A& alloc = A());
/**
* 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_ownerhsip()`` or ``accept_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 <class P, class O, class SC, class A = std::allocator<std::remove_pointer_t<P>>>
std::enable_if_t<!detail::is_array<SC>::value, xarray_adaptor<xbuffer_adaptor<std::remove_pointer_t<P>, O, A>, layout_type::dynamic, SC>>
xadapt(P& pointer, typename A::size_type size, O ownership, const SC& shape, const SC& strides, const A& alloc = A());
/***************************
* xtensor_adaptor builder *
***************************/
/**
* 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 <class C, std::size_t N, layout_type L = DEFAULT_LAYOUT>
xtensor_adaptor<C, N, L>
xadapt(C& container, const std::array<typename C::size_type, N>& shape, layout_type l = 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 <class C, std::size_t N>
xtensor_adaptor<C, N, layout_type::dynamic>
xadapt(C& container, const std::array<typename C::size_type, N>& shape, const std::array<typename C::size_type, N>& strides);
/**
* 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_ownerhsip()`` or ``accept_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 <class P, std::size_t N, class O, layout_type L = DEFAULT_LAYOUT, class A = std::allocator<std::remove_pointer_t<P>>>
xtensor_adaptor<xbuffer_adaptor<std::remove_pointer_t<P>, O, A>, N, L>
xadapt(P& pointer, typename A::size_type size, O ownership,
const std::array<typename A::size_type, N>& shape, layout_type l = L, const A& alloc = A());
/**
* 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_ownerhsip()`` or ``accept_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 <class P, std::size_t N, class O, class A = std::allocator<std::remove_pointer_t<P>>>
xtensor_adaptor<xbuffer_adaptor<std::remove_pointer_t<P>, O, A>, N, layout_type::dynamic>
xadapt(P& pointer, typename A::size_type size, O ownership,
const std::array<typename A::size_type, N>& shape, const std::array<typename A::size_type, N>& strides, const A& alloc = A());
/*****************************************
* xarray_adaptor builder implementation *
*****************************************/
template <class C, class SC, layout_type L>
inline std::enable_if_t<!detail::is_array<SC>::value, xarray_adaptor<C, L, SC>>
xadapt(C& container, const SC& shape, layout_type l)
{
return xarray_adaptor<C, L, SC>(container, shape, l);
}
template <class C, class SC>
inline std::enable_if_t<!detail::is_array<SC>::value, xarray_adaptor<C, layout_type::dynamic, SC>>
xadapt(C& container, const SC& shape, const SC& strides)
{
return xarray_adaptor<C, layout_type::dynamic, SC>(container, shape, strides);
}
template <class P, class O, class SC, layout_type L, class A>
inline std::enable_if_t<!detail::is_array<SC>::value, xarray_adaptor<xbuffer_adaptor<std::remove_pointer_t<P>, O, A>, L, SC>>
xadapt(P& pointer, typename A::size_type size, O, const SC& shape, layout_type l, const A& alloc)
{
using buffer_type = xbuffer_adaptor<std::remove_pointer_t<P>, O, A>;
buffer_type buf(pointer, size, alloc);
return xarray_adaptor<buffer_type, L, SC>(std::move(buf), shape, l);
}
template <class P, class O, class SC, class A>
inline std::enable_if_t<!detail::is_array<SC>::value, xarray_adaptor<xbuffer_adaptor<std::remove_pointer_t<P>, O, A>, layout_type::dynamic, SC>>
xadapt(P& pointer, typename A::size_type size, O, const SC& shape, const SC& strides, const A& alloc)
{
using buffer_type = xbuffer_adaptor<std::remove_pointer_t<P>, O, A>;
buffer_type buf(pointer, size, alloc);
return xarray_adaptor<buffer_type, layout_type::dynamic, SC>(std::move(buf), shape, strides);
}
/******************************************
* xtensor_adaptor builder implementation *
******************************************/
template <class C, std::size_t N, layout_type L>
inline xtensor_adaptor<C, N, L>
xadapt(C& container, const std::array<typename C::size_type, N>& shape, layout_type l)
{
return xtensor_adaptor<C, N, L>(container, shape, l);
}
template <class C, std::size_t N>
inline xtensor_adaptor<C, N, layout_type::dynamic>
xadapt(C& container, const std::array<typename C::size_type, N>& shape, const std::array<typename C::size_type, N>& strides)
{
return xtensor_adaptor<C, N, layout_type::dynamic>(container, shape, strides);
}
template <class P, std::size_t N, class O, layout_type L, class A>
inline xtensor_adaptor<xbuffer_adaptor<std::remove_pointer_t<P>, O, A>, N, L>
xadapt(P& pointer, typename A::size_type size, O,
const std::array<typename A::size_type, N>& shape, layout_type l, const A& alloc)
{
using buffer_type = xbuffer_adaptor<std::remove_pointer_t<P>, O, A>;
buffer_type buf(pointer, size, alloc);
return xtensor_adaptor<buffer_type, N, L>(std::move(buf), shape, l);
}
template <class P, std::size_t N, class O, class A>
inline xtensor_adaptor<xbuffer_adaptor<std::remove_pointer_t<P>, O, A>, N, layout_type::dynamic>
xadapt(P& pointer, typename A::size_type size, O,
const std::array<typename A::size_type, N>& shape, const std::array<typename A::size_type, N>& strides, const A& alloc)
{
using buffer_type = xbuffer_adaptor<std::remove_pointer_t<P>, O, A>;
buffer_type buf(pointer, size, alloc);
return xtensor_adaptor<buffer_type, N, layout_type::dynamic>(std::move(buf), shape, strides);
}
}
#endif
|