.. _program_listing_file__tmp_ws_src_eigenpy_include_eigenpy_numpy-type.hpp: Program Listing for File numpy-type.hpp ======================================= |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/eigenpy/include/eigenpy/numpy-type.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* * Copyright 2018-2023 INRIA */ #ifndef __eigenpy_numpy_type_hpp__ #define __eigenpy_numpy_type_hpp__ #include #include #include #include "eigenpy/fwd.hpp" #include "eigenpy/register.hpp" #include "eigenpy/scalar-conversion.hpp" namespace eigenpy { template bool np_type_is_convertible_into_scalar(const int np_type) { const auto scalar_np_code = static_cast(NumpyEquivalentType::type_code); if (scalar_np_code >= NPY_USERDEF) return np_type == Register::getTypeCode(); if (scalar_np_code == np_type) return true; // Manage type promotion switch (np_type) { case NPY_BOOL: return FromTypeToType::value; case NPY_INT8: return FromTypeToType::value; case NPY_INT16: return FromTypeToType::value; case NPY_INT32: return FromTypeToType::value; case NPY_INT64: return FromTypeToType::value; case NPY_UINT8: return FromTypeToType::value; case NPY_UINT16: return FromTypeToType::value; case NPY_UINT32: return FromTypeToType::value; case NPY_UINT64: return FromTypeToType::value; #if defined _WIN32 || defined __CYGWIN__ // Manage NPY_INT on Windows (NPY_INT32 is NPY_LONG). // See https://github.com/stack-of-tasks/eigenpy/pull/455 case NPY_INT: return FromTypeToType::value; case NPY_UINT: return FromTypeToType::value; #endif // WIN32 #if defined __APPLE__ // Manage NPY_LONGLONG on Mac (NPY_INT64 is NPY_LONG).. // long long and long are both the same type // but NPY_LONGLONG and NPY_LONGĀ are different dtype. // See https://github.com/stack-of-tasks/eigenpy/pull/455 case NPY_LONGLONG: return FromTypeToType::value; case NPY_ULONGLONG: return FromTypeToType::value; #endif // MAC case NPY_FLOAT: return FromTypeToType::value; case NPY_CFLOAT: return FromTypeToType, Scalar>::value; case NPY_DOUBLE: return FromTypeToType::value; case NPY_CDOUBLE: return FromTypeToType, Scalar>::value; case NPY_LONGDOUBLE: return FromTypeToType::value; case NPY_CLONGDOUBLE: return FromTypeToType, Scalar>::value; default: return false; } } struct EIGENPY_DLLAPI NumpyType { static NumpyType& getInstance(); static bp::object make(PyArrayObject* pyArray, bool copy = false); static bp::object make(PyObject* pyObj, bool copy = false); static void sharedMemory(const bool value); static bool sharedMemory(); static const PyTypeObject* getNumpyArrayType(); protected: NumpyType(); bp::object pyModule; // Numpy types bp::object NumpyArrayObject; PyTypeObject* NumpyArrayType; bool shared_memory; }; } // namespace eigenpy #endif // ifndef __eigenpy_numpy_type_hpp__