Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8022ce3e
提交
8022ce3e
authored
8月 29, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
some doc for RandomFunction
上级
dbc0ea78
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
24 行增加
和
0 行删除
+24
-0
tensor_random.py
tensor_random.py
+24
-0
没有找到文件。
tensor_random.py
浏览文件 @
8022ce3e
...
@@ -10,6 +10,12 @@ from copy import copy
...
@@ -10,6 +10,12 @@ from copy import copy
class
RandomFunction
(
gof
.
Op
):
class
RandomFunction
(
gof
.
Op
):
def
__init__
(
self
,
fn
,
outtype
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
fn
,
outtype
,
*
args
,
**
kwargs
):
"""
fn: a random function with the same signature as functions in numpy.random.RandomState
outtype: the type of the output
args: a list of default arguments for the function
kwargs: if the 'inplace' key is there, its value will be used to determine if the op operates inplace or not
"""
self
.
fn
=
fn
self
.
fn
=
fn
self
.
outtype
=
outtype
self
.
outtype
=
outtype
self
.
args
=
map
(
tensor
.
as_tensor
,
args
)
self
.
args
=
map
(
tensor
.
as_tensor
,
args
)
...
@@ -18,6 +24,13 @@ class RandomFunction(gof.Op):
...
@@ -18,6 +24,13 @@ class RandomFunction(gof.Op):
self
.
destroy_map
=
{
0
:
[
0
]}
self
.
destroy_map
=
{
0
:
[
0
]}
def
make_node
(
self
,
r
,
shape
,
*
args
):
def
make_node
(
self
,
r
,
shape
,
*
args
):
"""
in: r -> RandomState (gof.generic),
shape -> lvector
args -> the arguments expected by the numpy function
out: r2 -> the new RandomState (gof.generic)
out -> the random numbers we generated
"""
args
=
map
(
tensor
.
as_tensor
,
args
)
args
=
map
(
tensor
.
as_tensor
,
args
)
shape
=
tensor
.
as_tensor
(
shape
)
shape
=
tensor
.
as_tensor
(
shape
)
assert
shape
.
type
==
tensor
.
lvector
assert
shape
.
type
==
tensor
.
lvector
...
@@ -52,6 +65,17 @@ class RandomFunction(gof.Op):
...
@@ -52,6 +65,17 @@ class RandomFunction(gof.Op):
def
random_function
(
fn
,
dtype
,
*
rfargs
,
**
rfkwargs
):
def
random_function
(
fn
,
dtype
,
*
rfargs
,
**
rfkwargs
):
"""
Returns a wrapper around RandomFunction which automatically infers the number
of dimensions of the output from the given shape. If the shape cannot be inferred,
the user can give an integer as first argument, which will be interpreted as the
number of dimensions.
The number of dimensions for the following shape arguments can be inferred:
- shape(x)
- make_lvector(x, y, z, ...)
- constants
"""
def
f
(
ndim
,
*
args
,
**
kwargs
):
def
f
(
ndim
,
*
args
,
**
kwargs
):
if
isinstance
(
ndim
,
int
):
if
isinstance
(
ndim
,
int
):
r
,
shape
,
args
=
args
[
0
],
args
[
1
],
args
[
2
:]
r
,
shape
,
args
=
args
[
0
],
args
[
1
],
args
[
2
:]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论