[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/DerThorsten/xtensor-python/master/test_python/main.cpp [Back]  [Original]

/***************************************************************************
* 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/xmath.hpp"
#include "xtensor/xarray.hpp"
#include "xtensor/xfixed.hpp"
#define FORCE_IMPORT_ARRAY
#include "xtensor-python/pyarray.hpp"
#include "xtensor-python/pytensor.hpp"
#include "xtensor-python/pyvectorize.hpp"
#include "xtensor/xadapt.hpp"
#include "xtensor/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 

Web Proxy Viewer  |  New URL  |  Original Page