Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_38905368
tensorflow
提交
22af085f
T
tensorflow
项目概览
qq_38905368
/
tensorflow
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
tensorflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
22af085f
编写于
12月 12, 2018
作者:
A
A. Unique TensorFlower
提交者:
TensorFlower Gardener
12月 12, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[XLA] add Iota and BroadcastedIota to local Python client
PiperOrigin-RevId: 225256432
上级
1b7e1c7c
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
53 addition
and
0 deletion
+53
-0
tensorflow/compiler/xla/python/local_computation_builder.cc
tensorflow/compiler/xla/python/local_computation_builder.cc
+9
-0
tensorflow/compiler/xla/python/local_computation_builder.h
tensorflow/compiler/xla/python/local_computation_builder.h
+4
-0
tensorflow/compiler/xla/python/local_computation_builder.i
tensorflow/compiler/xla/python/local_computation_builder.i
+2
-0
tensorflow/compiler/xla/python/xla_client.py
tensorflow/compiler/xla/python/xla_client.py
+27
-0
tensorflow/compiler/xla/python/xla_client_test.py
tensorflow/compiler/xla/python/xla_client_test.py
+11
-0
未找到文件。
tensorflow/compiler/xla/python/local_computation_builder.cc
浏览文件 @
22af085f
...
...
@@ -647,6 +647,15 @@ LocalOp LocalComputationBuilder::ConstantLiteral(const Literal& literal) {
return
xla
::
ConstantLiteral
(
&
builder_
,
literal
);
}
LocalOp
LocalComputationBuilder
::
Iota
(
PrimitiveType
element_type
,
int64
size
)
{
return
xla
::
Iota
(
&
builder_
,
element_type
,
size
);
}
LocalOp
LocalComputationBuilder
::
BroadcastedIota
(
const
Shape
&
shape
,
int64
dimension
)
{
return
xla
::
Iota
(
&
builder_
,
shape
,
dimension
);
}
LocalOp
LocalComputationBuilder
::
Broadcast
(
const
LocalOp
&
operand
,
absl
::
Span
<
const
int64
>
broadcast_sizes
)
{
return
xla
::
Broadcast
(
operand
.
op
(),
broadcast_sizes
);
...
...
tensorflow/compiler/xla/python/local_computation_builder.h
浏览文件 @
22af085f
...
...
@@ -286,6 +286,10 @@ class LocalComputationBuilder {
LocalOp
ConstantLiteral
(
const
Literal
&
literal
);
LocalOp
Iota
(
PrimitiveType
element_type
,
int64
size
);
LocalOp
BroadcastedIota
(
const
Shape
&
shape
,
int64
dimension
);
LocalOp
Broadcast
(
const
LocalOp
&
operand
,
absl
::
Span
<
const
int64
>
broadcast_sizes
);
...
...
tensorflow/compiler/xla/python/local_computation_builder.i
浏览文件 @
22af085f
...
...
@@ -1051,6 +1051,8 @@ tensorflow::ImportNumpy();
%
unignore
xla
::
swig
::
LocalComputationBuilder
::
Outfeed
;
%
unignore
xla
::
swig
::
LocalComputationBuilder
::
ConstantLiteral
;
%
unignore
xla
::
swig
::
LocalComputationBuilder
::
ConstantR0
;
%
unignore
xla
::
swig
::
LocalComputationBuilder
::
Iota
;
%
unignore
xla
::
swig
::
LocalComputationBuilder
::
BroadcastedIota
;
%
unignore
xla
::
swig
::
LocalComputationBuilder
::
Broadcast
;
%
unignore
xla
::
swig
::
LocalComputationBuilder
::
BroadcastInDim
;
%
unignore
xla
::
swig
::
LocalComputationBuilder
::
Pad
;
...
...
tensorflow/compiler/xla/python/xla_client.py
浏览文件 @
22af085f
...
...
@@ -831,6 +831,33 @@ class ComputationBuilder(object):
return
self
.
ParameterWithShape
(
Shape
.
from_pyval
(
value
),
name
=
name
,
parameter_num
=
parameter_num
)
def
Iota
(
self
,
dtype
,
size
):
"""Enqueues an iota constant onto the computation.
Args:
dtype: expected numpy dtype of the output.
size: integer, the number of elements in the array.
Returns:
A LocalOp representing the added iota constant.
"""
element_type
=
DTYPE_TO_XLA_ELEMENT_TYPE
[
str
(
np
.
dtype
(
dtype
))]
return
self
.
_client
.
Iota
(
element_type
,
size
)
def
BroadcastedIota
(
self
,
dtype
,
shape
,
dimension
):
"""Enqueues a broadcasted iota constant onto the computation.
Args:
dtype: expected numpy dtype of the output.
shape: tuple of integers, the expected output shape (dimensions).
dimension: positive integer, dimension along which to increment values.
Returns:
A LocalOp representing the added broadcasted iota constant.
"""
xla_shape
=
Shape
.
array_shape
(
dtype
,
shape
)
return
self
.
_client
.
BroadcastedIota
(
xla_shape
,
dimension
)
def
Broadcast
(
self
,
operand
,
sizes
):
"""Enqueues a broadcast operation onto the computation.
...
...
tensorflow/compiler/xla/python/xla_client_test.py
浏览文件 @
22af085f
...
...
@@ -146,6 +146,17 @@ class ComputationsWithConstantsTest(LocalComputationTest):
c
.
Pow
(
c
.
Constant
(
NumpyArrayF64
([
1.5
,
2.5
,
3.0
])),
c
.
ConstantF64Scalar
(
2.
))
self
.
_ExecuteAndCompareClose
(
c
,
expected
=
[
2.25
,
6.25
,
9.
])
def
testIota
(
self
):
c
=
self
.
_NewComputation
()
c
.
Iota
(
np
.
float32
,
10
)
self
.
_ExecuteAndCompareExact
(
c
,
expected
=
np
.
arange
(
10
,
dtype
=
np
.
float32
))
def
testBroadcastedIota
(
self
):
c
=
self
.
_NewComputation
()
c
.
BroadcastedIota
(
np
.
int64
,
(
2
,
3
),
1
)
expected
=
np
.
array
([[
0
,
1
,
2
],
[
0
,
1
,
2
]],
dtype
=
np
.
int64
)
self
.
_ExecuteAndCompareExact
(
c
,
expected
=
expected
)
def
testBooleanAnd
(
self
):
c
=
self
.
_NewComputation
()
c
.
And
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录