Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
91935a04
提交
91935a04
authored
9月 16, 2011
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #45 from nouiz/mixed_commit
Mixed commit
上级
c0fd55c9
9637468f
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
75 行增加
和
27 行删除
+75
-27
cuda_ndarray.cu
theano/sandbox/cuda/cuda_ndarray.cu
+10
-0
cuda_ndarray.cuh
theano/sandbox/cuda/cuda_ndarray.cuh
+4
-0
test_cuda_ndarray.py
theano/sandbox/cuda/tests/test_cuda_ndarray.py
+5
-0
basic.py
theano/tensor/basic.py
+5
-1
test_basic.py
theano/tensor/tests/test_basic.py
+51
-26
没有找到文件。
theano/sandbox/cuda/cuda_ndarray.cu
浏览文件 @
91935a04
...
@@ -593,6 +593,12 @@ __global__ void k_copy_reshape_rowmajor(unsigned int numEls,
...
@@ -593,6 +593,12 @@ __global__ void k_copy_reshape_rowmajor(unsigned int numEls,
z_i
[
0
]
=
a_i
[
0
];
//copy one lousy float!
z_i
[
0
]
=
a_i
[
0
];
//copy one lousy float!
}
}
}
}
// Reshape self to the new shape gived by the tuple shape.
//
// If self is c contiguous, it return a view. Otherwise it always do a copy.
// TODO: make it return a view when the strides allow it event if it is not
// c contiguous
PyObject
*
CudaNdarray_Reshape
(
CudaNdarray
*
self
,
PyObject
*
shape
)
PyObject
*
CudaNdarray_Reshape
(
CudaNdarray
*
self
,
PyObject
*
shape
)
{
{
// check shape tuple
// check shape tuple
...
@@ -717,6 +723,7 @@ PyObject * CudaNdarray_View(CudaNdarray * self)
...
@@ -717,6 +723,7 @@ PyObject * CudaNdarray_View(CudaNdarray * self)
}
}
return
(
PyObject
*
)
rval
;
return
(
PyObject
*
)
rval
;
}
}
PyObject
*
CudaNdarray_SetStride
(
CudaNdarray
*
self
,
PyObject
*
args
)
PyObject
*
CudaNdarray_SetStride
(
CudaNdarray
*
self
,
PyObject
*
args
)
{
{
int
pos
,
stride
;
int
pos
,
stride
;
...
@@ -803,6 +810,9 @@ static PyMethodDef CudaNdarray_methods[] =
...
@@ -803,6 +810,9 @@ static PyMethodDef CudaNdarray_methods[] =
{
"copy"
,
{
"copy"
,
(
PyCFunction
)
CudaNdarray_Copy
,
METH_NOARGS
,
(
PyCFunction
)
CudaNdarray_Copy
,
METH_NOARGS
,
"Create a copy of this object"
},
"Create a copy of this object"
},
{
"is_c_contiguous"
,
(
PyCFunction
)
CudaNdarray_IS_C_Contiguous
,
METH_NOARGS
,
"Return True is the object is c contiguous. False otherwise."
},
{
"reduce_sum"
,
{
"reduce_sum"
,
(
PyCFunction
)
CudaNdarray_ReduceSum
,
METH_O
,
(
PyCFunction
)
CudaNdarray_ReduceSum
,
METH_O
,
"Reduce over the given dimensions by summation"
},
"Reduce over the given dimensions by summation"
},
...
...
theano/sandbox/cuda/cuda_ndarray.cuh
浏览文件 @
91935a04
...
@@ -504,6 +504,10 @@ CudaNdarray_ZEROS(int n, int * dims);
...
@@ -504,6 +504,10 @@ CudaNdarray_ZEROS(int n, int * dims);
* True iff the strides look like [dim[nd-2], dim[nd-3], ... , dim[0], 1]
* True iff the strides look like [dim[nd-2], dim[nd-3], ... , dim[0], 1]
*/
*/
bool
CudaNdarray_is_c_contiguous
(
const
CudaNdarray
*
self
);
bool
CudaNdarray_is_c_contiguous
(
const
CudaNdarray
*
self
);
PyObject
*
CudaNdarray_IS_C_Contiguous
(
CudaNdarray
*
self
)
{
return
PyBool_FromLong
(
CudaNdarray_is_c_contiguous
(
self
));
}
int
CudaNdarray_gemm
(
float
alpha
,
const
CudaNdarray
*
A
,
const
CudaNdarray
*
B
,
float
beta
,
CudaNdarray
*
C
);
int
CudaNdarray_gemm
(
float
alpha
,
const
CudaNdarray
*
A
,
const
CudaNdarray
*
B
,
float
beta
,
CudaNdarray
*
C
);
int
CudaNdarray_sger
(
float
alpha
,
CudaNdarray
*
x
,
CudaNdarray
*
y
,
CudaNdarray
*
A
);
int
CudaNdarray_sger
(
float
alpha
,
CudaNdarray
*
x
,
CudaNdarray
*
y
,
CudaNdarray
*
A
);
...
...
theano/sandbox/cuda/tests/test_cuda_ndarray.py
浏览文件 @
91935a04
...
@@ -909,6 +909,11 @@ def test_base():
...
@@ -909,6 +909,11 @@ def test_base():
e
=
b
.
reshape
((
5
,
2
,
2
,
3
))
e
=
b
.
reshape
((
5
,
2
,
2
,
3
))
assert
e
.
base
is
a
assert
e
.
base
is
a
def
test_is_c_contiguous
():
a
=
cuda_ndarray
.
CudaNdarray
.
zeros
((
3
,
4
,
5
))
assert
a
.
is_c_contiguous
()
assert
a
[
1
]
.
is_c_contiguous
()
assert
not
a
[::
2
]
.
is_c_contiguous
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
test_zeros_basic_3d_tensor
()
test_zeros_basic_3d_tensor
()
...
...
theano/tensor/basic.py
浏览文件 @
91935a04
...
@@ -4880,7 +4880,11 @@ class AdvancedSubtensor1(Op):
...
@@ -4880,7 +4880,11 @@ class AdvancedSubtensor1(Op):
x
,
i
=
inp
x
,
i
=
inp
out
,
=
out_
out
,
=
out_
# Copy always implied by numpy advanced indexing semantic.
# Copy always implied by numpy advanced indexing semantic.
out
[
0
]
=
x
[
i
]
if
out
[
0
]
is
not
None
and
out
[
0
]
.
shape
==
(
len
(
i
),)
+
x
.
shape
[
1
:]:
o
=
out
[
0
]
else
:
o
=
None
out
[
0
]
=
x
.
take
(
i
,
axis
=
0
,
out
=
o
)
def
grad
(
self
,
inputs
,
grads
):
def
grad
(
self
,
inputs
,
grads
):
gz
,
=
grads
gz
,
=
grads
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
91935a04
...
@@ -1809,6 +1809,8 @@ class T_subtensor(unittest.TestCase):
...
@@ -1809,6 +1809,8 @@ class T_subtensor(unittest.TestCase):
self
.
inc_sub
=
inc_sub
self
.
inc_sub
=
inc_sub
self
.
adv_sub1
=
adv_sub1
self
.
adv_sub1
=
adv_sub1
self
.
adv_incsub1
=
adv_incsub1
self
.
adv_incsub1
=
adv_incsub1
if
mode
is
None
:
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
self
.
mode
=
mode
self
.
mode
=
mode
self
.
dtype
=
dtype
self
.
dtype
=
dtype
self
.
ignore_topo
=
ignore_topo
self
.
ignore_topo
=
ignore_topo
...
@@ -1885,16 +1887,18 @@ class T_subtensor(unittest.TestCase):
...
@@ -1885,16 +1887,18 @@ class T_subtensor(unittest.TestCase):
def
test2_ok_range_finite
(
self
):
def
test2_ok_range_finite
(
self
):
n
=
self
.
shared
(
numpy
.
ones
((
3
,
4
),
dtype
=
self
.
dtype
)
*
5
)
n
=
self
.
shared
(
numpy
.
ones
((
3
,
4
),
dtype
=
self
.
dtype
)
*
5
)
t
=
n
[
0
:
2
,
3
]
# Also check negative index
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
Subtensor
))
for
idx
in
[(
slice
(
0
,
2
),
3
),((
slice
(
0
,
2
),
-
1
)),(
slice
(
0
,
2
),
-
4
)]:
f
=
inplace_func
([],
t
,
mode
=
self
.
mode
)
t
=
n
[
idx
]
#l]#0:2,3]
topo
=
f
.
maker
.
env
.
toposort
()
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
Subtensor
))
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
self
.
ignore_topo
)]
f
=
inplace_func
([],
t
,
mode
=
self
.
mode
)
assert
len
(
topo_
)
==
1
topo
=
f
.
maker
.
env
.
toposort
()
assert
isinstance
(
topo_
[
0
]
.
op
,
self
.
sub
)
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
self
.
ignore_topo
)]
tval
=
f
()
assert
len
(
topo_
)
==
1
self
.
assertTrue
(
tval
.
shape
==
(
2
,))
assert
isinstance
(
topo_
[
0
]
.
op
,
self
.
sub
)
self
.
assertTrue
(
tval
[
1
]
==
5.0
)
tval
=
f
()
self
.
assertTrue
(
tval
.
shape
==
(
2
,))
self
.
assertTrue
(
numpy
.
allclose
(
tval
,
n
.
get_value
()[
idx
]))
def
test1_err_invalid
(
self
):
def
test1_err_invalid
(
self
):
n
=
self
.
shared
(
numpy
.
ones
(
1
,
dtype
=
self
.
dtype
))
n
=
self
.
shared
(
numpy
.
ones
(
1
,
dtype
=
self
.
dtype
))
...
@@ -1946,20 +1950,22 @@ class T_subtensor(unittest.TestCase):
...
@@ -1946,20 +1950,22 @@ class T_subtensor(unittest.TestCase):
def
test2_err_bounds0
(
self
):
def
test2_err_bounds0
(
self
):
n
=
self
.
shared
(
numpy
.
ones
((
2
,
3
),
dtype
=
self
.
dtype
)
*
5
)
n
=
self
.
shared
(
numpy
.
ones
((
2
,
3
),
dtype
=
self
.
dtype
)
*
5
)
t
=
n
[
0
,
4
]
for
idx
in
[(
0
,
4
),(
0
,
-
4
)]:
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
Subtensor
))
t
=
n
[
idx
]
# Silence expected warnings
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
Subtensor
))
_logger
=
logging
.
getLogger
(
'theano.gof.opt'
)
# Silence expected warnings
oldlevel
=
_logger
.
level
_logger
=
logging
.
getLogger
(
'theano.gof.opt'
)
_logger
.
setLevel
(
logging
.
CRITICAL
)
oldlevel
=
_logger
.
level
try
:
_logger
.
setLevel
(
logging
.
CRITICAL
)
try
:
try
:
tval
=
self
.
eval_output_and_check
([
t
])
try
:
assert
0
tval
=
self
.
eval_output_and_check
([
t
])
except
IndexError
,
e
:
assert
0
pass
except
IndexError
,
e
:
finally
:
pass
_logger
.
setLevel
(
oldlevel
)
finally
:
_logger
.
setLevel
(
oldlevel
)
def
test2_err_bounds1
(
self
):
def
test2_err_bounds1
(
self
):
n
=
self
.
shared
((
numpy
.
ones
((
2
,
3
),
dtype
=
self
.
dtype
)
*
5
))
n
=
self
.
shared
((
numpy
.
ones
((
2
,
3
),
dtype
=
self
.
dtype
)
*
5
))
t
=
n
[
4
:
5
,
2
]
t
=
n
[
4
:
5
,
2
]
...
@@ -2075,6 +2081,10 @@ class T_subtensor(unittest.TestCase):
...
@@ -2075,6 +2081,10 @@ class T_subtensor(unittest.TestCase):
(
numpy
.
random
.
rand
(
4
,
5
),
[
2
,
3
]),
(
numpy
.
random
.
rand
(
4
,
5
),
[
2
,
3
]),
(
numpy
.
random
.
rand
(
4
,
2
,
3
),
[
0
,
3
]),
(
numpy
.
random
.
rand
(
4
,
2
,
3
),
[
0
,
3
]),
(
numpy
.
random
.
rand
(
4
,
2
,
3
),
[
3
,
3
,
1
,
1
,
2
,
2
,
0
,
0
]),
(
numpy
.
random
.
rand
(
4
,
2
,
3
),
[
3
,
3
,
1
,
1
,
2
,
2
,
0
,
0
]),
(
numpy
.
random
.
rand
(
4
,
2
,
3
),
[
3
,
3
,
1
,
1
,
2
,
2
,
0
,
0
,
-
1
,
-
2
,
-
3
,
-
4
]),
# Test 4 dims as gpu code use another algo in that case
# This new algo is not as much optimized for that case.
(
numpy
.
random
.
rand
(
4
,
4
,
2
,
3
),
[
3
,
3
,
1
,
1
,
2
,
2
,
0
,
0
,
-
1
,
-
2
,
-
3
,
-
4
]),
# Test with TensorConstant index.
# Test with TensorConstant index.
(
numpy
.
random
.
rand
(
4
,
2
,
3
),
constant
([
3
,
3
,
1
,
1
,
2
,
2
,
0
,
0
])),
(
numpy
.
random
.
rand
(
4
,
2
,
3
),
constant
([
3
,
3
,
1
,
1
,
2
,
2
,
0
,
0
])),
]:
]:
...
@@ -2093,6 +2103,19 @@ class T_subtensor(unittest.TestCase):
...
@@ -2093,6 +2103,19 @@ class T_subtensor(unittest.TestCase):
self
.
assertTrue
(
val
.
ndim
==
data
.
ndim
)
self
.
assertTrue
(
val
.
ndim
==
data
.
ndim
)
self
.
assertTrue
(
numpy
.
allclose
(
val
,
good
),
(
val
,
good
))
self
.
assertTrue
(
numpy
.
allclose
(
val
,
good
),
(
val
,
good
))
# Test reuse of output memory
if
isinstance
(
self
.
adv_sub1
,
tensor
.
AdvancedSubtensor1
):
op
=
self
.
adv_sub1
()
# When idx is a TensorConstant.
if
hasattr
(
idx
,
"data"
):
idx
=
idx
.
data
test_out
=
[[
None
]]
op
.
perform
(
None
,
[
data
,
idx
],
test_out
)
out1
=
test_out
[
0
][
0
]
op
.
perform
(
None
,
[
data
,
idx
],
test_out
)
out2
=
test_out
[
0
][
0
]
assert
out1
is
out2
def
test_err_invalid_list
(
self
):
def
test_err_invalid_list
(
self
):
n
=
self
.
shared
(
numpy
.
asarray
(
5
,
dtype
=
self
.
dtype
))
n
=
self
.
shared
(
numpy
.
asarray
(
5
,
dtype
=
self
.
dtype
))
self
.
assertRaises
(
TypeError
,
n
.
__getitem__
,
[
0
,
0
])
self
.
assertRaises
(
TypeError
,
n
.
__getitem__
,
[
0
,
0
])
...
@@ -2104,16 +2127,18 @@ class T_subtensor(unittest.TestCase):
...
@@ -2104,16 +2127,18 @@ class T_subtensor(unittest.TestCase):
def
test_err_bound_list
(
self
):
def
test_err_bound_list
(
self
):
n
=
self
.
shared
(
numpy
.
ones
((
2
,
3
),
dtype
=
self
.
dtype
)
*
5
)
n
=
self
.
shared
(
numpy
.
ones
((
2
,
3
),
dtype
=
self
.
dtype
)
*
5
)
t
=
n
[[
0
,
4
]]
l
=
lvector
()
t
=
n
[
l
]
# We test again AdvancedSubtensor1 as we transfer data to the cpu.
# We test again AdvancedSubtensor1 as we transfer data to the cpu.
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
theano
.
tensor
.
basic
.
AdvancedSubtensor1
))
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
theano
.
tensor
.
basic
.
AdvancedSubtensor1
))
f
=
function
([],
t
,
mode
=
self
.
mode
)
f
=
function
([
l
],
t
,
mode
=
self
.
mode
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
self
.
ignore_topo
)]
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
self
.
ignore_topo
)]
assert
len
(
topo_
)
==
1
assert
len
(
topo_
)
==
1
self
.
assertTrue
(
isinstance
(
topo_
[
0
]
.
op
,
self
.
adv_sub1
))
self
.
assertTrue
(
isinstance
(
topo_
[
0
]
.
op
,
self
.
adv_sub1
))
self
.
assertRaises
(
IndexError
,
f
)
for
shp
in
[[
0
,
4
],[
0
,
-
3
],
[
-
10
]]:
self
.
assertRaises
(
IndexError
,
f
,
shp
)
def
test_adv_sub1_broadcast
(
self
):
def
test_adv_sub1_broadcast
(
self
):
ones
=
numpy
.
ones
((
1
,
3
),
dtype
=
self
.
dtype
)
ones
=
numpy
.
ones
((
1
,
3
),
dtype
=
self
.
dtype
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论