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
d6e4cef6
Commit
d6e4cef6
authored
Feb 20, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor formatting changes, removed missing header files referenced in setup.py
parent
5e31d891
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
37 deletions
+31
-37
include/pybind11/numpy.h
+30
-34
setup.py
+1
-3
No files found.
include/pybind11/numpy.h
View file @
d6e4cef6
...
@@ -162,14 +162,13 @@ array_iterator<T> array_end(const buffer_info& buffer) {
...
@@ -162,14 +162,13 @@ array_iterator<T> array_end(const buffer_info& buffer) {
}
}
class
common_iterator
{
class
common_iterator
{
public
:
public
:
using
container_type
=
std
::
vector
<
size_t
>
;
using
container_type
=
std
::
vector
<
size_t
>
;
using
value_type
=
container_type
::
value_type
;
using
value_type
=
container_type
::
value_type
;
using
size_type
=
container_type
::
size_type
;
using
size_type
=
container_type
::
size_type
;
common_iterator
()
:
p_ptr
(
0
),
m_strides
()
{}
common_iterator
()
:
p_ptr
(
0
),
m_strides
()
{}
common_iterator
(
void
*
ptr
,
const
container_type
&
strides
,
const
std
::
vector
<
size_t
>&
shape
)
common_iterator
(
void
*
ptr
,
const
container_type
&
strides
,
const
std
::
vector
<
size_t
>&
shape
)
:
p_ptr
(
reinterpret_cast
<
char
*>
(
ptr
)),
m_strides
(
strides
.
size
())
{
:
p_ptr
(
reinterpret_cast
<
char
*>
(
ptr
)),
m_strides
(
strides
.
size
())
{
m_strides
.
back
()
=
static_cast
<
value_type
>
(
strides
.
back
());
m_strides
.
back
()
=
static_cast
<
value_type
>
(
strides
.
back
());
...
@@ -189,30 +188,26 @@ public:
...
@@ -189,30 +188,26 @@ public:
}
}
private
:
private
:
char
*
p_ptr
;
char
*
p_ptr
;
container_type
m_strides
;
container_type
m_strides
;
};
};
template
<
size_t
N
>
template
<
size_t
N
>
class
multi_array_iterator
{
class
multi_array_iterator
{
public
:
public
:
using
container_type
=
std
::
vector
<
size_t
>
;
using
container_type
=
std
::
vector
<
size_t
>
;
multi_array_iterator
(
const
std
::
array
<
buffer_info
,
N
>&
buffers
,
multi_array_iterator
(
const
std
::
array
<
buffer_info
,
N
>
&
buffers
,
const
std
::
vector
<
size_t
>&
shape
)
const
std
::
vector
<
size_t
>
&
shape
)
:
m_shape
(
shape
.
size
()),
m_index
(
shape
.
size
(),
0
),
m_common_iterator
()
{
:
m_shape
(
shape
.
size
()),
m_index
(
shape
.
size
(),
0
),
m_common_iterator
()
{
// Manual copy to avoid conversion warning if using std::copy
// Manual copy to avoid conversion warning if using std::copy
for
(
size_t
i
=
0
;
i
<
shape
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
shape
.
size
();
++
i
)
m_shape
[
i
]
=
static_cast
<
container_type
::
value_type
>
(
shape
[
i
]);
m_shape
[
i
]
=
static_cast
<
container_type
::
value_type
>
(
shape
[
i
]);
}
container_type
strides
(
shape
.
size
());
container_type
strides
(
shape
.
size
());
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
init_common_iterator
(
buffers
[
i
],
shape
,
m_common_iterator
[
i
],
strides
);
init_common_iterator
(
buffers
[
i
],
shape
,
m_common_iterator
[
i
],
strides
);
}
}
}
multi_array_iterator
&
operator
++
()
{
multi_array_iterator
&
operator
++
()
{
...
@@ -221,16 +216,14 @@ public:
...
@@ -221,16 +216,14 @@ public:
if
(
++
m_index
[
i
]
!=
m_shape
[
i
])
{
if
(
++
m_index
[
i
]
!=
m_shape
[
i
])
{
increment_common_iterator
(
i
);
increment_common_iterator
(
i
);
break
;
break
;
}
}
else
{
else
{
m_index
[
i
]
=
0
;
m_index
[
i
]
=
0
;
}
}
}
}
return
*
this
;
return
*
this
;
}
}
template
<
size_t
K
,
class
T
>
template
<
size_t
K
,
class
T
>
const
T
&
data
()
const
{
const
T
&
data
()
const
{
return
*
reinterpret_cast
<
T
*>
(
m_common_iterator
[
K
].
data
());
return
*
reinterpret_cast
<
T
*>
(
m_common_iterator
[
K
].
data
());
}
}
...
@@ -238,7 +231,9 @@ private:
...
@@ -238,7 +231,9 @@ private:
using
common_iter
=
common_iterator
;
using
common_iter
=
common_iterator
;
void
init_common_iterator
(
const
buffer_info
&
buffer
,
const
std
::
vector
<
size_t
>&
shape
,
common_iter
&
iterator
,
container_type
&
strides
)
{
void
init_common_iterator
(
const
buffer_info
&
buffer
,
const
std
::
vector
<
size_t
>
&
shape
,
common_iter
&
iterator
,
container_type
&
strides
)
{
auto
buffer_shape_iter
=
buffer
.
shape
.
rbegin
();
auto
buffer_shape_iter
=
buffer
.
shape
.
rbegin
();
auto
buffer_strides_iter
=
buffer
.
strides
.
rbegin
();
auto
buffer_strides_iter
=
buffer
.
strides
.
rbegin
();
auto
shape_iter
=
shape
.
rbegin
();
auto
shape_iter
=
shape
.
rbegin
();
...
@@ -261,9 +256,8 @@ private:
...
@@ -261,9 +256,8 @@ private:
}
}
void
increment_common_iterator
(
size_t
dim
)
{
void
increment_common_iterator
(
size_t
dim
)
{
std
::
for_each
(
m_common_iterator
.
begin
(),
m_common_iterator
.
end
(),
[
=
](
common_iter
&
iter
)
{
for
(
auto
&
iter
:
m_common_iterator
)
iter
.
increment
(
dim
);
iter
.
increment
(
dim
);
});
}
}
container_type
m_shape
;
container_type
m_shape
;
...
@@ -271,10 +265,6 @@ private:
...
@@ -271,10 +265,6 @@ private:
std
::
array
<
common_iter
,
N
>
m_common_iterator
;
std
::
array
<
common_iter
,
N
>
m_common_iterator
;
};
};
template
<
typename
T
>
struct
handle_type_name
<
array_t
<
T
>>
{
static
PYBIND11_DESCR
name
()
{
return
_
(
"array["
)
+
type_caster
<
T
>::
name
()
+
_
(
"]"
);
}
};
template
<
size_t
N
>
template
<
size_t
N
>
bool
broadcast
(
const
std
::
array
<
buffer_info
,
N
>&
buffers
,
int
&
ndim
,
std
::
vector
<
size_t
>&
shape
)
{
bool
broadcast
(
const
std
::
array
<
buffer_info
,
N
>&
buffers
,
int
&
ndim
,
std
::
vector
<
size_t
>&
shape
)
{
ndim
=
std
::
accumulate
(
buffers
.
begin
(),
buffers
.
end
(),
0
,
[](
int
res
,
const
buffer_info
&
buf
)
{
ndim
=
std
::
accumulate
(
buffers
.
begin
(),
buffers
.
end
(),
0
,
[](
int
res
,
const
buffer_info
&
buf
)
{
...
@@ -286,13 +276,14 @@ bool broadcast(const std::array<buffer_info, N>& buffers, int& ndim, std::vector
...
@@ -286,13 +276,14 @@ bool broadcast(const std::array<buffer_info, N>& buffers, int& ndim, std::vector
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
auto
res_iter
=
shape
.
rbegin
();
auto
res_iter
=
shape
.
rbegin
();
bool
i_trivial_broadcast
=
(
buffers
[
i
].
size
==
1
)
||
(
buffers
[
i
].
ndim
==
ndim
);
bool
i_trivial_broadcast
=
(
buffers
[
i
].
size
==
1
)
||
(
buffers
[
i
].
ndim
==
ndim
);
for
(
auto
shape_iter
=
buffers
[
i
].
shape
.
rbegin
();
shape_iter
!=
buffers
[
i
].
shape
.
rend
();
++
shape_iter
,
++
res_iter
)
{
for
(
auto
shape_iter
=
buffers
[
i
].
shape
.
rbegin
();
if
(
*
res_iter
==
1
)
{
shape_iter
!=
buffers
[
i
].
shape
.
rend
();
++
shape_iter
,
++
res_iter
)
{
if
(
*
res_iter
==
1
)
*
res_iter
=
*
shape_iter
;
*
res_iter
=
*
shape_iter
;
}
else
if
((
*
shape_iter
!=
1
)
&&
(
*
res_iter
!=
*
shape_iter
))
else
if
((
*
shape_iter
!=
1
)
&&
(
*
res_iter
!=
*
shape_iter
))
{
pybind11_fail
(
"pybind11::vectorize: incompatible size/dimension of inputs!"
);
pybind11_fail
(
"pybind11::vectorize: incompatible size/dimension of inputs!"
);
}
i_trivial_broadcast
=
i_trivial_broadcast
&&
(
*
res_iter
==
*
shape_iter
);
i_trivial_broadcast
=
i_trivial_broadcast
&&
(
*
res_iter
==
*
shape_iter
);
}
}
trivial_broadcast
=
trivial_broadcast
&&
i_trivial_broadcast
;
trivial_broadcast
=
trivial_broadcast
&&
i_trivial_broadcast
;
...
@@ -350,8 +341,7 @@ struct vectorize_helper {
...
@@ -350,8 +341,7 @@ struct vectorize_helper {
?
*
((
Args
*
)
buffers
[
Index
].
ptr
)
?
*
((
Args
*
)
buffers
[
Index
].
ptr
)
:
((
Args
*
)
buffers
[
Index
].
ptr
)[
i
])...);
:
((
Args
*
)
buffers
[
Index
].
ptr
)[
i
])...);
}
}
}
}
else
{
else
{
apply_broadcast
<
N
,
Index
...
>
(
buffers
,
buf
,
index
);
apply_broadcast
<
N
,
Index
...
>
(
buffers
,
buf
,
index
);
}
}
...
@@ -359,19 +349,25 @@ struct vectorize_helper {
...
@@ -359,19 +349,25 @@ struct vectorize_helper {
}
}
template
<
size_t
N
,
size_t
...
Index
>
template
<
size_t
N
,
size_t
...
Index
>
void
apply_broadcast
(
const
std
::
array
<
buffer_info
,
N
>&
buffers
,
buffer_info
&
output
,
index_sequence
<
Index
...
>
)
{
void
apply_broadcast
(
const
std
::
array
<
buffer_info
,
N
>
&
buffers
,
buffer_info
&
output
,
index_sequence
<
Index
...
>
)
{
using
input_iterator
=
multi_array_iterator
<
N
>
;
using
input_iterator
=
multi_array_iterator
<
N
>
;
using
output_iterator
=
array_iterator
<
Return
>
;
using
output_iterator
=
array_iterator
<
Return
>
;
input_iterator
input_iter
(
buffers
,
output
.
shape
);
input_iterator
input_iter
(
buffers
,
output
.
shape
);
output_iterator
output_end
=
array_end
<
Return
>
(
output
);
output_iterator
output_end
=
array_end
<
Return
>
(
output
);
for
(
output_iterator
iter
=
array_begin
<
Return
>
(
output
);
iter
!=
output_end
;
++
iter
,
++
input_iter
)
{
for
(
output_iterator
iter
=
array_begin
<
Return
>
(
output
);
iter
!=
output_end
;
++
iter
,
++
input_iter
)
{
*
iter
=
f
((
input_iter
.
template
data
<
Index
,
Args
>
())...);
*
iter
=
f
((
input_iter
.
template
data
<
Index
,
Args
>
())...);
}
}
}
}
};
};
template
<
typename
T
>
struct
handle_type_name
<
array_t
<
T
>>
{
static
PYBIND11_DESCR
name
()
{
return
_
(
"array["
)
+
type_caster
<
T
>::
name
()
+
_
(
"]"
);
}
};
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
detail
)
template
<
typename
Func
,
typename
Return
,
typename
...
Args
>
template
<
typename
Func
,
typename
Return
,
typename
...
Args
>
...
...
setup.py
View file @
d6e4cef6
...
@@ -27,9 +27,7 @@ setup(
...
@@ -27,9 +27,7 @@ setup(
'include/pybind11/functional.h'
,
'include/pybind11/functional.h'
,
'include/pybind11/operators.h'
,
'include/pybind11/operators.h'
,
'include/pybind11/pytypes.h'
,
'include/pybind11/pytypes.h'
,
'include/pybind11/typeid.h'
,
'include/pybind11/typeid.h'
'include/pybind11/short_vector.h'
,
'include/pybind11/array_iterator.h'
],
],
classifiers
=
[
classifiers
=
[
'Development Status :: 5 - Production/Stable'
,
'Development Status :: 5 - Production/Stable'
,
...
...
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