eigenpy
3.13.0
Bindings between Numpy and Eigen using Boost.Python
Toggle main menu visibility
Loading...
Searching...
No Matches
scipy-type.hpp
1
/*
2
* Copyright 2024 INRIA
3
*/
4
5
#ifndef __eigenpy_scipy_type_hpp__
6
#define __eigenpy_scipy_type_hpp__
7
8
#include "eigenpy/fwd.hpp"
9
#include "eigenpy/register.hpp"
10
#include "eigenpy/scalar-conversion.hpp"
11
#include "eigenpy/numpy-type.hpp"
12
13
namespace
eigenpy
{
14
15
struct
EIGENPY_DLLAPI ScipyType {
16
static
ScipyType& getInstance();
17
18
static
void
sharedMemory(
const
bool
value);
19
20
static
bool
sharedMemory();
21
22
static
bp::object getScipyType();
23
24
static
const
PyTypeObject* getScipyCSRMatrixType();
25
static
const
PyTypeObject* getScipyCSCMatrixType();
26
27
template
<
typename
SparseMatrix>
28
static
bp::object get_pytype_object(
29
const
Eigen::SparseMatrixBase<SparseMatrix>* ptr =
nullptr
) {
30
EIGENPY_UNUSED_VARIABLE(ptr);
31
return
SparseMatrix::IsRowMajor ? getInstance().csr_matrix_obj
32
: getInstance().csc_matrix_obj;
33
}
34
35
template
<
typename
SparseMatrix>
36
static
PyTypeObject
const
* get_pytype(
37
const
Eigen::SparseMatrixBase<SparseMatrix>* ptr =
nullptr
) {
38
EIGENPY_UNUSED_VARIABLE(ptr);
39
return
SparseMatrix::IsRowMajor ? getInstance().csr_matrix_type
40
: getInstance().csc_matrix_type;
41
}
42
43
static
int
get_numpy_type_num(
const
bp::object& obj) {
44
const
PyTypeObject*
type
= Py_TYPE(obj.ptr());
45
EIGENPY_USED_VARIABLE_ONLY_IN_DEBUG_MODE(
type
);
46
assert(
type
== getInstance().csr_matrix_type ||
47
type
== getInstance().csc_matrix_type);
48
49
bp::object dtype = obj.attr(
"dtype"
);
50
51
const
PyArray_Descr* npy_type =
52
reinterpret_cast<
PyArray_Descr*
>
(dtype.ptr());
53
return
npy_type->type_num;
54
}
55
56
protected
:
57
ScipyType();
58
59
bp::object sparse_module;
60
61
// SciPy types
62
bp::object csr_matrix_obj, csc_matrix_obj;
63
PyTypeObject *csr_matrix_type, *csc_matrix_type;
64
65
bool
shared_memory;
66
};
67
}
// namespace eigenpy
68
69
#endif
// ifndef __eigenpy_scipy_type_hpp__
eigenpy
Definition
alignment.hpp:14
eigenpy::type
include
eigenpy
scipy-type.hpp
Generated by
1.17.0