Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3775cef2
提交
3775cef2
authored
6月 04, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #669 from mrocklin/load-op
Load op
上级
f61e8099
98c29e37
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
92 行增加
和
5 行删除
+92
-5
graph.py
theano/gof/graph.py
+3
-3
__init__.py
theano/tensor/__init__.py
+1
-0
basic.py
theano/tensor/basic.py
+0
-1
io.py
theano/tensor/io.py
+64
-0
test_basic.py
theano/tensor/tests/test_basic.py
+0
-1
test_io.py
theano/tensor/tests/test_io.py
+24
-0
没有找到文件。
theano/gof/graph.py
浏览文件 @
3775cef2
...
@@ -559,7 +559,8 @@ def orphans(i, o):
...
@@ -559,7 +559,8 @@ def orphans(i, o):
def
clone
(
i
,
o
,
copy_inputs
=
True
):
def
clone
(
i
,
o
,
copy_inputs
=
True
):
""" WRITEME
"""
Copies the subgraph contained between i and o.
:type i: list
:type i: list
:param i: input L{Variable}s
:param i: input L{Variable}s
...
@@ -568,8 +569,7 @@ def clone(i, o, copy_inputs = True):
...
@@ -568,8 +569,7 @@ def clone(i, o, copy_inputs = True):
:type copy_inputs: bool
:type copy_inputs: bool
:param copy_inputs: if True, the inputs will be copied (defaults to False)
:param copy_inputs: if True, the inputs will be copied (defaults to False)
Copies the subgraph contained between i and o and returns the
Returns the inputs and outputs of that copy.
outputs of that copy (corresponding to o).
"""
"""
equiv
=
clone_get_equiv
(
i
,
o
,
copy_inputs
)
equiv
=
clone_get_equiv
(
i
,
o
,
copy_inputs
)
return
[
equiv
[
input
]
for
input
in
i
],
[
equiv
[
output
]
for
output
in
o
]
return
[
equiv
[
input
]
for
input
in
i
],
[
equiv
[
output
]
for
output
in
o
]
...
...
theano/tensor/__init__.py
浏览文件 @
3775cef2
...
@@ -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/basic.py
浏览文件 @
3775cef2
...
@@ -2021,7 +2021,6 @@ def cast(x, dtype):
...
@@ -2021,7 +2021,6 @@ def cast(x, dtype):
'imag(), angle() or abs()'
))
'imag(), angle() or abs()'
))
return
_cast_mapping
[
dtype
](
x
)
return
_cast_mapping
[
dtype
](
x
)
##########################
##########################
# Unary Operations
# Unary Operations
##########################
##########################
...
...
theano/tensor/io.py
0 → 100644
浏览文件 @
3775cef2
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
,
mmap_mode
=
None
):
self
.
dtype
=
numpy
.
dtype
(
dtype
)
# turn "float64" into numpy.float64
self
.
broadcastable
=
broadcastable
self
.
mmap_mode
=
mmap_mode
self
.
_info
=
(
dtype
,
broadcastable
,
mmap_mode
)
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
)
and
self
.
_info
==
other
.
_info
)
def
__hash__
(
self
):
return
hash
(
self
.
_info
)
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
]
if
(
path
.
split
(
'.'
)[
-
1
]
==
'npz'
):
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
):
return
"Load{dtype:
%
s, broadcastable:
%
s, mmep:
%
s}"
%
self
.
_info
def
load
(
path
,
dtype
,
broadcastable
,
mmap_mode
=
None
):
"""
Load an array from an .npy file
>>> from theano import *
>>> path = Variable(Generic())
>>> x = tensor.load(path, 'int64', (False,))
>>> y = x*2
>>> fn = function([path], y)
>>> fn("stored-array.npy")
array([0, 2, 4, 6, 8], dtype=int64)
"""
return
LoadFromDisk
(
dtype
,
broadcastable
,
mmap_mode
)(
path
)
theano/tensor/tests/test_basic.py
浏览文件 @
3775cef2
...
@@ -3964,7 +3964,6 @@ class T_scalarfromtensor(unittest.TestCase):
...
@@ -3964,7 +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
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
浏览文件 @
3775cef2
import
unittest
import
theano
from
theano
import
tensor
,
function
,
Variable
,
Generic
import
numpy
import
os
class
T_load_tensor
(
unittest
.
TestCase
):
def
test0
(
self
):
data
=
numpy
.
arange
(
5
,
dtype
=
numpy
.
int32
)
filename
=
os
.
path
.
join
(
theano
.
config
.
base_compiledir
,
"_test.npy"
)
numpy
.
save
(
filename
,
data
)
path
=
Variable
(
Generic
())
x
=
tensor
.
load
(
path
,
'int32'
,
(
False
,))
y
=
x
*
2
fn
=
function
([
path
],
y
)
assert
(
fn
(
filename
)
==
data
*
2
)
.
all
()
def
test_memmap
(
self
):
data
=
numpy
.
arange
(
5
,
dtype
=
numpy
.
int32
)
filename
=
os
.
path
.
join
(
theano
.
config
.
base_compiledir
,
"_test.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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论