Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
2fa274cf
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2fa274cf
编写于
5月 30, 2017
作者:
H
Helin Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix according to comments
上级
ec5db380
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
53 addition
and
55 deletion
+53
-55
paddle/go/crecordio/crecordio.go
paddle/go/crecordio/crecordio.go
+17
-18
paddle/go/crecordio/test/test.c
paddle/go/crecordio/test/test.c
+13
-14
paddle/go/recordio/range_scanner.go
paddle/go/recordio/range_scanner.go
+8
-8
paddle/go/recordio/recordio_internal_test.go
paddle/go/recordio/recordio_internal_test.go
+1
-1
paddle/go/recordio/recordio_test.go
paddle/go/recordio/recordio_test.go
+2
-2
paddle/go/recordio/scanner.go
paddle/go/recordio/scanner.go
+12
-12
未找到文件。
paddle/go/crecordio/crecordio.go
浏览文件 @
2fa274cf
...
...
@@ -25,7 +25,7 @@ type writer struct {
}
type
reader
struct
{
scanner
*
recordio
.
Multi
Scanner
scanner
*
recordio
.
Scanner
}
func
cArrayToSlice
(
p
unsafe
.
Pointer
,
len
int
)
[]
byte
{
...
...
@@ -55,21 +55,21 @@ func create_recordio_writer(path *C.char) C.writer {
return
addWriter
(
writer
)
}
//export
write_recordio
func
write_recordio
(
writer
C
.
writer
,
buf
*
C
.
uchar
,
size
C
.
int
)
int
{
//export
recordio_write
func
recordio_write
(
writer
C
.
writer
,
buf
*
C
.
uchar
,
size
C
.
int
)
C
.
int
{
w
:=
getWriter
(
writer
)
b
:=
cArrayToSlice
(
unsafe
.
Pointer
(
buf
),
int
(
size
))
_
,
err
:=
w
.
w
.
Write
(
b
)
c
,
err
:=
w
.
w
.
Write
(
b
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
-
1
}
return
0
return
C
.
int
(
c
)
}
//export release_recordio
func
release_recordio
(
writer
C
.
writer
)
{
//export release_recordio
_writer
func
release_recordio
_writer
(
writer
C
.
writer
)
{
w
:=
removeWriter
(
writer
)
w
.
w
.
Close
()
w
.
f
.
Close
()
...
...
@@ -78,7 +78,7 @@ func release_recordio(writer C.writer) {
//export create_recordio_reader
func
create_recordio_reader
(
path
*
C
.
char
)
C
.
reader
{
p
:=
C
.
GoString
(
path
)
s
,
err
:=
recordio
.
New
MultiScanner
(
strings
.
Split
(
p
,
","
)
)
s
,
err
:=
recordio
.
New
Scanner
(
strings
.
Split
(
p
,
","
)
...
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
-
1
...
...
@@ -88,24 +88,23 @@ func create_recordio_reader(path *C.char) C.reader {
return
addReader
(
r
)
}
//export re
ad_next_item
func
re
ad_next_item
(
reader
C
.
reader
,
size
*
C
.
int
)
*
C
.
uchar
{
//export re
cordio_read
func
re
cordio_read
(
reader
C
.
reader
,
record
**
C
.
uchar
)
C
.
int
{
r
:=
getReader
(
reader
)
if
r
.
scanner
.
Scan
()
{
buf
:=
r
.
scanner
.
Record
()
*
size
=
C
.
int
(
len
(
buf
))
if
len
(
buf
)
==
0
{
return
(
*
C
.
uchar
)(
nullPtr
)
*
record
=
(
*
C
.
uchar
)(
nullPtr
)
return
0
}
ptr
:=
C
.
malloc
(
C
.
size_t
(
len
(
buf
)))
C
.
memcpy
(
ptr
,
unsafe
.
Pointer
(
&
buf
[
0
]),
C
.
size_t
(
len
(
buf
)))
return
(
*
C
.
uchar
)(
ptr
)
size
:=
C
.
int
(
len
(
buf
))
*
record
=
(
*
C
.
uchar
)(
C
.
malloc
(
C
.
size_t
(
len
(
buf
))))
C
.
memcpy
(
unsafe
.
Pointer
(
*
record
),
unsafe
.
Pointer
(
&
buf
[
0
]),
C
.
size_t
(
len
(
buf
)))
return
size
}
*
size
=
-
1
return
(
*
C
.
uchar
)(
nullPtr
)
return
-
1
}
//export release_recordio_reader
...
...
paddle/go/crecordio/test/test.c
浏览文件 @
2fa274cf
...
...
@@ -12,44 +12,43 @@ void fail() {
int
main
()
{
writer
w
=
create_recordio_writer
(
"/tmp/test_recordio_0"
);
write_recordio
(
w
,
"hello"
,
6
);
write_recordio
(
w
,
"hi"
,
3
);
release_recordio
(
w
);
recordio_write
(
w
,
"hello"
,
6
);
recordio_write
(
w
,
"hi"
,
3
);
release_recordio
_writer
(
w
);
w
=
create_recordio_writer
(
"/tmp/test_recordio_1"
);
write_recordio
(
w
,
"dog"
,
4
);
write_recordio
(
w
,
"cat"
,
4
);
release_recordio
(
w
);
recordio_write
(
w
,
"dog"
,
4
);
recordio_write
(
w
,
"cat"
,
4
);
release_recordio
_writer
(
w
);
reader
r
=
create_recordio_reader
(
"/tmp/test_recordio_*"
);
int
size
;
unsigned
char
*
item
=
read_next_item
(
r
,
&
size
);
unsigned
char
*
item
=
NULL
;
int
size
=
recordio_read
(
r
,
&
item
);
if
(
strcmp
(
item
,
"hello"
)
||
size
!=
6
)
{
fail
();
}
free
(
item
);
item
=
read_next_item
(
r
,
&
size
);
size
=
recordio_read
(
r
,
&
item
);
if
(
strcmp
(
item
,
"hi"
)
||
size
!=
3
)
{
fail
();
}
free
(
item
);
item
=
read_next_item
(
r
,
&
size
);
size
=
recordio_read
(
r
,
&
item
);
if
(
strcmp
(
item
,
"dog"
)
||
size
!=
4
)
{
fail
();
}
free
(
item
);
item
=
read_next_item
(
r
,
&
size
);
size
=
recordio_read
(
r
,
&
item
);
if
(
strcmp
(
item
,
"cat"
)
||
size
!=
4
)
{
fail
();
}
free
(
item
);
item
=
read_next_item
(
r
,
&
size
);
if
(
item
!=
NULL
||
size
!=
-
1
)
{
size
=
recordio_read
(
r
,
&
item
);
if
(
size
!=
-
1
)
{
fail
();
}
...
...
paddle/go/recordio/r
ead
er.go
→
paddle/go/recordio/r
ange_scann
er.go
浏览文件 @
2fa274cf
...
...
@@ -74,8 +74,8 @@ func (r *Index) Locate(recordIndex int) (int, int) {
return
-
1
,
-
1
}
// Scanner scans records in a specified range within [0, numRecords).
type
Scanner
struct
{
//
Range
Scanner scans records in a specified range within [0, numRecords).
type
Range
Scanner
struct
{
reader
io
.
ReadSeeker
index
*
Index
start
,
end
,
cur
int
...
...
@@ -84,10 +84,10 @@ type Scanner struct {
err
error
}
// NewScanner creates a scanner that sequencially reads records in the
// New
Range
Scanner creates a scanner that sequencially reads records in the
// range [start, start+len). If start < 0, it scans from the
// beginning. If len < 0, it scans till the end of file.
func
New
Scanner
(
r
io
.
ReadSeeker
,
index
*
Index
,
start
,
len
int
)
*
Scanner
{
func
New
RangeScanner
(
r
io
.
ReadSeeker
,
index
*
Index
,
start
,
len
int
)
*
Range
Scanner
{
if
start
<
0
{
start
=
0
}
...
...
@@ -95,7 +95,7 @@ func NewScanner(r io.ReadSeeker, index *Index, start, len int) *Scanner {
len
=
index
.
NumRecords
()
-
start
}
return
&
Scanner
{
return
&
Range
Scanner
{
reader
:
r
,
index
:
index
,
start
:
start
,
...
...
@@ -108,7 +108,7 @@ func NewScanner(r io.ReadSeeker, index *Index, start, len int) *Scanner {
// Scan moves the cursor forward for one record and loads the chunk
// containing the record if not yet.
func
(
s
*
Scanner
)
Scan
()
bool
{
func
(
s
*
Range
Scanner
)
Scan
()
bool
{
s
.
cur
++
if
s
.
cur
>=
s
.
end
{
...
...
@@ -124,14 +124,14 @@ func (s *Scanner) Scan() bool {
}
// Record returns the record under the current cursor.
func
(
s
*
Scanner
)
Record
()
[]
byte
{
func
(
s
*
Range
Scanner
)
Record
()
[]
byte
{
_
,
ri
:=
s
.
index
.
Locate
(
s
.
cur
)
return
s
.
chunk
.
records
[
ri
]
}
// Err returns the first non-EOF error that was encountered by the
// Scanner.
func
(
s
*
Scanner
)
Err
()
error
{
func
(
s
*
Range
Scanner
)
Err
()
error
{
if
s
.
err
==
io
.
EOF
{
return
nil
}
...
...
paddle/go/recordio/recordio_internal_test.go
浏览文件 @
2fa274cf
...
...
@@ -68,7 +68,7 @@ func TestWriteAndRead(t *testing.T) {
2
*
4
)},
// two record legnths
idx
.
chunkOffsets
)
s
:=
NewScanner
(
bytes
.
NewReader
(
buf
.
Bytes
()),
idx
,
-
1
,
-
1
)
s
:=
New
Range
Scanner
(
bytes
.
NewReader
(
buf
.
Bytes
()),
idx
,
-
1
,
-
1
)
i
:=
0
for
s
.
Scan
()
{
assert
.
Equal
(
data
[
i
],
string
(
s
.
Record
()))
...
...
paddle/go/recordio/recordio_test.go
浏览文件 @
2fa274cf
...
...
@@ -29,7 +29,7 @@ func TestWriteRead(t *testing.T) {
t
.
Fatal
(
"num record does not match:"
,
idx
.
NumRecords
(),
total
)
}
s
:=
recordio
.
NewScanner
(
bytes
.
NewReader
(
buf
.
Bytes
()),
idx
,
-
1
,
-
1
)
s
:=
recordio
.
New
Range
Scanner
(
bytes
.
NewReader
(
buf
.
Bytes
()),
idx
,
-
1
,
-
1
)
i
:=
0
for
s
.
Scan
()
{
if
!
reflect
.
DeepEqual
(
s
.
Record
(),
make
([]
byte
,
i
))
{
...
...
@@ -66,7 +66,7 @@ func TestChunkIndex(t *testing.T) {
for
i
:=
0
;
i
<
total
;
i
++
{
newIdx
:=
idx
.
ChunkIndex
(
i
)
s
:=
recordio
.
NewScanner
(
bytes
.
NewReader
(
buf
.
Bytes
()),
newIdx
,
-
1
,
-
1
)
s
:=
recordio
.
New
Range
Scanner
(
bytes
.
NewReader
(
buf
.
Bytes
()),
newIdx
,
-
1
,
-
1
)
j
:=
0
for
s
.
Scan
()
{
if
!
reflect
.
DeepEqual
(
s
.
Record
(),
make
([]
byte
,
i
))
{
...
...
paddle/go/recordio/
multi_read
er.go
→
paddle/go/recordio/
scann
er.go
浏览文件 @
2fa274cf
...
...
@@ -6,18 +6,18 @@ import (
"path/filepath"
)
//
Multi
Scanner is a scanner for multiple recordio files.
type
Multi
Scanner
struct
{
// Scanner is a scanner for multiple recordio files.
type
Scanner
struct
{
paths
[]
string
curFile
*
os
.
File
curScanner
*
Scanner
curScanner
*
Range
Scanner
pathIdx
int
end
bool
err
error
}
// New
MultiScanner creates a new Multi
Scanner.
func
New
MultiScanner
(
paths
[]
string
)
(
*
Multi
Scanner
,
error
)
{
// New
Scanner creates a new
Scanner.
func
New
Scanner
(
paths
...
string
)
(
*
Scanner
,
error
)
{
var
ps
[]
string
for
_
,
s
:=
range
paths
{
match
,
err
:=
filepath
.
Glob
(
s
)
...
...
@@ -32,12 +32,12 @@ func NewMultiScanner(paths []string) (*MultiScanner, error) {
return
nil
,
fmt
.
Errorf
(
"no valid path provided: %v"
,
paths
)
}
return
&
Multi
Scanner
{
paths
:
ps
},
nil
return
&
Scanner
{
paths
:
ps
},
nil
}
// Scan moves the cursor forward for one record and loads the chunk
// containing the record if not yet.
func
(
s
*
Multi
Scanner
)
Scan
()
bool
{
func
(
s
*
Scanner
)
Scan
()
bool
{
if
s
.
err
!=
nil
{
return
false
}
...
...
@@ -92,12 +92,12 @@ func (s *MultiScanner) Scan() bool {
// Err returns the first non-EOF error that was encountered by the
// Scanner.
func
(
s
*
Multi
Scanner
)
Err
()
error
{
func
(
s
*
Scanner
)
Err
()
error
{
return
s
.
err
}
// Record returns the record under the current cursor.
func
(
s
*
Multi
Scanner
)
Record
()
[]
byte
{
func
(
s
*
Scanner
)
Record
()
[]
byte
{
if
s
.
curScanner
==
nil
{
return
nil
}
...
...
@@ -106,7 +106,7 @@ func (s *MultiScanner) Record() []byte {
}
// Close release the resources.
func
(
s
*
Multi
Scanner
)
Close
()
error
{
func
(
s
*
Scanner
)
Close
()
error
{
s
.
curScanner
=
nil
if
s
.
curFile
!=
nil
{
err
:=
s
.
curFile
.
Close
()
...
...
@@ -116,7 +116,7 @@ func (s *MultiScanner) Close() error {
return
nil
}
func
(
s
*
Multi
Scanner
)
nextFile
()
(
bool
,
error
)
{
func
(
s
*
Scanner
)
nextFile
()
(
bool
,
error
)
{
if
s
.
pathIdx
>=
len
(
s
.
paths
)
{
return
false
,
nil
}
...
...
@@ -135,6 +135,6 @@ func (s *MultiScanner) nextFile() (bool, error) {
}
s
.
curFile
=
f
s
.
curScanner
=
NewScanner
(
f
,
idx
,
0
,
-
1
)
s
.
curScanner
=
New
Range
Scanner
(
f
,
idx
,
0
,
-
1
)
return
true
,
nil
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录