Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
graph-tool
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
40
Issues
40
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tiago Peixoto
graph-tool
Commits
9f30098b
Commit
9f30098b
authored
May 24, 2013
by
Tiago Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update numpy bindings to comply with upcoming API deprecation
parent
a5990d2a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
16 deletions
+19
-16
src/graph/numpy_bind.hh
src/graph/numpy_bind.hh
+19
-16
No files found.
src/graph/numpy_bind.hh
View file @
9f30098b
...
...
@@ -26,6 +26,7 @@
#ifndef NUMPY_EXPORT
#define NO_IMPORT_ARRAY
#endif
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include "arrayobject.h"
#include <boost/array.hpp>
...
...
@@ -74,8 +75,8 @@ python::object wrap_vector_owned(vector<ValueType>& vec)
ndarray
=
(
PyArrayObject
*
)
PyArray_SimpleNewFromData
(
1
,
size
,
val_type
,
new_data
);
}
ndarray
->
flags
=
NPY_ALIGNED
|
NPY_C_CONTIGUOUS
|
NPY_OWNDATA
|
NPY_WRITEABLE
;
PyArray_ENABLEFLAGS
(
ndarray
,
NPY_ARRAY_ALIGNED
|
NPY_ARRAY_C_CONTIGUOUS
|
NPY_ARRAY_OWNDATA
|
NPY_ARRAY_WRITEABLE
)
;
handle
<>
x
((
PyObject
*
)
ndarray
);
object
o
(
x
);
return
o
;
...
...
@@ -92,7 +93,8 @@ python::object wrap_vector_not_owned(vector<ValueType>& vec)
else
ndarray
=
(
PyArrayObject
*
)
PyArray_SimpleNewFromData
(
1
,
&
size
,
val_type
,
&
vec
[
0
]);
ndarray
->
flags
=
NPY_ALIGNED
|
NPY_C_CONTIGUOUS
|
NPY_WRITEABLE
;
PyArray_ENABLEFLAGS
(
ndarray
,
NPY_ARRAY_ALIGNED
|
NPY_ARRAY_C_CONTIGUOUS
|
NPY_ARRAY_WRITEABLE
);
handle
<>
x
((
PyObject
*
)
ndarray
);
object
o
(
x
);
return
o
;
...
...
@@ -111,8 +113,8 @@ python::object wrap_multi_array_owned(multi_array<ValueType,Dim>& array)
PyArrayObject
*
ndarray
=
(
PyArrayObject
*
)
PyArray_SimpleNewFromData
(
Dim
,
shape
,
val_type
,
new_data
);
ndarray
->
flags
=
NPY_ALIGNED
|
NPY_C_CONTIGUOUS
|
NPY_OWNDATA
|
NPY_WRITEABLE
;
PyArray_ENABLEFLAGS
(
ndarray
,
NPY_ARRAY_ALIGNED
|
NPY_ARRAY_C_CONTIGUOUS
|
NPY_ARRAY_OWNDATA
|
NPY_ARRAY_WRITEABLE
)
;
handle
<>
x
((
PyObject
*
)
ndarray
);
object
o
(
x
);
return
o
;
...
...
@@ -125,7 +127,8 @@ python::object wrap_multi_array_not_owned(multi_array<ValueType,Dim>& array)
PyArrayObject
*
ndarray
=
(
PyArrayObject
*
)
PyArray_SimpleNewFromData
(
Dim
,
array
.
shape
(),
val_type
,
array
.
origin
());
ndarray
->
flags
=
NPY_ALIGNED
|
NPY_C_CONTIGUOUS
|
NPY_WRITEABLE
;
PyArray_ENABLEFLAGS
(
ndarray
,
NPY_ARRAY_ALIGNED
|
NPY_ARRAY_C_CONTIGUOUS
|
NPY_ARRAY_WRITEABLE
);
handle
<>
x
((
PyObject
*
)
ndarray
);
object
o
(
x
);
return
o
;
...
...
@@ -148,29 +151,29 @@ multi_array_ref<ValueType,dim> get_array(python::object points)
{
PyArrayObject
*
pa
=
(
PyArrayObject
*
)
points
.
ptr
();
if
(
pa
->
nd
!=
dim
)
if
(
PyArray_NDIM
(
pa
)
!=
dim
)
throw
invalid_numpy_conversion
(
"invalid array dimension!"
);
if
(
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
!=
pa
->
descr
->
type_num
)
if
(
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
!=
PyArray_DESCR
(
pa
)
->
type_num
)
{
using
python
::
detail
::
gcc_demangle
;
handle
<>
x
((
PyObject
*
)
pa
->
descr
->
typeobj
);
handle
<>
x
((
PyObject
*
)
PyArray_DESCR
(
pa
)
->
typeobj
);
object
dtype
(
x
);
string
type_name
=
python
::
extract
<
string
>
(
python
::
str
(
dtype
));
string
error
=
"invalid array value type: "
+
type_name
;
error
+=
" (id: "
+
lexical_cast
<
string
>
(
pa
->
descr
->
type_num
)
+
")"
;
error
+=
" (id: "
+
lexical_cast
<
string
>
(
PyArray_DESCR
(
pa
)
->
type_num
)
+
")"
;
error
+=
", wanted: "
+
string
(
gcc_demangle
(
typeid
(
ValueType
).
name
()));
error
+=
" (id: "
+
lexical_cast
<
string
>
(
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
)
+
")"
;
throw
invalid_numpy_conversion
(
error
);
}
vector
<
size_t
>
shape
(
pa
->
nd
);
for
(
int
i
=
0
;
i
<
pa
->
nd
;
++
i
)
shape
[
i
]
=
pa
->
dimensions
[
i
];
if
((
pa
->
flags
^
NP
Y_C_CONTIGUOUS
)
!=
0
)
return
multi_array_ref
<
ValueType
,
dim
>
((
ValueType
*
)
pa
->
data
,
shape
);
vector
<
size_t
>
shape
(
PyArray_NDIM
(
pa
)
);
for
(
int
i
=
0
;
i
<
PyArray_NDIM
(
pa
)
;
++
i
)
shape
[
i
]
=
PyArray_DIMS
(
pa
)
[
i
];
if
((
PyArray_FLAGS
(
pa
)
^
NPY_ARRA
Y_C_CONTIGUOUS
)
!=
0
)
return
multi_array_ref
<
ValueType
,
dim
>
((
ValueType
*
)
PyArray_DATA
(
pa
)
,
shape
);
else
return
multi_array_ref
<
ValueType
,
dim
>
((
ValueType
*
)
pa
->
data
,
shape
,
return
multi_array_ref
<
ValueType
,
dim
>
((
ValueType
*
)
PyArray_DATA
(
pa
)
,
shape
,
fortran_storage_order
());
}
...
...
Write
Preview
Markdown
is supported
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