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

/***************************************************************************
* Copyright (c) 2016, Johan Mabille and Sylvain Corlay                     *
*                                                                          *
* 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"
#define FORCE_IMPORT_ARRAY
#include "xtensor-python/pyarray.hpp"
#include "xtensor-python/pyvectorize.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;
}

// 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;
}

// 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