Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5f08dd27
提交
5f08dd27
authored
5月 15, 2013
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1377 from nouiz/fix_cho_test
Make test more resistent to different seed value.
上级
6a231fea
1a8eb6dd
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
96 行增加
和
80 行删除
+96
-80
test_linalg.py
theano/sandbox/linalg/tests/test_linalg.py
+8
-3
blas.py
theano/tensor/blas.py
+88
-77
没有找到文件。
theano/sandbox/linalg/tests/test_linalg.py
浏览文件 @
5f08dd27
...
...
@@ -78,12 +78,17 @@ def test_cholesky_grad():
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
r
=
rng
.
randn
(
5
,
5
)
.
astype
(
config
.
floatX
)
pd
=
numpy
.
dot
(
r
,
r
.
T
)
eps
=
None
if
config
.
floatX
==
"float64"
:
eps
=
2e-8
# Check the default.
yield
utt
.
verify_grad
,
cholesky
,
[
pd
],
3
,
rng
yield
(
lambda
:
utt
.
verify_grad
(
cholesky
,
[
pd
],
3
,
rng
,
eps
=
eps
))
# Explicit lower-triangular.
yield
utt
.
verify_grad
,
Cholesky
(
lower
=
True
),
[
pd
],
3
,
rng
yield
(
lambda
:
utt
.
verify_grad
(
Cholesky
(
lower
=
True
),
[
pd
],
3
,
rng
,
eps
=
eps
))
# Explicit upper-triangular.
yield
utt
.
verify_grad
,
Cholesky
(
lower
=
False
),
[
pd
],
3
,
rng
yield
(
lambda
:
utt
.
verify_grad
(
Cholesky
(
lower
=
False
),
[
pd
],
3
,
rng
,
eps
=
eps
))
def
test_cholesky_and_cholesky_grad_shape
():
...
...
theano/tensor/blas.py
浏览文件 @
5f08dd27
...
...
@@ -151,6 +151,84 @@ from theano.tensor.opt import local_dimshuffle_lift
_logger
=
logging
.
getLogger
(
'theano.tensor.blas'
)
# We need to define blas.ldflag before we try to import scipy.
# Otherwise, we give an optimization warning for no reason in some cases.
def
default_blas_ldflags
():
try
:
# If we are in a EPD installation, mkl is available
blas_info
=
numpy
.
distutils
.
__config__
.
blas_opt_info
if
"EPD"
in
sys
.
version
:
use_unix_epd
=
True
if
sys
.
platform
==
'win32'
:
return
' '
.
join
(
[
'-L
%
s'
%
os
.
path
.
join
(
sys
.
prefix
,
"Scripts"
)]
+
# Why on Windows, the library used are not the
# same as what is in
# blas_info['libraries']?
[
'-l
%
s'
%
l
for
l
in
[
"mk2_core"
,
"mk2_intel_thread"
,
"mk2_rt"
]])
elif
sys
.
platform
==
'darwin'
:
# The env variable is needed to link with mkl
new_path
=
os
.
path
.
join
(
sys
.
prefix
,
"lib"
)
v
=
os
.
getenv
(
"DYLD_FALLBACK_LIBRARY_PATH"
,
None
)
if
v
is
not
None
:
# Explicit version could be replaced by a symbolic
# link called 'Current' created by EPD installer
# This will resolve symbolic links
v
=
os
.
path
.
realpath
(
v
)
# The python __import__ don't seam to take into account
# the new env variable "DYLD_FALLBACK_LIBRARY_PATH"
# when we set with os.environ['...'] = X or os.putenv()
# So we warn the user and tell him what todo.
if
v
is
None
or
new_path
not
in
v
.
split
(
":"
):
_logger
.
warning
(
"The environment variable "
"'DYLD_FALLBACK_LIBRARY_PATH' does not contain "
"the '
%
s' path in its value. This will make "
"Theano use a slow version of BLAS. Update "
"'DYLD_FALLBACK_LIBRARY_PATH' to contain the "
"said value, this will disable this warning."
%
new_path
)
use_unix_epd
=
False
if
use_unix_epd
:
return
' '
.
join
(
[
'-L
%
s'
%
os
.
path
.
join
(
sys
.
prefix
,
"lib"
)]
+
[
'-l
%
s'
%
l
for
l
in
blas_info
[
'libraries'
]])
#if numpy was linked with library that are not installed, we
#can't reuse them.
if
any
(
os
.
path
.
exists
(
dir
)
for
dir
in
blas_info
[
'library_dirs'
]):
return
' '
.
join
(
#TODO: the Gemm op below should separate the
# -L and -l arguments into the two callbacks
# that CLinker uses for that stuff. for now,
# we just pass the whole ldflags as the -l
# options part.
[
'-L
%
s'
%
l
for
l
in
blas_info
[
'library_dirs'
]]
+
[
'-l
%
s'
%
l
for
l
in
blas_info
[
'libraries'
]]
+
[])
# ['-I%s' % l for l in blas_info['include_dirs']])
except
KeyError
:
pass
# Even if we could not detect what was used for numpy, or if these
# libraries are not found, most Linux systems have a libblas.so
# readily available. We try to see if that's the case, rather
# than disable blas.
if
GCC_compiler
.
try_flags
([
"-lblas"
]):
return
"-lblas"
else
:
return
""
AddConfigVar
(
'blas.ldflags'
,
"lib[s] to include for [Fortran] level-3 blas implementation"
,
StrParam
(
default_blas_ldflags
))
try
:
import
scipy.linalg.blas
have_fblas
=
True
...
...
@@ -169,8 +247,16 @@ try:
}
except
ImportError
,
e
:
have_fblas
=
False
_logger
.
warning
(
'Failed to import scipy.linalg.blas. '
'Falling back on slower implementations (
%
s)'
,
str
(
e
))
# This is used in Gemv and ScipyGer. We use CGemv and CGer
# when theano.config.blas.ldflags is defined. So we don't need a
# warning in that case.
if
not
config
.
blas
.
ldflags
:
_logger
.
warning
(
'Failed to import scipy.linalg.blas and '
'Theano flag blas.ldflags empty. '
'Falling back on slower implementations for '
'dot(matrix, vector), dot(vector, matrix) and '
'dot(vector, vector) (
%
s)'
,
str
(
e
))
class
Gemv
(
Op
):
...
...
@@ -330,81 +416,6 @@ ger = Ger(destructive=False)
ger_destructive
=
Ger
(
destructive
=
True
)
def
default_blas_ldflags
():
try
:
# If we are in a EPD installation, mkl is available
blas_info
=
numpy
.
distutils
.
__config__
.
blas_opt_info
if
"EPD"
in
sys
.
version
:
use_unix_epd
=
True
if
sys
.
platform
==
'win32'
:
return
' '
.
join
(
[
'-L
%
s'
%
os
.
path
.
join
(
sys
.
prefix
,
"Scripts"
)]
+
# Why on Windows, the library used are not the
# same as what is in
# blas_info['libraries']?
[
'-l
%
s'
%
l
for
l
in
[
"mk2_core"
,
"mk2_intel_thread"
,
"mk2_rt"
]])
elif
sys
.
platform
==
'darwin'
:
# The env variable is needed to link with mkl
new_path
=
os
.
path
.
join
(
sys
.
prefix
,
"lib"
)
v
=
os
.
getenv
(
"DYLD_FALLBACK_LIBRARY_PATH"
,
None
)
if
v
is
not
None
:
# Explicit version could be replaced by a symbolic
# link called 'Current' created by EPD installer
# This will resolve symbolic links
v
=
os
.
path
.
realpath
(
v
)
# The python __import__ don't seam to take into account
# the new env variable "DYLD_FALLBACK_LIBRARY_PATH"
# when we set with os.environ['...'] = X or os.putenv()
# So we warn the user and tell him what todo.
if
v
is
None
or
new_path
not
in
v
.
split
(
":"
):
_logger
.
warning
(
"The environment variable "
"'DYLD_FALLBACK_LIBRARY_PATH' does not contain "
"the '
%
s' path in its value. This will make "
"Theano use a slow version of BLAS. Update "
"'DYLD_FALLBACK_LIBRARY_PATH' to contain the "
"said value, this will disable this warning."
%
new_path
)
use_unix_epd
=
False
if
use_unix_epd
:
return
' '
.
join
(
[
'-L
%
s'
%
os
.
path
.
join
(
sys
.
prefix
,
"lib"
)]
+
[
'-l
%
s'
%
l
for
l
in
blas_info
[
'libraries'
]])
#if numpy was linked with library that are not installed, we
#can't reuse them.
if
any
(
os
.
path
.
exists
(
dir
)
for
dir
in
blas_info
[
'library_dirs'
]):
return
' '
.
join
(
#TODO: the Gemm op below should separate the
# -L and -l arguments into the two callbacks
# that CLinker uses for that stuff. for now,
# we just pass the whole ldflags as the -l
# options part.
[
'-L
%
s'
%
l
for
l
in
blas_info
[
'library_dirs'
]]
+
[
'-l
%
s'
%
l
for
l
in
blas_info
[
'libraries'
]]
+
[])
# ['-I%s' % l for l in blas_info['include_dirs']])
except
KeyError
:
pass
# Even if we could not detect what was used for numpy, or if these
# libraries are not found, most Linux systems have a libblas.so
# readily available. We try to see if that's the case, rather
# than disable blas.
if
GCC_compiler
.
try_flags
([
"-lblas"
]):
return
"-lblas"
else
:
return
""
AddConfigVar
(
'blas.ldflags'
,
"lib[s] to include for [Fortran] level-3 blas implementation"
,
StrParam
(
default_blas_ldflags
))
@utils.memoize
def
ldflags
(
libs
=
True
,
flags
=
False
,
libs_dir
=
False
,
include_dir
=
False
):
"""Return a list of libraries against which an Op's object file should be
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论