This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <numeric> | |
#include "xtensor/xmath.hpp" | |
#include "xtensor/xarray.hpp" | |
#define FORCE_IMPORT_ARRAY | |
#include "xtensor-python/pyarray.hpp" | |
#include "xtensor-python/pyvectorize.hpp" | |
namespace py = pybind11; | |
using complex_t = std::complex<double>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void dump_numpy_constant() | |
{ | |
std::cout << "NPY_BOOL = " << NPY_BOOL << std::endl; | |
std::cout << "NPY_BYTE = " << NPY_BYTE << std::endl; | |
std::cout << "NPY_UBYTE = " << NPY_UBYTE << std::endl; | |
std::cout << "NPY_INT8 = " << NPY_INT8 << std::endl; | |
std::cout << "NPY_UINT8 = " << NPY_UINT8 << std::endl; | |
std::cout << "NPY_SHORT = " << NPY_SHORT << std::endl; | |
std::cout << "NPY_USHORT = " << NPY_USHORT << std::endl; | |
std::cout << "NPY_INT16 = " << NPY_INT16 << std::endl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T, class A = std::allocator<T>> | |
class xarray | |
{ | |
public: | |
using allocator_type = A; | |
using value_type = typename allocator_type::value_type; | |
using reference = typename allocator_type::reference; | |
using const_reference = typename allocator_type::const_reference; | |
using pointer = typename allocator_type::pointer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T, class A> | |
inline auto xarray<T, A>::size() const -> size_type | |
{ | |
return std::accumulate(m_shape.cbegin(), m_shape.cend(), size_type(1), std::multiplies<size_type>()); | |
} | |
template <class T, class A> | |
inline auto xarray<T, A>::dimension() const -> size_type | |
{ | |
return m_shape.size(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T, class A = std::allocator<T>> | |
class xarray | |
{ | |
public: | |
// ... as before | |
private: | |
shape_type m_shape; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T, class A = std::allocator<T>> | |
class xarray | |
{ | |
public: | |
// ... as before | |
using strides_type = shape_type; | |
using storage_type = std::vector<T, A>; | |
void resize(const shape_type& shape, const strides_type& strides); | |
void reshape(const shape_type& shape, const strides_type& strides); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum class layout_type | |
{ | |
dynamic, | |
row_major, | |
column_major | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T, layout_type L = XTENSOR_DEFAULT_LAYOUT, | |
class A = std::allocator<T>> | |
class xarray | |
{ | |
public: | |
// ... as before | |
void resize(const shape_type& shape, const strides_type& strides); | |
void resize(const shape_type& shape, layout_type l = L); | |
void reshape(const shape_type& shape, const strides_type& strides); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class shape_type, class strides_type> | |
std::size_t compute_strides(const shape_type& shape, | |
const strides_type& strides, | |
layout_type l) | |
{ | |
std::size_t data_size = 1; | |
if(l == layout_type::row_major) | |
{ | |
for(std::size_t i = shape.size(); i != 0; --i) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class shape_type> | |
std::size_t compute_size(const shape_type& shape) | |
{ | |
using size_type = std::decay_t<typename shape_type::value_type>; | |
return std::accumulate(shape.cbegin(), | |
shape.cend(), | |
size_type(1), | |
std::multiplies<size_type>()); | |
} |
OlderNewer