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
ebe35be5
Commit
ebe35be5
authored
Jan 23, 2020
by
Tiago Peixoto
Browse files
Improve numpy binding to boost::multi_array
parent
6a5b5703
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/graph/correlations/graph_avg_correlations.hh
View file @
ebe35be5
...
...
@@ -91,8 +91,8 @@ struct get_avg_correlation
python
::
list
ret_bins
;
ret_bins
.
append
(
wrap_vector_owned
(
bins
[
0
]));
_ret_bins
=
ret_bins
;
_avg
=
wrap_multi_array_owned
<
avg_type
,
1
>
(
sum
.
get_array
());
_dev
=
wrap_multi_array_owned
<
avg_type
,
1
>
(
sum2
.
get_array
());
_avg
=
wrap_multi_array_owned
(
sum
.
get_array
());
_dev
=
wrap_multi_array_owned
(
sum2
.
get_array
());
}
python
::
object
&
_avg
;
python
::
object
&
_dev
;
...
...
src/graph/correlations/graph_corr_hist.hh
View file @
ebe35be5
...
...
@@ -73,7 +73,7 @@ struct get_correlation_histogram
ret_bins
.
append
(
wrap_vector_owned
(
bins
[
0
]));
ret_bins
.
append
(
wrap_vector_owned
(
bins
[
1
]));
_ret_bins
=
ret_bins
;
_hist
=
wrap_multi_array_owned
<
count_type
,
2
>
(
hist
.
get_array
());
_hist
=
wrap_multi_array_owned
(
hist
.
get_array
());
}
python
::
object
&
_hist
;
const
std
::
array
<
vector
<
long
double
>
,
2
>&
_bins
;
...
...
src/graph/numpy_bind.hh
View file @
ebe35be5
...
...
@@ -138,17 +138,19 @@ boost::python::object wrap_vector_not_owned(const std::vector<std::array<ValueTy
return
o
;
}
template
<
class
ValueType
,
size_t
Dim
>
template
<
class
Array
>
boost
::
python
::
object
wrap_multi_array_owned
(
const
boost
::
multi_array
<
ValueType
,
Dim
>
&
array
)
wrap_multi_array_owned
(
const
Array
&
array
)
{
size_t
val_type
=
boost
::
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
;
npy_intp
shape
[
Dim
];
for
(
size_t
i
=
0
;
i
<
Dim
;
++
i
)
typedef
typename
Array
::
element
value_t
;
constexpr
int
dim
=
Array
::
dimensionality
;
size_t
val_type
=
boost
::
mpl
::
at
<
numpy_types
,
value_t
>::
type
::
value
;
npy_intp
shape
[
dim
];
for
(
size_t
i
=
0
;
i
<
dim
;
++
i
)
shape
[
i
]
=
array
.
shape
()[
i
];
PyArrayObject
*
ndarray
=
(
PyArrayObject
*
)
PyArray_SimpleNew
(
D
im
,
shape
,
val_type
);
memcpy
(
PyArray_DATA
(
ndarray
),
array
.
data
(),
array
.
num_elements
()
*
sizeof
(
V
alue
Type
));
(
PyArrayObject
*
)
PyArray_SimpleNew
(
d
im
,
shape
,
val_type
);
memcpy
(
PyArray_DATA
(
ndarray
),
array
.
data
(),
array
.
num_elements
()
*
sizeof
(
v
alue
_t
));
PyArray_ENABLEFLAGS
(
ndarray
,
NPY_ARRAY_ALIGNED
|
NPY_ARRAY_C_CONTIGUOUS
|
NPY_ARRAY_OWNDATA
|
NPY_ARRAY_WRITEABLE
);
boost
::
python
::
handle
<>
x
((
PyObject
*
)
ndarray
);
...
...
@@ -156,14 +158,19 @@ wrap_multi_array_owned(const boost::multi_array<ValueType,Dim>& array)
return
o
;
}
template
<
class
ValueType
,
size_t
Dim
>
template
<
class
Array
>
boost
::
python
::
object
wrap_multi_array_not_owned
(
boost
::
multi_array
<
ValueType
,
Dim
>
&
array
)
wrap_multi_array_not_owned
(
Array
&
array
)
{
size_t
val_type
=
boost
::
mpl
::
at
<
numpy_types
,
ValueType
>::
type
::
value
;
typedef
typename
Array
::
element
value_t
;
constexpr
int
dim
=
Array
::
dimensionality
;
size_t
val_type
=
boost
::
mpl
::
at
<
numpy_types
,
value_t
>::
type
::
value
;
npy_intp
shape
[
dim
];
for
(
size_t
i
=
0
;
i
<
dim
;
++
i
)
shape
[
i
]
=
array
.
shape
()[
i
];
PyArrayObject
*
ndarray
=
(
PyArrayObject
*
)
PyArray_SimpleNewFromData
(
D
im
,
array
.
shape
()
,
val_type
,
array
.
origin
());
(
PyArrayObject
*
)
PyArray_SimpleNewFromData
(
d
im
,
shape
,
val_type
,
array
.
data
());
PyArray_ENABLEFLAGS
(
ndarray
,
NPY_ARRAY_ALIGNED
|
NPY_ARRAY_C_CONTIGUOUS
|
NPY_ARRAY_WRITEABLE
);
boost
::
python
::
handle
<>
x
((
PyObject
*
)
ndarray
);
...
...
src/graph/stats/graph_distance.hh
View file @
ebe35be5
...
...
@@ -106,7 +106,7 @@ struct get_distance_histogram
s_hist
.
gather
();
python
::
list
ret
;
ret
.
append
(
wrap_multi_array_owned
<
size_t
,
1
>
(
hist
.
get_array
()));
ret
.
append
(
wrap_multi_array_owned
(
hist
.
get_array
()));
ret
.
append
(
wrap_vector_owned
<
val_type
>
(
hist
.
get_bins
()[
0
]));
phist
=
ret
;
}
...
...
src/graph/stats/graph_distance_sampled.hh
View file @
ebe35be5
...
...
@@ -123,7 +123,7 @@ struct get_sampled_distance_histogram
s_hist
.
gather
();
python
::
list
ret
;
ret
.
append
(
wrap_multi_array_owned
<
size_t
,
1
>
(
hist
.
get_array
()));
ret
.
append
(
wrap_multi_array_owned
(
hist
.
get_array
()));
ret
.
append
(
wrap_vector_owned
<
val_type
>
(
hist
.
get_bins
()[
0
]));
phist
=
ret
;
}
...
...
src/graph/stats/graph_histograms.hh
View file @
ebe35be5
...
...
@@ -132,7 +132,7 @@ struct get_histogram
bin_list
=
hist
.
get_bins
();
python
::
object
ret_bins
=
wrap_vector_owned
(
bin_list
[
0
]);
_ret_bins
=
ret_bins
;
_hist
=
wrap_multi_array_owned
<
size_t
,
1
>
(
hist
.
get_array
());
_hist
=
wrap_multi_array_owned
(
hist
.
get_array
());
}
python
::
object
&
_hist
;
const
vector
<
long
double
>&
_bins
;
...
...
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