Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
4be37c17
Commit
4be37c17
authored
Jul 06, 2016
by
Wenzel Jakob
Committed by
GitHub
Jul 06, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #269 from jagerman/ternary-description
Add _<bool>("s1", "s2") ternary & use TYPE_CASTER
parents
22201d08
4609beb4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
48 deletions
+18
-48
include/pybind11/cast.h
+1
-16
include/pybind11/descr.h
+13
-0
include/pybind11/eigen.h
+4
-32
No files found.
include/pybind11/cast.h
View file @
4be37c17
...
@@ -369,22 +369,7 @@ public:
...
@@ -369,22 +369,7 @@ public:
}
}
}
}
static
handle
cast
(
const
T
*
src
,
return_value_policy
policy
,
handle
parent
)
{
PYBIND11_TYPE_CASTER
(
T
,
_
<
std
::
is_integral
<
T
>::
value
>
(
"int"
,
"float"
));
return
cast
(
*
src
,
policy
,
parent
);
}
template
<
typename
T2
=
T
,
typename
std
::
enable_if
<
std
::
is_integral
<
T2
>::
value
,
int
>::
type
=
0
>
static
PYBIND11_DESCR
name
()
{
return
type_descr
(
_
(
"int"
));
}
template
<
typename
T2
=
T
,
typename
std
::
enable_if
<!
std
::
is_integral
<
T2
>::
value
,
int
>::
type
=
0
>
static
PYBIND11_DESCR
name
()
{
return
type_descr
(
_
(
"float"
));
}
operator
T
*
()
{
return
&
value
;
}
operator
T
&
()
{
return
value
;
}
template
<
typename
T2
>
using
cast_op_type
=
pybind11
::
detail
::
cast_op_type
<
T2
>
;
protected
:
T
value
;
};
};
template
<>
class
type_caster
<
void_type
>
{
template
<>
class
type_caster
<
void_type
>
{
...
...
include/pybind11/descr.h
View file @
4be37c17
...
@@ -83,6 +83,16 @@ template <size_t...Digits> struct int_to_str<0, Digits...> {
...
@@ -83,6 +83,16 @@ template <size_t...Digits> struct int_to_str<0, Digits...> {
static
constexpr
auto
digits
=
descr
<
sizeof
...(
Digits
),
0
>
({
(
'0'
+
Digits
)...,
'\0'
},
{
nullptr
});
static
constexpr
auto
digits
=
descr
<
sizeof
...(
Digits
),
0
>
({
(
'0'
+
Digits
)...,
'\0'
},
{
nullptr
});
};
};
// Ternary description (like std::conditional)
template
<
bool
B
,
size_t
Size1
,
size_t
Size2
>
constexpr
typename
std
::
enable_if
<
B
,
descr
<
Size1
-
1
,
0
>>::
type
_
(
char
const
(
&
text1
)[
Size1
],
char
const
(
&
)[
Size2
])
{
return
_
(
text1
);
}
template
<
bool
B
,
size_t
Size1
,
size_t
Size2
>
constexpr
typename
std
::
enable_if
<!
B
,
descr
<
Size2
-
1
,
0
>>::
type
_
(
char
const
(
&
)[
Size1
],
char
const
(
&
text2
)[
Size2
])
{
return
_
(
text2
);
}
template
<
size_t
Size
>
auto
constexpr
_
()
{
template
<
size_t
Size
>
auto
constexpr
_
()
{
return
int_to_str
<
Size
/
10
,
Size
%
10
>::
digits
;
return
int_to_str
<
Size
/
10
,
Size
%
10
>::
digits
;
}
}
...
@@ -153,6 +163,9 @@ PYBIND11_NOINLINE inline descr _(const char *text) {
...
@@ -153,6 +163,9 @@ PYBIND11_NOINLINE inline descr _(const char *text) {
return
descr
(
text
,
types
);
return
descr
(
text
,
types
);
}
}
template
<
bool
B
>
PYBIND11_NOINLINE
typename
std
::
enable_if
<
B
,
descr
>::
type
_
(
const
char
*
text1
,
const
char
*
)
{
return
_
(
text1
);
}
template
<
bool
B
>
PYBIND11_NOINLINE
typename
std
::
enable_if
<!
B
,
descr
>::
type
_
(
char
const
*
,
const
char
*
text2
)
{
return
_
(
text2
);
}
template
<
typename
Type
>
PYBIND11_NOINLINE
descr
_
()
{
template
<
typename
Type
>
PYBIND11_NOINLINE
descr
_
()
{
const
std
::
type_info
*
types
[
2
]
=
{
&
typeid
(
Type
),
nullptr
};
const
std
::
type_info
*
types
[
2
]
=
{
&
typeid
(
Type
),
nullptr
};
return
descr
(
"%"
,
types
);
return
descr
(
"%"
,
types
);
...
...
include/pybind11/eigen.h
View file @
4be37c17
...
@@ -99,10 +99,6 @@ struct type_caster<Type, typename std::enable_if<is_eigen_dense<Type>::value>::t
...
@@ -99,10 +99,6 @@ struct type_caster<Type, typename std::enable_if<is_eigen_dense<Type>::value>::t
return
true
;
return
true
;
}
}
static
handle
cast
(
const
Type
*
src
,
return_value_policy
policy
,
handle
parent
)
{
return
cast
(
*
src
,
policy
,
parent
);
}
static
handle
cast
(
const
Type
&
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
static
handle
cast
(
const
Type
&
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
if
(
isVector
)
{
if
(
isVector
)
{
return
array
(
buffer_info
(
return
array
(
buffer_info
(
...
@@ -139,15 +135,8 @@ struct type_caster<Type, typename std::enable_if<is_eigen_dense<Type>::value>::t
...
@@ -139,15 +135,8 @@ struct type_caster<Type, typename std::enable_if<is_eigen_dense<Type>::value>::t
}
}
}
}
template
<
typename
_T
>
using
cast_op_type
=
pybind11
::
detail
::
cast_op_type
<
_T
>
;
PYBIND11_TYPE_CASTER
(
Type
,
_
(
"numpy.ndarray[dtype="
)
+
npy_format_descriptor
<
Scalar
>::
name
()
+
_
(
", shape=("
)
+
rows
()
+
_
(
", "
)
+
cols
()
+
_
(
")]"
));
static
PYBIND11_DESCR
name
()
{
return
_
(
"numpy.ndarray[dtype="
)
+
npy_format_descriptor
<
Scalar
>::
name
()
+
_
(
", shape=("
)
+
rows
()
+
_
(
", "
)
+
cols
()
+
_
(
")]"
);
}
operator
Type
*
()
{
return
&
value
;
}
operator
Type
&
()
{
return
value
;
}
protected
:
protected
:
template
<
typename
T
=
Type
,
typename
std
::
enable_if
<
T
::
RowsAtCompileTime
==
Eigen
::
Dynamic
,
int
>::
type
=
0
>
template
<
typename
T
=
Type
,
typename
std
::
enable_if
<
T
::
RowsAtCompileTime
==
Eigen
::
Dynamic
,
int
>::
type
=
0
>
...
@@ -158,9 +147,6 @@ protected:
...
@@ -158,9 +147,6 @@ protected:
static
PYBIND11_DESCR
cols
()
{
return
_
(
"n"
);
}
static
PYBIND11_DESCR
cols
()
{
return
_
(
"n"
);
}
template
<
typename
T
=
Type
,
typename
std
::
enable_if
<
T
::
ColsAtCompileTime
!=
Eigen
::
Dynamic
,
int
>::
type
=
0
>
template
<
typename
T
=
Type
,
typename
std
::
enable_if
<
T
::
ColsAtCompileTime
!=
Eigen
::
Dynamic
,
int
>::
type
=
0
>
static
PYBIND11_DESCR
cols
()
{
return
_
<
T
::
ColsAtCompileTime
>
();
}
static
PYBIND11_DESCR
cols
()
{
return
_
<
T
::
ColsAtCompileTime
>
();
}
protected
:
Type
value
;
};
};
template
<
typename
Type
>
template
<
typename
Type
>
...
@@ -214,10 +200,6 @@ struct type_caster<Type, typename std::enable_if<is_eigen_sparse<Type>::value>::
...
@@ -214,10 +200,6 @@ struct type_caster<Type, typename std::enable_if<is_eigen_sparse<Type>::value>::
return
true
;
return
true
;
}
}
static
handle
cast
(
const
Type
*
src
,
return_value_policy
policy
,
handle
parent
)
{
return
cast
(
*
src
,
policy
,
parent
);
}
static
handle
cast
(
const
Type
&
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
static
handle
cast
(
const
Type
&
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
const_cast
<
Type
&>
(
src
).
makeCompressed
();
const_cast
<
Type
&>
(
src
).
makeCompressed
();
...
@@ -275,18 +257,8 @@ struct type_caster<Type, typename std::enable_if<is_eigen_sparse<Type>::value>::
...
@@ -275,18 +257,8 @@ struct type_caster<Type, typename std::enable_if<is_eigen_sparse<Type>::value>::
).
release
();
).
release
();
}
}
template
<
typename
_T
>
using
cast_op_type
=
pybind11
::
detail
::
cast_op_type
<
_T
>
;
PYBIND11_TYPE_CASTER
(
Type
,
_
<
(
Type
::
Flags
&
Eigen
::
RowMajorBit
)
!=
0
>
(
"scipy.sparse.csr_matrix[dtype="
,
"scipy.sparse.csc_matrix[dtype="
)
+
npy_format_descriptor
<
Scalar
>::
name
()
+
_
(
"]"
));
template
<
typename
T
=
Type
,
typename
std
::
enable_if
<
(
T
::
Flags
&
Eigen
::
RowMajorBit
)
!=
0
,
int
>::
type
=
0
>
static
PYBIND11_DESCR
name
()
{
return
_
(
"scipy.sparse.csr_matrix[dtype="
)
+
npy_format_descriptor
<
Scalar
>::
name
()
+
_
(
"]"
);
}
template
<
typename
T
=
Type
,
typename
std
::
enable_if
<
(
T
::
Flags
&
Eigen
::
RowMajorBit
)
==
0
,
int
>::
type
=
0
>
static
PYBIND11_DESCR
name
()
{
return
_
(
"scipy.sparse.csc_matrix[dtype="
)
+
npy_format_descriptor
<
Scalar
>::
name
()
+
_
(
"]"
);
}
operator
Type
*
()
{
return
&
value
;
}
operator
Type
&
()
{
return
value
;
}
protected
:
Type
value
;
};
};
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
detail
)
...
...
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