Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d7fa47aa
提交
d7fa47aa
authored
11月 17, 2010
作者:
David Warde-Farley
浏览文件
操作
浏览文件
下载
差异文件
Merged with the last thing before Fred's updates which conflict.
上级
96d67acb
9264cf11
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
300 行增加
和
25 行删除
+300
-25
config.txt
doc/library/config.txt
+4
-4
argparse.py
theano/misc/hooks/argparse.py
+0
-0
check_whitespace.py
theano/misc/hooks/check_whitespace.py
+184
-0
reindent.py
theano/misc/hooks/reindent.py
+0
-0
cuda_ndarray.cu
theano/sandbox/cuda/cuda_ndarray.cu
+0
-0
test_basic_ops.py
theano/sandbox/cuda/tests/test_basic_ops.py
+4
-5
test_cuda_ndarray.py
theano/sandbox/cuda/tests/test_cuda_ndarray.py
+6
-1
test_randomstreams.py
theano/tensor/tests/test_randomstreams.py
+11
-7
test_shared_randomstreams.py
theano/tensor/tests/test_shared_randomstreams.py
+91
-8
没有找到文件。
doc/library/config.txt
浏览文件 @
d7fa47aa
...
...
@@ -34,7 +34,7 @@ theano.config. For example, to see a list of all active configuration
variables, type this from the command-line:
.. code-block:: bash
python -c 'import theano; print theano.config' | less
Environment Variables
...
...
@@ -52,7 +52,7 @@ Environment Variables
.. code-block:: bash
THEANO_FLAGS='floatX=float32,device=gpu0,nvcc.fastmath' python <myscript>.py
THEANO_FLAGS='floatX=float32,device=gpu0,nvcc.fastmath
=True
' python <myscript>.py
If a value is defined several times in ``THEANO_FLAGS``,
the right-most definition is used. So, for instance, if
...
...
@@ -86,7 +86,7 @@ that you might want to use. For the complete list (including documentation),
import theano and print the config variable, as in:
.. code-block:: bash
python -c 'import theano; print theano.config' | less
...
...
@@ -164,7 +164,7 @@ Config Attributes
This flag allows a new user not to get warnings about old bugs, that were fixed
before their first checkout of Theano.
You can set its value to the first version of Theano
You can set its value to the first version of Theano
that you used (probably 0.3 or higher)
`None` mean that all warnings will be displayed.
...
...
theano/misc/hooks/argparse.py
0 → 100644
浏览文件 @
d7fa47aa
差异被折叠。
点击展开。
theano/misc/hooks/check_whitespace.py
0 → 100755
浏览文件 @
d7fa47aa
#!/usr/bin/env python
__docformat__
=
'restructuredtext en'
import
difflib
import
operator
import
os
import
string
from
StringIO
import
StringIO
from
subprocess
import
Popen
,
PIPE
import
sys
import
tabnanny
import
tokenize
import
argparse
import
reindent
def
get_parse_error
(
code
):
"""
Checks code for ambiguous tabs or other basic parsing issues.
:param code: a string containing a file's worth of Python code
:returns: a string containing a description of the first parse error encountered,
or None if the code is ok
"""
# note that this uses non-public elements from stdlib's tabnanny, because tabnanny
# is (very frustratingly) written only to be used as a script, but using it that way
# in this context requires writing temporarily files, running subprocesses, blah blah blah
code_buffer
=
StringIO
(
code
)
try
:
tabnanny
.
process_tokens
(
tokenize
.
generate_tokens
(
code_buffer
.
readline
))
except
tokenize
.
TokenError
as
err
:
return
"Could not parse code: {err}"
.
format
(
err
=
err
)
except
IndentationError
as
err
:
return
"Indentation error: {err}"
.
format
(
err
=
err
)
except
tabnanny
.
NannyNag
as
err
:
return
"Ambiguous tab at line {line_number}; line is '{line}'."
.
format
(
line_number
=
err
.
get_lineno
(),
line
=
err
.
get_line
())
return
None
def
get_correct_indentation_diff
(
code
,
filename
):
"""
Generate a diff to make code correctly indented.
:param code: a string containing a file's worth of Python code
:param filename: the filename being considered (used in diff generation only)
:returns: a unified diff to make code correctly indented, or
None if code is already correctedly indented
"""
code_buffer
=
StringIO
(
code
)
output_buffer
=
StringIO
()
reindenter
=
reindent
.
Reindenter
(
code_buffer
)
reindenter
.
run
()
reindenter
.
write
(
output_buffer
)
reindent_output
=
output_buffer
.
getvalue
()
output_buffer
.
close
()
if
code
!=
reindent_output
:
diff_generator
=
difflib
.
unified_diff
(
code
.
splitlines
(
True
),
reindent_output
.
splitlines
(
True
),
fromfile
=
filename
,
tofile
=
filename
+
" (reindented)"
)
# work around http://bugs.python.org/issue2142
diff_tuple
=
[
diff_line
if
diff_line
.
endswith
(
"
\n
"
)
else
diff_line
+
"
\n\\
No newline at end of file
\n
"
for
diff_line
in
diff_generator
]
diff
=
""
.
join
(
diff_tuple
)
return
diff
else
:
return
None
def
is_merge
():
parent2
=
os
.
environ
.
get
(
"HG_PARENT2"
,
None
)
return
parent2
is
not
None
and
len
(
parent2
)
>
0
def
parent_commit
():
parent1
=
os
.
environ
.
get
(
"HG_PARENT1"
,
None
)
return
parent1
class
MercurialRuntimeError
(
Exception
):
pass
def
run_mercurial_command
(
hg_command
):
hg_subprocess
=
Popen
(
hg_command
.
split
(),
stdout
=
PIPE
,
stderr
=
PIPE
)
hg_out
,
hg_err
=
hg_subprocess
.
communicate
()
if
len
(
hg_err
)
>
0
:
raise
MercurialRuntimeError
(
hg_err
)
return
hg_out
def
parse_stdout_filelist
(
hg_out_filelist
):
files
=
hg_out_filelist
.
split
()
files
=
[
f
.
strip
(
string
.
whitespace
+
"'"
)
for
f
in
files
]
files
=
filter
(
operator
.
truth
,
files
)
# get rid of empty entries
return
files
def
changed_files
():
hg_out
=
run_mercurial_command
(
"hg tip --template '{file_mods}'"
)
return
parse_stdout_filelist
(
hg_out
)
def
added_files
():
hg_out
=
run_mercurial_command
(
"hg tip --template '{file_adds}'"
)
return
parse_stdout_filelist
(
hg_out
)
def
is_python_file
(
filename
):
return
filename
.
endswith
(
".py"
)
def
get_file_contents
(
filename
,
revision
=
"tip"
):
hg_out
=
run_mercurial_command
(
"hg cat -r {revision} {filename}"
.
format
(
filename
=
filename
,
revision
=
revision
))
return
hg_out
def
save_commit_message
(
filename
):
commit_message
=
run_mercurial_command
(
"hg tip --template '{desc}'"
)
with
open
(
filename
,
"w"
)
as
save_file
:
save_file
.
write
(
commit_message
)
def
save_diffs
(
diffs
,
filename
):
diff
=
"
\n\n
"
.
join
(
diffs
)
with
open
(
filename
,
"w"
)
as
diff_file
:
diff_file
.
write
(
diff
)
def
main
(
argv
=
None
):
if
argv
is
None
:
argv
=
sys
.
argv
[
1
:]
parser
=
argparse
.
ArgumentParser
(
description
=
"Pretxncommit hook for Mercurial to check for whitespace issues"
)
parser
.
add_argument
(
"-n"
,
"--no-indentation"
,
action
=
"store_const"
,
default
=
False
,
const
=
True
,
help
=
"don't check indentation, just basic parsing"
)
parser
.
add_argument
(
"-i"
,
"--incremental"
,
action
=
"store_const"
,
default
=
False
,
const
=
True
,
help
=
"only check indentation if the file was previously correctly indented (or is new)"
)
args
=
parser
.
parse_args
(
argv
)
if
is_merge
():
# don't inspect merges: (a) they're complex and (b) they don't really introduce new code
return
0
block_commit
=
False
diffs
=
[]
added_filenames
=
added_files
()
changed_filenames
=
changed_files
()
for
filename
in
filter
(
is_python_file
,
added_filenames
+
changed_filenames
):
code
=
get_file_contents
(
filename
)
parse_error
=
get_parse_error
(
code
)
if
parse_error
is
not
None
:
print
>>
sys
.
stderr
,
"*** {filename} has parse error: {err}"
.
format
(
filename
=
filename
,
err
=
parse_error
)
block_commit
=
True
else
:
# parsing succeeded, it is safe to check indentation
if
not
args
.
no_indentation
:
if
args
.
incremental
and
filename
in
changed_filenames
:
# only check it if it was clean before
old_file_contents
=
get_file_contents
(
filename
,
revision
=
parent_commit
())
check_indentation
=
get_correct_indentation_diff
(
old_file_contents
,
""
)
is
None
else
:
check_indentation
=
True
if
check_indentation
:
indentation_diff
=
get_correct_indentation_diff
(
code
,
filename
)
if
indentation_diff
is
not
None
:
block_commit
=
True
diffs
.
append
(
indentation_diff
)
print
>>
sys
.
stderr
,
"{filename} is not correctly indented"
.
format
(
filename
=
filename
)
if
len
(
diffs
)
>
0
:
diffs_filename
=
".hg/indentation_fixes.patch"
save_diffs
(
diffs
,
diffs_filename
)
print
>>
sys
.
stderr
,
"*** To fix all indentation issues, run: cd `hg root` && patch -p0 < {filename}"
.
format
(
filename
=
diffs_filename
)
if
block_commit
:
save_filename
=
".hg/commit_message.saved"
save_commit_message
(
save_filename
)
print
>>
sys
.
stderr
,
"*** Commit message saved to {filename}"
.
format
(
filename
=
save_filename
)
return
int
(
block_commit
)
if
__name__
==
'__main__'
:
sys
.
exit
(
main
())
theano/misc/hooks/reindent.py
0 → 100755
浏览文件 @
d7fa47aa
差异被折叠。
点击展开。
theano/sandbox/cuda/cuda_ndarray.cu
浏览文件 @
d7fa47aa
差异被折叠。
点击展开。
theano/sandbox/cuda/tests/test_basic_ops.py
浏览文件 @
d7fa47aa
import
sys
,
time
from
theano
import
shared
from
theano.compile.pfunc
import
pfunc
from
theano
import
tensor
...
...
@@ -17,7 +16,7 @@ if cuda_ndarray.cuda_available == False:
import
theano.sandbox.cuda
as
tcn
import
theano.sandbox.cuda
as
cuda
import
theano.sandbox.cuda.basic_ops
as
B
import
theano.compile.mod
e
from
theano.tensor.basic
import
_allclos
e
from
theano.tests
import
unittest_tools
as
utt
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
...
...
@@ -98,7 +97,7 @@ def test_sum():
if
val
.
size
==
0
:
assert
f2
(
val
)
==
f
(
val
),
(
'shape'
,
shape
,
'pattern'
,
pattern
)
else
:
assert
numpy
.
allclose
(
f2
(
val
),
f
(
val
)),
(
'shape'
,
shape
,
'pattern'
,
pattern
)
assert
_allclose
(
f2
(
val
),
f
(
val
)),
(
'shape'
,
shape
,
'pattern'
,
pattern
,
sum
([
shape
[
i
]
for
i
in
pattern
])
)
#test with dimshuffle
...
...
@@ -121,7 +120,7 @@ def test_sum():
f2
=
theano
.
function
([
a
],
b
,
mode
=
mode_without_gpu
)
assert
tcn
.
GpuSum
in
[
x
.
op
.
__class__
for
x
in
f
.
maker
.
env
.
toposort
()]
assert
T
.
Sum
in
[
x
.
op
.
__class__
for
x
in
f2
.
maker
.
env
.
toposort
()]
assert
numpy
.
allclose
(
f2
(
val
),
f
(
val
))
assert
_allclose
(
f2
(
val
),
f
(
val
)),
(
'shape'
,
shape
,
'pattern'
,
pattern
,
sum
([
shape
[
i
]
for
i
in
pattern
]
))
#test with broadcast
...
...
@@ -155,7 +154,7 @@ def test_sum():
f2
=
theano
.
function
([
a2
],
b2
,
mode
=
mode_with_gpu
)
assert
tcn
.
GpuSum
in
[
x
.
op
.
__class__
for
x
in
f2
.
maker
.
env
.
toposort
()]
assert
T
.
Sum
in
[
x
.
op
.
__class__
for
x
in
f
.
maker
.
env
.
toposort
()]
assert
numpy
.
allclose
(
f2
(
val2
),
f
(
val
))
assert
_allclose
(
f2
(
val2
),
f
(
val
)),
(
'shape'
,
shape
,
'pattern'
,
pattern
,
sum
([
shape
[
i
]
for
i
in
pattern
]
))
def
test_flatten
():
x
=
cuda
.
fmatrix
(
'x'
)
...
...
theano/sandbox/cuda/tests/test_cuda_ndarray.py
浏览文件 @
d7fa47aa
...
...
@@ -15,7 +15,7 @@ def test_host_to_device():
c
=
numpy
.
asarray
(
b
)
assert
numpy
.
all
(
a
==
c
)
def
test_add
():
def
test_add
_iadd_idiv
():
for
shape
in
((),
(
0
,),
(
3
,),
(
2
,
3
),
(
1
,
10000000
),(
10
,
1000000
),
(
100
,
100000
),
(
1000
,
10000
),(
10000
,
1000
),
(
4100
,
33
,
34
),(
33
,
4100
,
34
),(
33
,
34
,
4100
),
...
...
@@ -51,6 +51,11 @@ def test_add():
assert
numpy
.
allclose
(
a0
,
numpy
.
asarray
(
b0
))
assert
numpy
.
allclose
(
a0
,
a1
*
2
)
b0
/=
b1
a0
/=
a1
assert
numpy
.
allclose
(
a0
,
numpy
.
asarray
(
b0
))
assert
numpy
.
allclose
(
a0
,
numpy
.
ones
(
a0
.
shape
)
*
2
)
if
len
(
shape
)
==
2
:
#test not contiguous version.
#should raise not implemented.
...
...
theano/tensor/tests/test_randomstreams.py
浏览文件 @
d7fa47aa
...
...
@@ -367,18 +367,22 @@ class T_RandomStreams(unittest.TestCase):
made
=
m
.
make
()
made
.
random
.
initialize
()
rng_seed
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
.
randint
(
2
**
30
)
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#seed_rng is generator for generating *seeds* for RandomStates
seed_rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
uniform_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_rng
.
randint
(
2
**
30
)))
multinomial_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_rng
.
randint
(
2
**
30
)))
val0
=
made
.
f
()
val1
=
made
.
f
()
numpy_val0
=
numpy
_rng
.
uniform
()
numpy_val1
=
numpy
_rng
.
uniform
()
numpy_val0
=
uniform
_rng
.
uniform
()
numpy_val1
=
uniform
_rng
.
uniform
()
assert
numpy
.
allclose
(
val0
,
numpy_val0
)
assert
numpy
.
allclose
(
val1
,
numpy_val1
)
val2
=
made
.
g
()
numpy_val2
=
numpy_rng
.
multinomial
(
n
=
1
,
pvals
=
[
.
5
,
.
5
])
assert
numpy
.
all
(
val2
==
numpy_val2
)
for
i
in
range
(
10
):
# every test has 50% chance of passing even with non-matching random states
val2
=
made
.
g
()
numpy_val2
=
multinomial_rng
.
multinomial
(
n
=
1
,
pvals
=
[
.
5
,
.
5
])
assert
numpy
.
all
(
val2
==
numpy_val2
)
def
test_vector_arguments
(
self
):
m
=
Module
()
...
...
theano/tensor/tests/test_shared_randomstreams.py
浏览文件 @
d7fa47aa
...
...
@@ -6,7 +6,7 @@ import numpy
from
theano.tensor
import
raw_random
from
theano.tensor.shared_randomstreams
import
RandomStreams
from
theano
import
function
from
theano
import
function
,
shared
from
theano
import
tensor
from
theano
import
compile
,
config
,
gof
...
...
@@ -336,19 +336,23 @@ class T_SharedRandomStreams(unittest.TestCase):
random
=
RandomStreams
(
utt
.
fetch_seed
())
f
=
function
([],
random
.
uniform
())
g
=
function
([],
random
.
multinomial
())
rng_seed
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
.
randint
(
2
**
30
)
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
#seed_rng is generator for generating *seeds* for RandomStates
seed_rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
uniform_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_rng
.
randint
(
2
**
30
)))
multinomial_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_rng
.
randint
(
2
**
30
)))
val0
=
f
()
val1
=
f
()
numpy_val0
=
numpy
_rng
.
uniform
()
numpy_val1
=
numpy
_rng
.
uniform
()
numpy_val0
=
uniform
_rng
.
uniform
()
numpy_val1
=
uniform
_rng
.
uniform
()
assert
numpy
.
allclose
(
val0
,
numpy_val0
)
assert
numpy
.
allclose
(
val1
,
numpy_val1
)
val2
=
g
()
numpy_val2
=
numpy_rng
.
multinomial
(
n
=
1
,
pvals
=
[
.
5
,
.
5
])
assert
numpy
.
all
(
val2
==
numpy_val2
)
for
i
in
range
(
10
):
# every test has 50% chance of passing even with non-matching random states
val2
=
g
()
numpy_val2
=
multinomial_rng
.
multinomial
(
n
=
1
,
pvals
=
[
.
5
,
.
5
])
assert
numpy
.
all
(
val2
==
numpy_val2
)
def
test_vector_arguments
(
self
):
random
=
RandomStreams
(
utt
.
fetch_seed
())
...
...
@@ -607,6 +611,85 @@ class T_SharedRandomStreams(unittest.TestCase):
assert
numpy
.
all
(
abs
(
val1
)
<=
1
)
def
test_shared_constructor_borrow
(
self
):
rng
=
numpy
.
random
.
RandomState
(
123
)
s_rng_default
=
shared
(
rng
)
s_rng_True
=
shared
(
rng
,
borrow
=
True
)
s_rng_False
=
shared
(
rng
,
borrow
=
False
)
# test borrow contract: that False means a copy must have been made
assert
s_rng_default
.
container
.
storage
[
0
]
is
not
rng
assert
s_rng_False
.
container
.
storage
[
0
]
is
not
rng
# test current implementation: that True means a copy was not made
assert
s_rng_True
.
container
.
storage
[
0
]
is
rng
# ensure that all the random number generators are in the same state
v
=
rng
.
randn
()
v0
=
s_rng_default
.
container
.
storage
[
0
]
.
randn
()
v1
=
s_rng_False
.
container
.
storage
[
0
]
.
randn
()
assert
v
==
v0
==
v1
def
test_get_value_borrow
(
self
):
rng
=
numpy
.
random
.
RandomState
(
123
)
s_rng
=
shared
(
rng
)
r_
=
s_rng
.
container
.
storage
[
0
]
r_T
=
s_rng
.
get_value
(
borrow
=
True
)
r_F
=
s_rng
.
get_value
(
borrow
=
False
)
#the contract requires that borrow=False returns a copy
assert
r_
is
not
r_F
# the current implementation allows for True to return the real thing
assert
r_
is
r_T
#either way, the rngs should all be in the same state
assert
r_
.
rand
()
==
r_F
.
rand
()
def
test_get_value_internal_type
(
self
):
rng
=
numpy
.
random
.
RandomState
(
123
)
s_rng
=
shared
(
rng
)
# there is no special behaviour required of return_internal_type
# this test just ensures that the flag doesn't screw anything up
# by repeating the get_value_borrow test.
r_
=
s_rng
.
container
.
storage
[
0
]
r_T
=
s_rng
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
r_F
=
s_rng
.
get_value
(
borrow
=
False
,
return_internal_type
=
True
)
#the contract requires that borrow=False returns a copy
assert
r_
is
not
r_F
# the current implementation allows for True to return the real thing
assert
r_
is
r_T
#either way, the rngs should all be in the same state
assert
r_
.
rand
()
==
r_F
.
rand
()
def
test_set_value_borrow
(
self
):
rng
=
numpy
.
random
.
RandomState
(
123
)
s_rng
=
shared
(
rng
)
new_rng
=
numpy
.
random
.
RandomState
(
234234
)
# Test the borrow contract is respected:
# assigning with borrow=False makes a copy
s_rng
.
set_value
(
new_rng
,
borrow
=
False
)
assert
new_rng
is
not
s_rng
.
container
.
storage
[
0
]
assert
new_rng
.
randn
()
==
s_rng
.
container
.
storage
[
0
]
.
randn
()
# Test that the current implementation is actually borrowing when it can.
rr
=
numpy
.
random
.
RandomState
(
33
)
s_rng
.
set_value
(
rr
,
borrow
=
True
)
assert
rr
is
s_rng
.
container
.
storage
[
0
]
if
__name__
==
'__main__'
:
from
theano.tests
import
main
main
(
"test_shared_randomstreams"
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论