Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
512a28f3
提交
512a28f3
authored
6月 04, 2012
作者:
Matthew Rocklin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move LoadFromDisk op to new io.py file
Also moved relevant test
上级
78348f09
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
74 行增加
和
65 行删除
+74
-65
basic.py
theano/tensor/basic.py
+0
-54
io.py
theano/tensor/io.py
+59
-0
test_basic.py
theano/tensor/tests/test_basic.py
+0
-11
test_io.py
theano/tensor/tests/test_io.py
+15
-0
没有找到文件。
theano/tensor/basic.py
浏览文件 @
512a28f3
...
@@ -2021,60 +2021,6 @@ def cast(x, dtype):
...
@@ -2021,60 +2021,6 @@ def cast(x, dtype):
'imag(), angle() or abs()'
))
'imag(), angle() or abs()'
))
return
_cast_mapping
[
dtype
](
x
)
return
_cast_mapping
[
dtype
](
x
)
##########################
# Disk Access
##########################
class
LoadFromDisk
(
Op
):
"""
An operation to load an array from disk
See Also
load
@note: Non-differentiable.
"""
def
__init__
(
self
,
dtype
,
broadcastable
):
self
.
dtype
=
dtype
self
.
broadcastable
=
broadcastable
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
)
and
self
.
broadcastable
==
other
.
broadcastable
and
self
.
dtype
==
other
.
dtype
)
def
__hash__
(
self
):
return
hash
((
type
(
self
),
self
.
dtype
,
self
.
broadcastable
))
def
make_node
(
self
,
path
):
if
isinstance
(
path
,
str
):
path
=
Constant
(
Generic
(),
path
)
return
gof
.
Apply
(
self
,
[
path
],
[
tensor
(
self
.
dtype
,
broadcastable
=
self
.
broadcastable
)])
def
perform
(
self
,
node
,
inp
,
out
):
path
=
inp
[
0
]
d
=
numpy
.
load
(
path
)
out
[
0
][
0
]
=
d
[
d
.
keys
()[
0
]]
.
astype
(
self
.
dtype
)
def
__str__
(
self
):
return
"Load:
%
s,
%
s"
%
(
self
.
dtype
,
self
.
broadcastable
)
def
load
(
path
,
dtype
,
broadcastable
):
"""
Load an array from a .npz file
>>> from theano import *
>>> path = Variable(Generic())
>>> x = tensor.load(path, 'int64', (False,))
>>> y = x*2
>>> fn = function([path], y)
>>> fn("stored-array.npz")
array([0, 2, 4, 6, 8], dtype=int64)
"""
return
LoadFromDisk
(
dtype
,
broadcastable
)(
path
)
##########################
##########################
# Unary Operations
# Unary Operations
##########################
##########################
...
...
theano/tensor/io.py
0 → 100644
浏览文件 @
512a28f3
import
numpy
import
theano
from
theano
import
gof
from
theano.gof
import
Apply
,
Constant
,
Generic
,
Op
,
Type
,
Value
,
Variable
from
basic
import
tensor
##########################
# Disk Access
##########################
class
LoadFromDisk
(
Op
):
"""
An operation to load an array from disk
See Also
load
@note: Non-differentiable.
"""
def
__init__
(
self
,
dtype
,
broadcastable
):
self
.
dtype
=
dtype
self
.
broadcastable
=
broadcastable
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
)
and
self
.
broadcastable
==
other
.
broadcastable
and
self
.
dtype
==
other
.
dtype
)
def
__hash__
(
self
):
return
hash
((
type
(
self
),
self
.
dtype
,
self
.
broadcastable
))
def
make_node
(
self
,
path
):
if
isinstance
(
path
,
str
):
path
=
Constant
(
Generic
(),
path
)
return
gof
.
Apply
(
self
,
[
path
],
[
tensor
(
self
.
dtype
,
broadcastable
=
self
.
broadcastable
)])
def
perform
(
self
,
node
,
inp
,
out
):
path
=
inp
[
0
]
d
=
numpy
.
load
(
path
)
out
[
0
][
0
]
=
d
[
d
.
keys
()[
0
]]
.
astype
(
self
.
dtype
)
def
__str__
(
self
):
return
"Load:
%
s,
%
s"
%
(
self
.
dtype
,
self
.
broadcastable
)
def
load
(
path
,
dtype
,
broadcastable
):
"""
Load an array from a .npz file
>>> from theano import *
>>> path = Variable(Generic())
>>> x = tensor.load(path, 'int64', (False,))
>>> y = x*2
>>> fn = function([path], y)
>>> fn("stored-array.npz")
array([0, 2, 4, 6, 8], dtype=int64)
"""
return
LoadFromDisk
(
dtype
,
broadcastable
)(
path
)
theano/tensor/tests/test_basic.py
浏览文件 @
512a28f3
...
@@ -3964,17 +3964,6 @@ class T_scalarfromtensor(unittest.TestCase):
...
@@ -3964,17 +3964,6 @@ class T_scalarfromtensor(unittest.TestCase):
self
.
assertTrue
(
isinstance
(
v
,
numpy
.
int64
))
self
.
assertTrue
(
isinstance
(
v
,
numpy
.
int64
))
self
.
assertTrue
(
v
.
shape
==
(),
v
.
shape
)
self
.
assertTrue
(
v
.
shape
==
(),
v
.
shape
)
class
T_load_tensor
(
unittest
.
TestCase
):
def
test0
(
self
):
data
=
numpy
.
arange
(
5
)
filename
=
"_load_tensor_test_1.npz"
numpy
.
savez
(
filename
,
data
)
path
=
Variable
(
Generic
())
x
=
tensor
.
load
(
path
,
'int64'
,
(
False
,))
y
=
x
*
2
fn
=
function
([
path
],
[
y
])
assert
(
fn
(
filename
)
==
data
*
2
)
.
all
()
class
test_grad
(
unittest
.
TestCase
):
class
test_grad
(
unittest
.
TestCase
):
class
O
(
gof
.
op
.
Op
):
class
O
(
gof
.
op
.
Op
):
def
__init__
(
self
):
def
__init__
(
self
):
...
...
theano/tensor/tests/test_io.py
0 → 100644
浏览文件 @
512a28f3
import
unittest
from
theano
import
tensor
,
function
,
Variable
,
Generic
import
numpy
class
T_load_tensor
(
unittest
.
TestCase
):
def
test0
(
self
):
data
=
numpy
.
arange
(
5
)
filename
=
"_load_tensor_test_1.npz"
numpy
.
savez
(
filename
,
data
)
path
=
Variable
(
Generic
())
x
=
tensor
.
load
(
path
,
'int64'
,
(
False
,))
y
=
x
*
2
fn
=
function
([
path
],
[
y
])
assert
(
fn
(
filename
)
==
data
*
2
)
.
all
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论