eigenpy.cpp 2.24 KB
Newer Older
jcarpent's avatar
jcarpent committed
1
/*
2
 * Copyright 2014-2019, CNRS
3
 * Copyright 2018-2021, INRIA
jcarpent's avatar
jcarpent committed
4
5
 */

6
#include "eigenpy/eigenpy.hpp"
7
#include <stdlib.h>
8
9
10
11

namespace eigenpy
{

12
13
14
15
16
  void seed(unsigned int seed_value)
  {
    srand(seed_value);
  }

17
  void exposeMatrixBool();
18
19
20
21
22
23
24
25
26
27
  void exposeMatrixInt();
  void exposeMatrixLong();
  void exposeMatrixFloat();
  void exposeMatrixDouble();
  void exposeMatrixLongDouble();

  void exposeMatrixComplexFloat();
  void exposeMatrixComplexDouble();
  void exposeMatrixComplexLongDouble();

28
  /* Enable Eigen-Numpy serialization for a set of standard MatrixBase instances. */
29
30
  void enableEigenPy()
  {
31
    using namespace Eigen;
32
    import_numpy();
33
    
34
    Exception::registerException();
35
    
36
    bp::def("setNumpyType",&NumpyType::setNumpyType,
37
            bp::arg("Numpy type (np.ndarray or np.matrix)"),
Justin Carpentier's avatar
Justin Carpentier committed
38
            "Change the Numpy type returned by the converters from an Eigen object.");
39
40
41
            
    bp::def("getNumpyType",&NumpyType::getNumpyType,
            "Get the Numpy type returned by the converters from an Eigen object.");
42
    
43
    bp::def("switchToNumpyArray",&NumpyType::switchToNumpyArray,
44
45
            "Set the conversion from Eigen::Matrix to numpy.ndarray.");
    
46
    bp::def("switchToNumpyMatrix",&NumpyType::switchToNumpyMatrix,
47
            "Set the conversion from Eigen::Matrix to numpy.matrix.");
48
    
49
50
51
    bp::def("sharedMemory",
            (void (*)(const bool))NumpyType::sharedMemory,
            bp::arg("value"),
Justin Carpentier's avatar
Justin Carpentier committed
52
            "Share the memory when converting from Eigen to Numpy.");
53
54
55
    
    bp::def("sharedMemory",
            (bool (*)())NumpyType::sharedMemory,
Justin Carpentier's avatar
Justin Carpentier committed
56
            "Status of the shared memory when converting from Eigen to Numpy.\n"
57
            "If True, the memory is shared when converting an Eigen::Matrix to a numpy.array.\n"
Justin Carpentier's avatar
Justin Carpentier committed
58
            "Otherwise, a deep copy of the Eigen::Matrix is performed.");
59
    
60
61
    bp::def("seed",&seed,bp::arg("seed_value"),
            "Initialize the pseudo-random number generator with the argument seed_value.");
62
    
63
    exposeMatrixBool();
64
65
66
67
68
    exposeMatrixInt();
    exposeMatrixLong();
    exposeMatrixFloat();
    exposeMatrixDouble();
    exposeMatrixLongDouble();
69
    
70
71
72
    exposeMatrixComplexFloat();
    exposeMatrixComplexDouble();
    exposeMatrixComplexLongDouble();
73
74
75
  }

} // namespace eigenpy