FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GitHub Viewer

/*************************************************************************** * Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * * 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. * ****************************************************************************/ #include #include "xtensor/core/xmath.hpp" #include "xtensor/containers/xarray.hpp" #include "xtensor/containers/xfixed.hpp" #define FORCE_IMPORT_ARRAY #include "xtensor-python/pyarray.hpp" #include "xtensor-python/pytensor.hpp" #include "xtensor-python/pyvectorize.hpp" #include "xtensor/containers/xadapt.hpp" #include "xtensor/views/xstrided_view.hpp" namespace py = pybind11; using complex_t = std::complex; // Examples double example1(xt::pyarray& m) { return m(0); } xt::pyarray example2(xt::pyarray& m) { return m + 2; } xt::xarray example3_xarray(const xt::xarray& m) { return xt::transpose(m) + 2; } xt::xarray example3_xarray_colmajor( const xt::xarray& m) { return xt::transpose(m) + 2; } xt::xtensor example3_xtensor3(const xt::xtensor& m) { return xt::transpose(m) + 2; } xt::xtensor example3_xtensor2(const xt::xtensor& m) { return xt::transpose(m) + 2; } xt::xtensor example3_xtensor2_colmajor( const xt::xtensor& m) { return xt::transpose(m) + 2; } xt::xtensor_fixed example3_xfixed3(const xt::xtensor_fixed& m) { return xt::transpose(m) + 2; } xt::xtensor_fixed example3_xfixed2(const xt::xtensor_fixed& m) { return xt::transpose(m) + 2; } xt::xtensor_fixed example3_xfixed2_colmajor( const xt::xtensor_fixed& m) { return xt::transpose(m) + 2; } // Readme Examples double readme_example1(xt::pyarray& m) { auto sines = xt::sin(m); return std::accumulate(sines.cbegin(), sines.cend(), 0.0); } double readme_example2(double i, double j) { return std::sin(i) - std::cos(j); } auto complex_overload(const xt::pyarray& a) { return a; } auto no_complex_overload(const xt::pyarray& a) { return a; } auto complex_overload_reg(const std::complex& a) { return a; } auto no_complex_overload_reg(const double& a) { return a; } // // Operator examples // xt::pyarray array_addition(const xt::pyarray& m, const xt::pyarray& n) { return m + n; } xt::pyarray array_subtraction(xt::pyarray& m, xt::pyarray& n) { return m - n; } xt::pyarray array_multiplication(xt::pyarray& m, xt::pyarray& n) { return m * n; } xt::pyarray array_division(xt::pyarray& m, xt::pyarray& n) { return m / n; } // Vectorize Examples int add(int i, int j) { return i + j; } template std::string typestring() { return "Unknown"; } template std::string typestring() { return "uint8"; } template std::string typestring() { return "int8"; } template std::string typestring() { return "uint16"; } template std::string typestring() { return "int16"; } template std::string typestring() { return "uint32"; } template std::string typestring() { return "int32"; } template std::string typestring() { return "uint64"; } template std::string typestring() { return "int64"; } template inline std::string int_overload(xt::pyarray& m) { return typestring(); } void dump_numpy_constant() { std::cout

Back | FazBrowse Home | New Git URL