Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
3dd325b7
Commit
3dd325b7
authored
Jun 18, 2016
by
Ivan Smirnov
Browse files
Change npy_format_descriptor typenum to static fn
parent
09f40e01
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
include/pybind11/numpy.h
include/pybind11/numpy.h
+9
-6
No files found.
include/pybind11/numpy.h
View file @
3dd325b7
...
@@ -84,7 +84,7 @@ public:
...
@@ -84,7 +84,7 @@ public:
template
<
typename
Type
>
array
(
size_t
size
,
const
Type
*
ptr
)
{
template
<
typename
Type
>
array
(
size_t
size
,
const
Type
*
ptr
)
{
API
&
api
=
lookup_api
();
API
&
api
=
lookup_api
();
PyObject
*
descr
=
api
.
PyArray_DescrFromType_
(
detail
::
npy_format_descriptor
<
Type
>::
value
);
PyObject
*
descr
=
api
.
PyArray_DescrFromType_
(
detail
::
npy_format_descriptor
<
Type
>::
typenum
()
);
if
(
descr
==
nullptr
)
if
(
descr
==
nullptr
)
pybind11_fail
(
"NumPy: unsupported buffer format!"
);
pybind11_fail
(
"NumPy: unsupported buffer format!"
);
Py_intptr_t
shape
=
(
Py_intptr_t
)
size
;
Py_intptr_t
shape
=
(
Py_intptr_t
)
size
;
...
@@ -135,7 +135,7 @@ public:
...
@@ -135,7 +135,7 @@ public:
if
(
ptr
==
nullptr
)
if
(
ptr
==
nullptr
)
return
nullptr
;
return
nullptr
;
API
&
api
=
lookup_api
();
API
&
api
=
lookup_api
();
PyObject
*
descr
=
api
.
PyArray_DescrFromType_
(
detail
::
npy_format_descriptor
<
T
>::
value
);
PyObject
*
descr
=
api
.
PyArray_DescrFromType_
(
detail
::
npy_format_descriptor
<
T
>::
typenum
()
);
PyObject
*
result
=
api
.
PyArray_FromAny_
(
ptr
,
descr
,
0
,
0
,
API
::
NPY_ENSURE_ARRAY_
|
ExtraFlags
,
nullptr
);
PyObject
*
result
=
api
.
PyArray_FromAny_
(
ptr
,
descr
,
0
,
0
,
API
::
NPY_ENSURE_ARRAY_
|
ExtraFlags
,
nullptr
);
if
(
!
result
)
if
(
!
result
)
PyErr_Clear
();
PyErr_Clear
();
...
@@ -152,7 +152,7 @@ private:
...
@@ -152,7 +152,7 @@ private:
array
::
API
::
NPY_BYTE_
,
array
::
API
::
NPY_UBYTE_
,
array
::
API
::
NPY_SHORT_
,
array
::
API
::
NPY_USHORT_
,
array
::
API
::
NPY_BYTE_
,
array
::
API
::
NPY_UBYTE_
,
array
::
API
::
NPY_SHORT_
,
array
::
API
::
NPY_USHORT_
,
array
::
API
::
NPY_INT_
,
array
::
API
::
NPY_UINT_
,
array
::
API
::
NPY_LONGLONG_
,
array
::
API
::
NPY_ULONGLONG_
};
array
::
API
::
NPY_INT_
,
array
::
API
::
NPY_UINT_
,
array
::
API
::
NPY_LONGLONG_
,
array
::
API
::
NPY_ULONGLONG_
};
public:
public:
enum
{
value
=
values
[
detail
::
log2
(
sizeof
(
T
))
*
2
+
(
std
::
is_unsigned
<
T
>::
value
?
1
:
0
)]
}
;
static
int
typ
enum
()
{
return
values
[
detail
::
log2
(
sizeof
(
T
))
*
2
+
(
std
::
is_unsigned
<
T
>::
value
?
1
:
0
)]
;
}
template
<
typename
T2
=
T
,
typename
std
::
enable_if
<
std
::
is_signed
<
T2
>
::
value
,
int
>::
type
=
0
>
template
<
typename
T2
=
T
,
typename
std
::
enable_if
<
std
::
is_signed
<
T2
>
::
value
,
int
>::
type
=
0
>
static
PYBIND11_DESCR
name
()
{
return
_
(
"int"
)
+
_
<
sizeof
(
T
)
*
8
>
();
}
static
PYBIND11_DESCR
name
()
{
return
_
(
"int"
)
+
_
<
sizeof
(
T
)
*
8
>
();
}
template
<
typename
T2
=
T
,
typename
std
::
enable_if
<!
std
::
is_signed
<
T2
>
::
value
,
int
>::
type
=
0
>
template
<
typename
T2
=
T
,
typename
std
::
enable_if
<!
std
::
is_signed
<
T2
>
::
value
,
int
>::
type
=
0
>
...
@@ -162,10 +162,13 @@ template <typename T> constexpr const int npy_format_descriptor<
...
@@ -162,10 +162,13 @@ template <typename T> constexpr const int npy_format_descriptor<
T
,
typename
std
::
enable_if
<
std
::
is_integral
<
T
>::
value
>::
type
>::
values
[
8
];
T
,
typename
std
::
enable_if
<
std
::
is_integral
<
T
>::
value
>::
type
>::
values
[
8
];
#define DECL_FMT(Type, NumPyName, Name) template<> struct npy_format_descriptor<Type> { \
#define DECL_FMT(Type, NumPyName, Name) template<> struct npy_format_descriptor<Type> { \
enum {
value =
array::API::NumPyName }
;
\
static int typ
enum
()
{
return
array::API::NumPyName
;
}
\
static PYBIND11_DESCR name() { return _(Name); } }
static PYBIND11_DESCR name() { return _(Name); } }
DECL_FMT
(
float
,
NPY_FLOAT_
,
"float32"
);
DECL_FMT
(
double
,
NPY_DOUBLE_
,
"float64"
);
DECL_FMT
(
bool
,
NPY_BOOL_
,
"bool"
);
DECL_FMT
(
float
,
NPY_FLOAT_
,
"float32"
);
DECL_FMT
(
std
::
complex
<
float
>
,
NPY_CFLOAT_
,
"complex64"
);
DECL_FMT
(
std
::
complex
<
double
>
,
NPY_CDOUBLE_
,
"complex128"
);
DECL_FMT
(
double
,
NPY_DOUBLE_
,
"float64"
);
DECL_FMT
(
bool
,
NPY_BOOL_
,
"bool"
);
DECL_FMT
(
std
::
complex
<
float
>
,
NPY_CFLOAT_
,
"complex64"
);
DECL_FMT
(
std
::
complex
<
double
>
,
NPY_CDOUBLE_
,
"complex128"
);
#undef DECL_FMT
#undef DECL_FMT
template
<
class
T
>
template
<
class
T
>
...
...
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