Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
466935b4
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
466935b4
编写于
2月 22, 2017
作者:
H
Helin Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add decorator: map_readers
上级
963de16b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
1 deletion
+40
-1
python/paddle/reader/decorator.py
python/paddle/reader/decorator.py
+24
-1
python/paddle/reader/tests/decorator_test.py
python/paddle/reader/tests/decorator_test.py
+16
-0
未找到文件。
python/paddle/reader/decorator.py
浏览文件 @
466935b4
...
@@ -12,7 +12,10 @@
...
@@ -12,7 +12,10 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
__all__
=
[
'buffered'
,
'compose'
,
'chain'
,
'shuffle'
,
'ComposeNotAligned'
]
__all__
=
[
'map_readers'
,
'buffered'
,
'compose'
,
'chain'
,
'shuffle'
,
'ComposeNotAligned'
]
from
Queue
import
Queue
from
Queue
import
Queue
from
threading
import
Thread
from
threading
import
Thread
...
@@ -20,6 +23,26 @@ import itertools
...
@@ -20,6 +23,26 @@ import itertools
import
random
import
random
def
map_readers
(
func
,
*
readers
):
"""
Creates a data reader that outputs return value of function using
output of each data readers as arguments.
:param func: function to use.
:param *readers: readers whose outputs will be used as arguments of func.
:returns: the created data reader.
"""
def
reader
():
rs
=
[]
for
r
in
readers
:
rs
.
append
(
r
())
for
e
in
itertools
.
imap
(
func
,
*
rs
):
yield
e
return
reader
def
shuffle
(
reader
,
buf_size
):
def
shuffle
(
reader
,
buf_size
):
"""
"""
Creates a data reader whose data output is suffled.
Creates a data reader whose data output is suffled.
...
...
python/paddle/reader/tests/decorator_test.py
浏览文件 @
466935b4
...
@@ -26,6 +26,22 @@ def reader_creator_10(dur):
...
@@ -26,6 +26,22 @@ def reader_creator_10(dur):
return
reader
return
reader
class
TestMap
(
unittest
.
TestCase
):
def
test_map
(
self
):
d
=
{
"h"
:
0
,
"i"
:
1
}
def
tokenize
(
x
):
return
d
[
x
]
def
read
():
yield
"h"
yield
"i"
r
=
paddle
.
reader
.
map_readers
(
tokenize
,
read
)
for
i
,
e
in
enumerate
(
r
()):
self
.
assertEqual
(
e
,
i
)
class
TestBuffered
(
unittest
.
TestCase
):
class
TestBuffered
(
unittest
.
TestCase
):
def
test_read
(
self
):
def
test_read
(
self
):
for
size
in
range
(
20
):
for
size
in
range
(
20
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录