Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e0d06a4e
提交
e0d06a4e
authored
9月 25, 2012
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #955 from nouiz/small
Small
上级
e76dbade
422190c4
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
51 行增加
和
17 行删除
+51
-17
.travis.yml
.travis.yml
+1
-1
faq.txt
doc/tutorial/faq.txt
+19
-0
scan_perform_ext.py
theano/scan_module/scan_perform_ext.py
+1
-1
extra_ops.py
theano/tensor/extra_ops.py
+11
-2
test_extra_ops.py
theano/tensor/tests/test_extra_ops.py
+9
-2
test_sort.py
theano/tensor/tests/test_sort.py
+10
-11
没有找到文件。
.travis.yml
浏览文件 @
e0d06a4e
...
@@ -11,7 +11,7 @@ before_install:
...
@@ -11,7 +11,7 @@ before_install:
-
sudo apt-get install -qq libatlas3gf-base libatlas-dev
-
sudo apt-get install -qq libatlas3gf-base libatlas-dev
install
:
install
:
#If we don't install numpy before SciPy 0.10.1, the SciPy installations fails.
#If we don't install numpy before SciPy 0.10.1, the SciPy installations fails.
-
"
pip
install
-q
numpy
--use-mirrors"
-
"
pip
install
-q
numpy
==1.4.1
--use-mirrors"
#We can't install SciPy as there is no BLAS installed.
#We can't install SciPy as there is no BLAS installed.
-
"
pip
install
.
--no-deps
--use-mirrors"
-
"
pip
install
.
--no-deps
--use-mirrors"
# command to run tests
# command to run tests
...
...
doc/tutorial/faq.txt
浏览文件 @
e0d06a4e
...
@@ -42,6 +42,25 @@ space to allow to reuse them during the next call to the same Theano
...
@@ -42,6 +42,25 @@ space to allow to reuse them during the next call to the same Theano
function if they are of the good shape. The shape could change if the
function if they are of the good shape. The shape could change if the
shape of the inputs change.
shape of the inputs change.
Faster Small Theano function
----------------------------
.. note::
For Theano 0.6 and up.
For Theano function that don't do much work like a regular logistic
regression, the overhead of checking the input can be significant. You
can disable it by setting f.trust_input to True to remove this
check. Make sure you pass argument as what you said when compiling the
Theano function.
Also for small Theano function, you can remove more python overhead by
making a Theano function that don't take any inputs. You can use shared
variable to help you. Then you can call it like this: ``f.fn()`` or
``f.fn(n_calls=N)`` to speed up. In the last case, only the last
function output is returned.
Related Projects
Related Projects
----------------
----------------
...
...
theano/scan_module/scan_perform_ext.py
浏览文件 @
e0d06a4e
...
@@ -51,7 +51,7 @@ except ImportError:
...
@@ -51,7 +51,7 @@ except ImportError:
loc
=
os
.
path
.
join
(
config
.
compiledir
,
dirname
)
loc
=
os
.
path
.
join
(
config
.
compiledir
,
dirname
)
if
not
os
.
path
.
exists
(
loc
):
if
not
os
.
path
.
exists
(
loc
):
os
.
mkdir
(
loc
)
os
.
mkdir
(
loc
)
preargs
=
[
'-
pthread'
,
'-
fwrapv'
,
'-O2'
,
'-fno-strict-aliasing'
]
preargs
=
[
'-fwrapv'
,
'-O2'
,
'-fno-strict-aliasing'
]
preargs
+=
cmodule
.
GCC_compiler
.
compile_args
()
preargs
+=
cmodule
.
GCC_compiler
.
compile_args
()
cmodule
.
GCC_compiler
.
compile_str
(
dirname
,
code
,
location
=
loc
,
cmodule
.
GCC_compiler
.
compile_str
(
dirname
,
code
,
location
=
loc
,
preargs
=
preargs
)
preargs
=
preargs
)
...
...
theano/tensor/extra_ops.py
浏览文件 @
e0d06a4e
...
@@ -91,6 +91,12 @@ class BinCountOp(theano.Op):
...
@@ -91,6 +91,12 @@ class BinCountOp(theano.Op):
def
__init__
(
self
,
minlength
=
None
):
def
__init__
(
self
,
minlength
=
None
):
self
.
minlength
=
minlength
self
.
minlength
=
minlength
if
minlength
is
not
None
:
numpy_ver
=
[
int
(
n
)
for
n
in
numpy
.
__version__
.
split
(
'.'
)[:
2
]]
if
not
bool
(
numpy_ver
>=
[
1
,
6
]):
raise
NotImplementedError
(
"BinCountOp with minlength attribute"
" need NumPy 1.6 or higher."
)
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
)
and
return
(
type
(
self
)
==
type
(
other
)
and
...
@@ -145,8 +151,11 @@ class BinCountOp(theano.Op):
...
@@ -145,8 +151,11 @@ class BinCountOp(theano.Op):
if
weights
is
not
None
and
weights
.
shape
!=
x
.
shape
:
if
weights
is
not
None
and
weights
.
shape
!=
x
.
shape
:
raise
TypeError
(
"All inputs must have the same shape."
)
raise
TypeError
(
"All inputs must have the same shape."
)
#Needed for numpy 1.4.1 compatibility
z
[
0
]
=
np
.
bincount
(
x
,
weights
=
weights
,
minlength
=
self
.
minlength
)
if
self
.
minlength
:
z
[
0
]
=
np
.
bincount
(
x
,
weights
=
weights
,
minlength
=
self
.
minlength
)
else
:
z
[
0
]
=
np
.
bincount
(
x
,
weights
=
weights
)
def
grad
(
self
,
inputs
,
outputs_gradients
):
def
grad
(
self
,
inputs
,
outputs_gradients
):
output
=
self
(
*
inputs
)
output
=
self
(
*
inputs
)
...
...
theano/tensor/tests/test_extra_ops.py
浏览文件 @
e0d06a4e
...
@@ -10,6 +10,9 @@ from theano import tensor as T
...
@@ -10,6 +10,9 @@ from theano import tensor as T
from
theano
import
config
,
tensor
,
function
from
theano
import
config
,
tensor
,
function
numpy_ver
=
[
int
(
n
)
for
n
in
numpy
.
__version__
.
split
(
'.'
)[:
2
]]
numpy_16
=
bool
(
numpy_ver
>=
[
1
,
6
])
class
TestBinCountOp
(
utt
.
InferShapeTester
):
class
TestBinCountOp
(
utt
.
InferShapeTester
):
def
setUp
(
self
):
def
setUp
(
self
):
super
(
TestBinCountOp
,
self
)
.
setUp
()
super
(
TestBinCountOp
,
self
)
.
setUp
()
...
@@ -39,12 +42,14 @@ class TestBinCountOp(utt.InferShapeTester):
...
@@ -39,12 +42,14 @@ class TestBinCountOp(utt.InferShapeTester):
f1
=
theano
.
function
([
x
],
bincount
(
x
))
f1
=
theano
.
function
([
x
],
bincount
(
x
))
f2
=
theano
.
function
([
x
,
w
],
bincount
(
x
,
weights
=
w
))
f2
=
theano
.
function
([
x
,
w
],
bincount
(
x
,
weights
=
w
))
f3
=
theano
.
function
([
x
],
bincount
(
x
,
minlength
=
23
))
f4
=
theano
.
function
([
x
],
bincount
(
x
,
minlength
=
5
))
assert
(
np
.
bincount
(
a
)
==
f1
(
a
))
.
all
()
assert
(
np
.
bincount
(
a
)
==
f1
(
a
))
.
all
()
assert
np
.
allclose
(
np
.
bincount
(
a
,
weights
=
weights
),
assert
np
.
allclose
(
np
.
bincount
(
a
,
weights
=
weights
),
f2
(
a
,
weights
))
f2
(
a
,
weights
))
if
not
numpy_16
:
continue
f3
=
theano
.
function
([
x
],
bincount
(
x
,
minlength
=
23
))
f4
=
theano
.
function
([
x
],
bincount
(
x
,
minlength
=
5
))
assert
(
np
.
bincount
(
a
,
minlength
=
23
)
==
f3
(
a
))
.
all
()
assert
(
np
.
bincount
(
a
,
minlength
=
23
)
==
f3
(
a
))
.
all
()
assert
(
np
.
bincount
(
a
,
minlength
=
5
)
==
f4
(
a
))
.
all
()
assert
(
np
.
bincount
(
a
,
minlength
=
5
)
==
f4
(
a
))
.
all
()
...
@@ -79,6 +84,8 @@ class TestBinCountOp(utt.InferShapeTester):
...
@@ -79,6 +84,8 @@ class TestBinCountOp(utt.InferShapeTester):
50
,
size
=
(
25
,))
.
astype
(
dtype
)],
50
,
size
=
(
25
,))
.
astype
(
dtype
)],
self
.
op_class
)
self
.
op_class
)
if
not
numpy_16
:
continue
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
x
],
[
x
],
[
bincount
(
x
,
minlength
=
60
)],
[
bincount
(
x
,
minlength
=
60
)],
...
...
theano/tensor/tests/test_sort.py
浏览文件 @
e0d06a4e
import
unittest
import
unittest
from
numpy.testing
import
assert_allclose
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
import
numpy
as
np
import
numpy
as
np
...
@@ -22,7 +21,7 @@ class test_sort(unittest.TestCase):
...
@@ -22,7 +21,7 @@ class test_sort(unittest.TestCase):
a
=
tensor
.
dmatrix
()
a
=
tensor
.
dmatrix
()
w
=
sort
(
a
)
w
=
sort
(
a
)
f
=
theano
.
function
([
a
],
w
)
f
=
theano
.
function
([
a
],
w
)
assert
_
allclose
(
f
(
self
.
m_val
),
np
.
sort
(
self
.
m_val
))
assert
np
.
allclose
(
f
(
self
.
m_val
),
np
.
sort
(
self
.
m_val
))
def
test2
(
self
):
def
test2
(
self
):
a
=
tensor
.
dmatrix
()
a
=
tensor
.
dmatrix
()
...
@@ -32,7 +31,7 @@ class test_sort(unittest.TestCase):
...
@@ -32,7 +31,7 @@ class test_sort(unittest.TestCase):
for
axis_val
in
0
,
1
:
for
axis_val
in
0
,
1
:
gv
=
f
(
self
.
m_val
,
axis_val
)
gv
=
f
(
self
.
m_val
,
axis_val
)
gt
=
np
.
sort
(
self
.
m_val
,
axis_val
)
gt
=
np
.
sort
(
self
.
m_val
,
axis_val
)
assert
_
allclose
(
gv
,
gt
)
assert
np
.
allclose
(
gv
,
gt
)
def
test3
(
self
):
def
test3
(
self
):
a
=
tensor
.
dvector
()
a
=
tensor
.
dvector
()
...
@@ -40,7 +39,7 @@ class test_sort(unittest.TestCase):
...
@@ -40,7 +39,7 @@ class test_sort(unittest.TestCase):
f
=
theano
.
function
([
a
],
w2
)
f
=
theano
.
function
([
a
],
w2
)
gv
=
f
(
self
.
v_val
)
gv
=
f
(
self
.
v_val
)
gt
=
np
.
sort
(
self
.
v_val
)
gt
=
np
.
sort
(
self
.
v_val
)
assert
_
allclose
(
gv
,
gt
)
assert
np
.
allclose
(
gv
,
gt
)
def
test4
(
self
):
def
test4
(
self
):
a
=
tensor
.
dmatrix
()
a
=
tensor
.
dmatrix
()
...
@@ -50,7 +49,7 @@ class test_sort(unittest.TestCase):
...
@@ -50,7 +49,7 @@ class test_sort(unittest.TestCase):
for
axis_val
in
0
,
1
:
for
axis_val
in
0
,
1
:
gv
=
f
(
self
.
m_val
,
axis_val
)
gv
=
f
(
self
.
m_val
,
axis_val
)
gt
=
np
.
sort
(
self
.
m_val
,
axis_val
)
gt
=
np
.
sort
(
self
.
m_val
,
axis_val
)
assert
_
allclose
(
gv
,
gt
)
assert
np
.
allclose
(
gv
,
gt
)
def
test5
(
self
):
def
test5
(
self
):
a1
=
SortOp
(
"mergesort"
,
[])
a1
=
SortOp
(
"mergesort"
,
[])
...
@@ -67,7 +66,7 @@ class test_sort(unittest.TestCase):
...
@@ -67,7 +66,7 @@ class test_sort(unittest.TestCase):
f
=
theano
.
function
([
a
],
l
)
f
=
theano
.
function
([
a
],
l
)
gv
=
f
(
self
.
m_val
)
gv
=
f
(
self
.
m_val
)
gt
=
np
.
sort
(
self
.
m_val
,
None
)
gt
=
np
.
sort
(
self
.
m_val
,
None
)
assert
_
allclose
(
gv
,
gt
)
assert
np
.
allclose
(
gv
,
gt
)
class
TensorInferShapeTester
(
utt
.
InferShapeTester
):
class
TensorInferShapeTester
(
utt
.
InferShapeTester
):
...
@@ -97,7 +96,7 @@ def test_argsort():
...
@@ -97,7 +96,7 @@ def test_argsort():
f
=
theano
.
function
([
a
],
w
)
f
=
theano
.
function
([
a
],
w
)
gv
=
f
(
m_val
)
gv
=
f
(
m_val
)
gt
=
np
.
argsort
(
m_val
)
gt
=
np
.
argsort
(
m_val
)
assert
_
allclose
(
gv
,
gt
)
assert
np
.
allclose
(
gv
,
gt
)
#Example 2
#Example 2
a
=
tensor
.
dmatrix
()
a
=
tensor
.
dmatrix
()
...
@@ -107,7 +106,7 @@ def test_argsort():
...
@@ -107,7 +106,7 @@ def test_argsort():
for
axis_val
in
0
,
1
:
for
axis_val
in
0
,
1
:
gv
=
f
(
m_val
,
axis_val
)
gv
=
f
(
m_val
,
axis_val
)
gt
=
np
.
argsort
(
m_val
,
axis_val
)
gt
=
np
.
argsort
(
m_val
,
axis_val
)
assert
_
allclose
(
gv
,
gt
)
assert
np
.
allclose
(
gv
,
gt
)
#Example 3
#Example 3
a
=
tensor
.
dvector
()
a
=
tensor
.
dvector
()
...
@@ -115,7 +114,7 @@ def test_argsort():
...
@@ -115,7 +114,7 @@ def test_argsort():
f
=
theano
.
function
([
a
],
w2
)
f
=
theano
.
function
([
a
],
w2
)
gv
=
f
(
v_val
)
gv
=
f
(
v_val
)
gt
=
np
.
argsort
(
v_val
)
gt
=
np
.
argsort
(
v_val
)
assert
_
allclose
(
gv
,
gt
)
assert
np
.
allclose
(
gv
,
gt
)
#Example 4
#Example 4
a
=
tensor
.
dmatrix
()
a
=
tensor
.
dmatrix
()
...
@@ -125,7 +124,7 @@ def test_argsort():
...
@@ -125,7 +124,7 @@ def test_argsort():
for
axis_val
in
0
,
1
:
for
axis_val
in
0
,
1
:
gv
=
f
(
m_val
,
axis_val
)
gv
=
f
(
m_val
,
axis_val
)
gt
=
np
.
argsort
(
m_val
,
axis_val
)
gt
=
np
.
argsort
(
m_val
,
axis_val
)
assert
_
allclose
(
gv
,
gt
)
assert
np
.
allclose
(
gv
,
gt
)
#Example 5
#Example 5
a
=
tensor
.
dmatrix
()
a
=
tensor
.
dmatrix
()
...
@@ -143,4 +142,4 @@ def test_argsort():
...
@@ -143,4 +142,4 @@ def test_argsort():
f
=
theano
.
function
([
a
],
w2
)
f
=
theano
.
function
([
a
],
w2
)
gv
=
f
(
m_val
)
gv
=
f
(
m_val
)
gt
=
np
.
argsort
(
m_val
,
None
)
gt
=
np
.
argsort
(
m_val
,
None
)
assert
_
allclose
(
gv
,
gt
)
assert
np
.
allclose
(
gv
,
gt
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论