Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
273eaf4c
提交
273eaf4c
authored
6月 04, 2012
作者:
Matthew Rocklin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added memmap mode to load. changed from npz to npy
上级
512a28f3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
31 行增加
和
18 行删除
+31
-18
__init__.py
theano/tensor/__init__.py
+1
-0
io.py
theano/tensor/io.py
+17
-12
test_io.py
theano/tensor/tests/test_io.py
+13
-6
没有找到文件。
theano/tensor/__init__.py
浏览文件 @
273eaf4c
...
@@ -30,6 +30,7 @@ import sharedvar # adds shared-variable constructors
...
@@ -30,6 +30,7 @@ import sharedvar # adds shared-variable constructors
# `theano.shared` and `tensor._shared`.
# `theano.shared` and `tensor._shared`.
from
sharedvar
import
tensor_constructor
as
_shared
from
sharedvar
import
tensor_constructor
as
_shared
from
io
import
*
def
shared
(
*
args
,
**
kw
):
def
shared
(
*
args
,
**
kw
):
"""
"""
...
...
theano/tensor/io.py
浏览文件 @
273eaf4c
...
@@ -16,17 +16,17 @@ class LoadFromDisk(Op):
...
@@ -16,17 +16,17 @@ class LoadFromDisk(Op):
@note: Non-differentiable.
@note: Non-differentiable.
"""
"""
def
__init__
(
self
,
dtype
,
broadcastable
):
def
__init__
(
self
,
dtype
,
broadcastable
,
mmap_mode
=
None
):
self
.
dtype
=
dtype
self
.
dtype
=
dtype
self
.
broadcastable
=
broadcastable
self
.
broadcastable
=
broadcastable
self
.
mmap_mode
=
mmap_mode
self
.
_info
=
(
dtype
,
broadcastable
,
mmap_mode
)
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
)
and
return
(
type
(
self
)
==
type
(
other
)
and
self
.
_info
==
other
.
_info
)
self
.
broadcastable
==
other
.
broadcastable
and
self
.
dtype
==
other
.
dtype
)
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
(
(
type
(
self
),
self
.
dtype
,
self
.
broadcastable
)
)
return
hash
(
self
.
_info
)
def
make_node
(
self
,
path
):
def
make_node
(
self
,
path
):
if
isinstance
(
path
,
str
):
if
isinstance
(
path
,
str
):
...
@@ -36,24 +36,29 @@ class LoadFromDisk(Op):
...
@@ -36,24 +36,29 @@ class LoadFromDisk(Op):
def
perform
(
self
,
node
,
inp
,
out
):
def
perform
(
self
,
node
,
inp
,
out
):
path
=
inp
[
0
]
path
=
inp
[
0
]
d
=
numpy
.
load
(
path
)
if
(
path
.
split
(
'.'
)[
-
1
]
==
'npz'
):
out
[
0
][
0
]
=
d
[
d
.
keys
()[
0
]]
.
astype
(
self
.
dtype
)
raise
ValueError
(
"Expected a .npy file, got
%
s instead"
%
path
)
result
=
numpy
.
load
(
path
,
mmap_mode
=
self
.
mmap_mode
)
if
result
.
dtype
!=
self
.
dtype
:
raise
TypeError
(
"Expected an array of type
%
s, got
%
s instead"
%
(
self
.
dtype
,
result
.
dtype
))
out
[
0
][
0
]
=
result
def
__str__
(
self
):
def
__str__
(
self
):
return
"Load:
%
s,
%
s"
%
(
self
.
dtype
,
self
.
broadcastable
)
return
"Load:
dtype:
%
s, broadcastable:
%
s, mmep:
%
s"
%
self
.
_info
def
load
(
path
,
dtype
,
broadcastable
):
def
load
(
path
,
dtype
,
broadcastable
,
mmap_mode
=
None
):
"""
"""
Load an array from a
.npz
file
Load an array from a
n .npy
file
>>> from theano import *
>>> from theano import *
>>> path = Variable(Generic())
>>> path = Variable(Generic())
>>> x = tensor.load(path, 'int64', (False,))
>>> x = tensor.load(path, 'int64', (False,))
>>> y = x*2
>>> y = x*2
>>> fn = function([path], y)
>>> fn = function([path], y)
>>> fn("stored-array.np
z
")
>>> fn("stored-array.np
y
")
array([0, 2, 4, 6, 8], dtype=int64)
array([0, 2, 4, 6, 8], dtype=int64)
"""
"""
return
LoadFromDisk
(
dtype
,
broadcastable
)(
path
)
return
LoadFromDisk
(
dtype
,
broadcastable
,
mmap_mode
)(
path
)
theano/tensor/tests/test_io.py
浏览文件 @
273eaf4c
...
@@ -4,12 +4,19 @@ import numpy
...
@@ -4,12 +4,19 @@ import numpy
class
T_load_tensor
(
unittest
.
TestCase
):
class
T_load_tensor
(
unittest
.
TestCase
):
def
test0
(
self
):
def
test0
(
self
):
data
=
numpy
.
arange
(
5
)
data
=
numpy
.
arange
(
5
,
dtype
=
numpy
.
int32
)
filename
=
"_load_tensor_test_1.np
z
"
filename
=
"_load_tensor_test_1.np
y
"
numpy
.
save
z
(
filename
,
data
)
numpy
.
save
(
filename
,
data
)
path
=
Variable
(
Generic
())
path
=
Variable
(
Generic
())
x
=
tensor
.
load
(
path
,
'int
64
'
,
(
False
,))
x
=
tensor
.
load
(
path
,
'int
32
'
,
(
False
,))
y
=
x
*
2
y
=
x
*
2
fn
=
function
([
path
],
[
y
]
)
fn
=
function
([
path
],
y
)
assert
(
fn
(
filename
)
==
data
*
2
)
.
all
()
assert
(
fn
(
filename
)
==
data
*
2
)
.
all
()
def
test_memmap
(
self
):
data
=
numpy
.
arange
(
5
,
dtype
=
numpy
.
int32
)
filename
=
"_load_tensor_test_1.npy"
numpy
.
save
(
filename
,
data
)
path
=
Variable
(
Generic
())
x
=
tensor
.
load
(
path
,
'int32'
,
(
False
,),
mmap_mode
=
'r+'
)
fn
=
function
([
path
],
x
)
assert
type
(
fn
(
filename
))
==
numpy
.
core
.
memmap
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论