Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
84a48576
提交
84a48576
authored
1月 23, 2012
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'delallea/tmp2'
上级
b9977855
f9ca8f9d
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
53 行增加
和
20 行删除
+53
-20
__init__.py
theano/__init__.py
+23
-14
gradient.py
theano/gradient.py
+0
-0
basic.py
theano/sparse/basic.py
+12
-0
test_basic.py
theano/sparse/tests/test_basic.py
+14
-0
__init__.py
theano/tensor/__init__.py
+2
-4
basic.py
theano/tensor/basic.py
+2
-2
tensor_grad.py
theano/tensor/tensor_grad.py
+0
-0
test_2nd_order_grads.py
theano/tests/test_2nd_order_grads.py
+0
-0
test_rop.py
theano/tests/test_rop.py
+0
-0
没有找到文件。
theano/__init__.py
浏览文件 @
84a48576
"""
Theano is an optimizing compiler in Python, built to evaluate complicated expressions
(especially matrix-valued ones) as quickly as possible.
Theano compiles expression graphs (see :doc:`graph` ) that are built by Python code.
The expressions in these graphs are called `Apply` nodes and the variables in these graphs are called `Variable` nodes.
You compile a graph by calling `function`, which takes a graph, and returns a callable object.
One of theano's most important features is that `function` can transform your graph before
compiling it.
It can replace simple expressions with faster or more numerically stable implementations.
Theano is an optimizing compiler in Python, built to evaluate
complicated expressions (especially matrix-valued ones) as quickly as
possible. Theano compiles expression graphs (see :doc:`graph` ) that
are built by Python code. The expressions in these graphs are called
`Apply` nodes and the variables in these graphs are called `Variable`
nodes.
You compile a graph by calling `function`, which takes a graph, and
returns a callable object. One of theano's most important features is
that `function` can transform your graph before compiling it. It can
replace simple expressions with faster or more numerically stable
implementations.
To learn more, check out:
...
...
@@ -37,7 +40,8 @@ logging_default_handler.setFormatter(logging_default_formatter)
theano_logger
.
addHandler
(
logging_default_handler
)
theano_logger
.
setLevel
(
logging
.
WARNING
)
import
configparser
,
configdefaults
import
configparser
import
configdefaults
config
=
configparser
.
TheanoConfigParser
()
...
...
@@ -87,8 +91,10 @@ from updates import Updates
import
tensor
import
scalar
#import sparse #we don't import by default as we don't want to force having scipy installed.
#we don't import by default as we don't want to force having scipy installed.
#import sparse
import
gradient
from
gradient
import
Rop
,
Lop
,
grad
import
gof
if
config
.
device
.
startswith
(
'gpu'
)
or
config
.
init_gpu_device
.
startswith
(
'gpu'
):
...
...
@@ -126,8 +132,10 @@ del _all, _divide, _over, _under, _invalid
## import scalar_opt
### This is defined here because it is designed to work across symbolic datatypes
# (Sparse and Tensor)
### This is defined here because it is designed to work across symbolic
# datatypes (Sparse and Tensor)
def
dot
(
l
,
r
):
"""Return a symbolic matrix/dot product between l and r """
rval
=
NotImplemented
...
...
@@ -144,5 +152,6 @@ def dot(l, r):
except
Exception
,
e1
:
rval
=
NotImplemented
if
rval
==
NotImplemented
:
raise
NotImplementedError
(
"Dot failed for the following reasons:"
,
(
e0
,
e1
))
raise
NotImplementedError
(
"Dot failed for the following reasons:"
,
(
e0
,
e1
))
return
rval
theano/gradient.py
浏览文件 @
84a48576
差异被折叠。
点击展开。
theano/sparse/basic.py
浏览文件 @
84a48576
...
...
@@ -137,6 +137,15 @@ def sp_ones_like(x):
data
,
indices
,
indptr
,
shape
=
csm_properties
(
x
)
#TODO: don't restrict to CSM formats
return
CSM
(
format
=
x
.
format
)(
tensor
.
ones_like
(
data
),
indices
,
indptr
,
shape
)
def
sp_zeros_like
(
x
):
#TODO: don't restrict to CSM formats
_
,
_
,
indptr
,
shape
=
csm_properties
(
x
)
return
CSM
(
format
=
x
.
format
)(
numpy
.
array
([],
dtype
=
x
.
type
.
dtype
),
numpy
.
array
([]),
tensor
.
zeros_like
(
indptr
),
shape
)
class
_sparse_py_operators
:
T
=
property
(
lambda
self
:
transpose
(
self
),
doc
=
"Return aliased transpose of self (read-only)"
)
def
__neg__
(
self
):
return
neg
(
self
)
...
...
@@ -172,6 +181,9 @@ class _sparse_py_operators:
# that stored zeros *do* count in the size.
size
=
property
(
lambda
self
:
csm_data
(
self
)
.
size
)
def
zeros_like
(
model
):
return
sp_zeros_like
(
model
)
class
SparseVariable
(
gof
.
Variable
,
_sparse_py_operators
):
dtype
=
property
(
lambda
self
:
self
.
type
.
dtype
)
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
84a48576
...
...
@@ -820,6 +820,20 @@ class UsmmTests(unittest.TestCase):
for
node
in
topo
])
==
nb
class
test_zeros_like
(
unittest
.
TestCase
):
def
test
(
self
):
x
=
theano
.
sparse
.
csr_matrix
()
f
=
theano
.
function
([
x
],
theano
.
sparse
.
sp_zeros_like
(
x
))
vx
=
scipy
.
sparse
.
csr_matrix
(
numpy
.
asarray
(
numpy
.
random
.
binomial
(
1
,
0.5
,
(
100
,
100
)),
dtype
=
theano
.
config
.
floatX
))
fx
=
f
(
vx
)
assert
fx
.
nnz
==
0
assert
fx
.
shape
==
vx
.
shape
def
test_shape_i
():
sparse_dtype
=
'float32'
...
...
theano/tensor/__init__.py
浏览文件 @
84a48576
...
...
@@ -30,7 +30,6 @@ import sharedvar # adds shared-variable constructors
# `theano.shared` and `tensor._shared`.
from
sharedvar
import
tensor_constructor
as
_shared
def
shared
(
*
args
,
**
kw
):
"""
Backward-compatibility wrapper around `tensor._shared`.
...
...
@@ -50,6 +49,5 @@ def shared(*args, **kw):
import
nnet
# used for softmax, sigmoid, etc.
from
tensor_grad
import
Rop
,
Lop
,
grad
,
numeric_grad
,
verify_grad
,
\
jacobian
,
hessian
from
theano.gradient
import
Rop
,
Lop
,
grad
,
numeric_grad
,
verify_grad
,
\
jacobian
,
hessian
theano/tensor/basic.py
浏览文件 @
84a48576
...
...
@@ -1450,12 +1450,13 @@ class _tensor_py_operators:
def
get_constant_value
(
self
):
return
get_constant_value
(
self
)
def
zeros_like
(
model
):
return
zeros_like
(
model
)
class
TensorVariable
(
_tensor_py_operators
,
Variable
):
"""Subclass to add the tensor operators to the basic `Variable` class."""
TensorType
.
Variable
=
TensorVariable
...
...
@@ -2368,7 +2369,6 @@ def zeros_like(model, dtype=None):
dtype
=
model
.
type
.
dtype
return
fill
(
model
,
constant
(
0.0
,
dtype
=
dtype
))
def
zeros
(
shape
,
dtype
=
config
.
floatX
):
"""
Create a Tensor filled with zeros, closer to Numpy's syntax than ``alloc``.
...
...
theano/tensor/tensor_grad.py
deleted
100644 → 0
浏览文件 @
b9977855
差异被折叠。
点击展开。
theano/te
nsor/te
sts/test_2nd_order_grads.py
→
theano/tests/test_2nd_order_grads.py
浏览文件 @
84a48576
File moved
theano/te
nsor/te
sts/test_rop.py
→
theano/tests/test_rop.py
浏览文件 @
84a48576
File moved
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论