Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
bd0f7fd5
Commit
bd0f7fd5
authored
Nov 17, 2013
by
Tiago Peixoto
Browse files
Fix compilation errors with older numpy versions
parent
9384b6e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/graph/numpy_bind_old.hh
View file @
bd0f7fd5
...
...
@@ -33,26 +33,24 @@
#include
<boost/mpl/for_each.hpp>
using
namespace
std
;
namespace
mpl
=
boost
::
mpl
;
namespace
python
=
boost
::
python
;
typedef
mpl
::
map
<
mpl
::
pair
<
bool
,
mpl
::
int_
<
NPY_BOOL
>
>
,
mpl
::
pair
<
uint8_t
,
mpl
::
int_
<
NPY_BYTE
>
>
,
mpl
::
pair
<
uint32_t
,
mpl
::
int_
<
NPY_UINT32
>
>
,
mpl
::
pair
<
int16_t
,
mpl
::
int_
<
NPY_INT16
>
>
,
mpl
::
pair
<
int32_t
,
mpl
::
int_
<
NPY_INT32
>
>
,
mpl
::
pair
<
int64_t
,
mpl
::
int_
<
NPY_INT64
>
>
,
mpl
::
pair
<
uint64_t
,
mpl
::
int_
<
NPY_UINT64
>
>
,
mpl
::
pair
<
unsigned
long
int
,
mpl
::
int_
<
NPY_ULONG
>
>
,
mpl
::
pair
<
double
,
mpl
::
int_
<
NPY_DOUBLE
>
>
,
mpl
::
pair
<
long
double
,
mpl
::
int_
<
NPY_LONGDOUBLE
>
>
typedef
boost
::
mpl
::
map
<
boost
::
mpl
::
pair
<
bool
,
boost
::
mpl
::
int_
<
NPY_BOOL
>
>
,
boost
::
mpl
::
pair
<
uint8_t
,
boost
::
mpl
::
int_
<
NPY_BYTE
>
>
,
boost
::
mpl
::
pair
<
uint32_t
,
boost
::
mpl
::
int_
<
NPY_UINT32
>
>
,
boost
::
mpl
::
pair
<
int16_t
,
boost
::
mpl
::
int_
<
NPY_INT16
>
>
,
boost
::
mpl
::
pair
<
int32_t
,
boost
::
mpl
::
int_
<
NPY_INT32
>
>
,
boost
::
mpl
::
pair
<
int64_t
,
boost
::
mpl
::
int_
<
NPY_INT64
>
>
,
boost
::
mpl
::
pair
<
uint64_t
,
boost
::
mpl
::
int_
<
NPY_UINT64
>
>
,
boost
::
mpl
::
pair
<
unsigned
long
int
,
boost
::
mpl
::
int_
<
NPY_ULONG
>
>
,
boost
::
mpl
::
pair
<
double
,
boost
::
mpl
::
int_
<
NPY_DOUBLE
>
>
,
boost
::
mpl
::
pair
<
long
double
,
boost
::
mpl
::
int_
<
NPY_LONGDOUBLE
>
>
>
numpy_types
;
template
<
class
ValueType
>
python
::
object
wrap_vector_owned
(
vector
<
ValueType
>&
vec
)
boost
::
python
::
object
wrap_vector_owned
(
vector
<
ValueType
>&
vec
)
{
int
val_type
=
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
;
int
val_type
=
boost
::
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
;
npy_intp
size
[
1
];
size
[
0
]
=
vec
.
size
();
PyArrayObject
*
ndarray
;
...
...
@@ -69,16 +67,16 @@ python::object wrap_vector_owned(vector<ValueType>& vec)
}
ndarray
->
flags
=
NPY_ALIGNED
|
NPY_C_CONTIGUOUS
|
NPY_OWNDATA
|
NPY_WRITEABLE
;
python
::
handle
<>
x
((
PyObject
*
)
ndarray
);
python
::
object
o
(
x
);
boost
::
python
::
handle
<>
x
((
PyObject
*
)
ndarray
);
boost
::
python
::
object
o
(
x
);
return
o
;
}
template
<
class
ValueType
>
python
::
object
wrap_vector_not_owned
(
vector
<
ValueType
>&
vec
)
boost
::
python
::
object
wrap_vector_not_owned
(
vector
<
ValueType
>&
vec
)
{
PyArrayObject
*
ndarray
;
int
val_type
=
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
;
int
val_type
=
boost
::
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
;
npy_intp
size
=
vec
.
size
();
if
(
vec
.
empty
())
return
wrap_vector_owned
(
vec
);
// return an _owned_ array of size one.
...
...
@@ -86,18 +84,18 @@ python::object wrap_vector_not_owned(vector<ValueType>& vec)
ndarray
=
(
PyArrayObject
*
)
PyArray_SimpleNewFromData
(
1
,
&
size
,
val_type
,
&
vec
[
0
]);
ndarray
->
flags
=
NPY_ALIGNED
|
NPY_C_CONTIGUOUS
|
NPY_WRITEABLE
;
python
::
handle
<>
x
((
PyObject
*
)
ndarray
);
object
o
(
x
);
boost
::
python
::
handle
<>
x
((
PyObject
*
)
ndarray
);
boost
::
python
::
object
o
(
x
);
return
o
;
}
template
<
class
ValueType
,
int
Dim
>
python
::
object
wrap_multi_array_owned
(
boost
::
multi_array
<
ValueType
,
Dim
>&
array
)
boost
::
python
::
object
wrap_multi_array_owned
(
boost
::
multi_array
<
ValueType
,
Dim
>&
array
)
{
ValueType
*
new_data
=
new
ValueType
[
array
.
num_elements
()];
memcpy
(
new_data
,
array
.
data
(),
array
.
num_elements
()
*
sizeof
(
ValueType
));
int
val_type
=
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
;
int
val_type
=
boost
::
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
;
npy_intp
shape
[
Dim
];
for
(
int
i
=
0
;
i
<
Dim
;
++
i
)
shape
[
i
]
=
array
.
shape
()[
i
];
...
...
@@ -106,21 +104,21 @@ python::object wrap_multi_array_owned(boost::multi_array<ValueType,Dim>& array)
new_data
);
ndarray
->
flags
=
NPY_ALIGNED
|
NPY_C_CONTIGUOUS
|
NPY_OWNDATA
|
NPY_WRITEABLE
;
python
::
handle
<>
x
((
PyObject
*
)
ndarray
);
python
::
object
o
(
x
);
boost
::
python
::
handle
<>
x
((
PyObject
*
)
ndarray
);
boost
::
python
::
object
o
(
x
);
return
o
;
}
template
<
class
ValueType
,
int
Dim
>
python
::
object
wrap_multi_array_not_owned
(
boost
::
multi_array
<
ValueType
,
Dim
>&
array
)
boost
::
python
::
object
wrap_multi_array_not_owned
(
boost
::
multi_array
<
ValueType
,
Dim
>&
array
)
{
int
val_type
=
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
;
int
val_type
=
boost
::
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
;
PyArrayObject
*
ndarray
=
(
PyArrayObject
*
)
PyArray_SimpleNewFromData
(
Dim
,
array
.
shape
(),
val_type
,
array
.
origin
());
ndarray
->
flags
=
NPY_ALIGNED
|
NPY_C_CONTIGUOUS
|
NPY_WRITEABLE
;
python
::
handle
<>
x
((
PyObject
*
)
ndarray
);
python
::
object
o
(
x
);
boost
::
python
::
handle
<>
x
((
PyObject
*
)
ndarray
);
boost
::
python
::
object
o
(
x
);
return
o
;
}
...
...
@@ -137,23 +135,23 @@ public:
};
template
<
class
ValueType
,
size_t
dim
>
boost
::
multi_array_ref
<
ValueType
,
dim
>
get_array
(
python
::
object
points
)
boost
::
multi_array_ref
<
ValueType
,
dim
>
get_array
(
boost
::
python
::
object
points
)
{
PyArrayObject
*
pa
=
(
PyArrayObject
*
)
points
.
ptr
();
if
(
pa
->
nd
!=
dim
)
throw
invalid_numpy_conversion
(
"invalid array dimension!"
);
if
(
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
!=
pa
->
descr
->
type_num
)
if
(
boost
::
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
!=
pa
->
descr
->
type_num
)
{
using
python
::
detail
::
gcc_demangle
;
python
::
handle
<>
x
((
PyObject
*
)
pa
->
descr
->
typeobj
);
python
::
object
dtype
(
x
);
string
type_name
=
python
::
extract
<
string
>
(
python
::
str
(
dtype
));
using
boost
::
python
::
detail
::
gcc_demangle
;
boost
::
python
::
handle
<>
x
((
PyObject
*
)
pa
->
descr
->
typeobj
);
boost
::
python
::
object
dtype
(
x
);
string
type_name
=
boost
::
python
::
extract
<
string
>
(
boost
::
python
::
str
(
dtype
));
string
error
=
"invalid array value type: "
+
type_name
;
error
+=
" (id: "
+
boost
::
lexical_cast
<
string
>
(
pa
->
descr
->
type_num
)
+
")"
;
error
+=
", wanted: "
+
string
(
gcc_demangle
(
typeid
(
ValueType
).
name
()));
error
+=
" (id: "
+
boost
::
lexical_cast
<
string
>
(
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
)
+
")"
;
error
+=
" (id: "
+
boost
::
lexical_cast
<
string
>
(
boost
::
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
)
+
")"
;
throw
invalid_numpy_conversion
(
error
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment