Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fcdd8c77
提交
fcdd8c77
authored
1月 11, 2017
作者:
Frédéric Bastien
提交者:
GitHub
1月 11, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5346 from nouiz/multinomial_wor
[ENH] Multinomial without replacement
上级
752cc01a
7469193c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
28 行增加
和
7 行删除
+28
-7
multinomial.py
theano/gpuarray/multinomial.py
+24
-6
multinomial.py
theano/sandbox/multinomial.py
+4
-1
没有找到文件。
theano/gpuarray/multinomial.py
浏览文件 @
fcdd8c77
...
@@ -315,8 +315,11 @@ KERNEL void k_multi_warp_multinomial_wor(
...
@@ -315,8 +315,11 @@ KERNEL void k_multi_warp_multinomial_wor(
done = true;
done = true;
}
}
}
}
// renormalize the multinomial
// No need to renormalize after the last samples.
for (ga_int k = 0; k < nb_outcomes; ++k)
if (c == (n_samples - 1))
break;
// parallel renormalize the multinomial
for (ga_int k = LID_1; k < nb_outcomes; k+=LDIM_1)
{
{
global_pvals_copy[k * pvals_col_stride + n * pvals_row_stride] /= cummul;
global_pvals_copy[k * pvals_col_stride + n * pvals_row_stride] /= cummul;
}
}
...
@@ -385,7 +388,8 @@ KERNEL void k_multi_warp_multinomial_wor(
...
@@ -385,7 +388,8 @@ KERNEL void k_multi_warp_multinomial_wor(
if (theano_prep_output(&out, 2, dims, GA_LONG,
if (theano_prep_output(&out, 2, dims, GA_LONG,
GA_C_ORDER,
%(ctx)
s) != 0){
GA_C_ORDER,
%(ctx)
s) != 0){
%(fail)
s
Py_DECREF(pvals_copy);
%(fail)
s
}
}
%(out)
s = out;
%(out)
s = out;
...
@@ -413,6 +417,7 @@ KERNEL void k_multi_warp_multinomial_wor(
...
@@ -413,6 +417,7 @@ KERNEL void k_multi_warp_multinomial_wor(
PyExc_ValueError,
PyExc_ValueError,
"Multinomial is not implemented for so many rows in the matrix (
%%
i)",
"Multinomial is not implemented for so many rows in the matrix (
%%
i)",
nb_multi);
nb_multi);
Py_DECREF(pvals_copy);
%(fail)
s
%(fail)
s
}
}
...
@@ -439,23 +444,36 @@ KERNEL void k_multi_warp_multinomial_wor(
...
@@ -439,23 +444,36 @@ KERNEL void k_multi_warp_multinomial_wor(
args[9] = (void*)&strides[3];
args[9] = (void*)&strides[3];
args[10] = (void*)&strides[4];
args[10] = (void*)&strides[4];
err = GpuKernel_call(&
%(kname)
s, 1, &nb_threads, &nb_blocks, 0, args);
size_t nb_threads2[2], nb_blocks2[2];
nb_threads2[0] = nb_threads;
nb_threads2[1] = 1;
// If we can't schedule enough threads parallelize the renormalization.
// I do this because we don't always use those extra threads.
if (nb_threads * nb_blocks < 2048)
nb_threads2[1] = 1024 / nb_threads;
nb_blocks2[0] = nb_blocks;
nb_blocks2[1] = 1;
err = GpuKernel_call(&
%(kname)
s, 2, nb_threads2, nb_blocks2, 0, args);
if (err != GA_NO_ERROR) {
if (err != GA_NO_ERROR) {
PyErr_Format(
PyErr_Format(
PyExc_RuntimeError,
PyExc_RuntimeError,
"gpuarray error:
%%
s:
%%
s.
\\
n",
"gpuarray error:
%%
s:
%%
s.
\\
n",
"k_multi_warp_
%(name)
s",
"k_multi_warp_
%(name)
s",
GpuKernel_error(&
%(kname)
s, err));
GpuKernel_error(&
%(kname)
s, err));
%(fail)
s;
Py_DECREF(pvals_copy);
%(fail)
s;
}
}
if(
%(sync)
d)
if(
%(sync)
d)
GpuArray_sync(&(out->ga));
GpuArray_sync(&(out->ga));
Py_DECREF(pvals_copy);
} // END NESTED SCOPE
} // END NESTED SCOPE
"""
%
locals
()
"""
%
locals
()
return
s
return
s
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
1
,)
return
(
4
,)
@register_opt
(
'fast_compile'
)
@register_opt
(
'fast_compile'
)
...
...
theano/sandbox/multinomial.py
浏览文件 @
fcdd8c77
...
@@ -329,6 +329,9 @@ class MultinomialWOReplacementFromUniform(MultinomialFromUniform):
...
@@ -329,6 +329,9 @@ class MultinomialWOReplacementFromUniform(MultinomialFromUniform):
if (cummul > *unis_n)
if (cummul > *unis_n)
{
{
*z_nc = m;
*z_nc = m;
// No need to renormalize after the last samples.
if (c == (n_samples - 1))
break;
// renormalize the nth row of pvals, reuse (cummul-*pvals_nm) to initialize the sum
// renormalize the nth row of pvals, reuse (cummul-*pvals_nm) to initialize the sum
dtype_
%(pvals)
s sum = cummul - *pvals_nm;
dtype_
%(pvals)
s sum = cummul - *pvals_nm;
dtype_
%(pvals)
s* pvals_n = (dtype_
%(pvals)
s*)PyArray_GETPTR2(pvals_copy, n, m);
dtype_
%(pvals)
s* pvals_n = (dtype_
%(pvals)
s*)PyArray_GETPTR2(pvals_copy, n, m);
...
@@ -434,7 +437,7 @@ class GpuMultinomialFromUniform(MultinomialFromUniform, GpuOp):
...
@@ -434,7 +437,7 @@ class GpuMultinomialFromUniform(MultinomialFromUniform, GpuOp):
return
Op
.
perform
(
self
,
node
,
ins
,
outs
)
return
Op
.
perform
(
self
,
node
,
ins
,
outs
)
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
8
,)
return
(
9
,)
def
c_support_code_apply
(
self
,
node
,
nodename
):
def
c_support_code_apply
(
self
,
node
,
nodename
):
return
"""
return
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论