Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
tensorflow
提交
4c620cc8
T
tensorflow
项目概览
xxadev
/
tensorflow
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
1
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,发现更多精彩内容 >>
提交
4c620cc8
编写于
1月 12, 2017
作者:
A
A. Unique TensorFlower
提交者:
TensorFlower Gardener
1月 12, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[XLA] Add LiteralUtil::Replicate.
Change: 144352405
上级
a2f9e996
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
0 deletion
+30
-0
tensorflow/compiler/xla/literal_util.h
tensorflow/compiler/xla/literal_util.h
+30
-0
未找到文件。
tensorflow/compiler/xla/literal_util.h
浏览文件 @
4c620cc8
...
...
@@ -136,6 +136,12 @@ class LiteralUtil {
const
Literal
&
literal
,
tensorflow
::
gtl
::
ArraySlice
<
int64
>
start_indices
,
tensorflow
::
gtl
::
ArraySlice
<
int64
>
limit_indices
);
// Creates a literal with a prepended dimension with bound "times"; e.g. a
// f32[3x2] with times=4 will produce a f32[4x3x2] with the 3x2 from the input
// literal replicated four times.
template
<
typename
NativeT
>
static
std
::
unique_ptr
<
Literal
>
Replicate
(
const
Literal
&
input
,
int64
times
);
// Create a literal by converting each element in an original literal to a new
// type.
template
<
typename
NativeSrcT
,
typename
NativeDestT
>
...
...
@@ -999,6 +1005,30 @@ LiteralUtil::CreateFullWithMonotonicDim0MajorLayout(
return
literal
;
}
template
<
typename
NativeT
>
/* static */
std
::
unique_ptr
<
Literal
>
LiteralUtil
::
Replicate
(
const
Literal
&
input
,
int64
times
)
{
std
::
vector
<
int64
>
bounds
=
{
times
};
bounds
.
insert
(
bounds
.
end
(),
input
.
shape
().
dimensions
().
begin
(),
input
.
shape
().
dimensions
().
end
());
auto
literal
=
MakeUnique
<
Literal
>
();
*
literal
->
mutable_shape
()
=
ShapeUtil
::
MakeShape
(
input
.
shape
().
element_type
(),
bounds
);
Reserve
(
ShapeUtil
::
ElementsIn
(
literal
->
shape
()),
literal
.
get
());
for
(
int64
index
=
0
;
index
<
ShapeUtil
::
ElementsIn
(
input
.
shape
());
++
index
)
{
const
std
::
vector
<
int64
>
element_indices
=
IndexUtil
::
LinearIndexToMultidimensionalIndex
(
input
.
shape
(),
index
);
const
auto
element
=
Get
<
NativeT
>
(
input
,
element_indices
);
for
(
int64
sample
=
0
;
sample
<
times
;
++
sample
)
{
std
::
vector
<
int64
>
output_indices
=
{
sample
};
output_indices
.
insert
(
output_indices
.
end
(),
element_indices
.
begin
(),
element_indices
.
end
());
Set
<
NativeT
>
(
literal
.
get
(),
output_indices
,
element
);
}
}
return
literal
;
}
}
// namespace xla
#endif // TENSORFLOW_COMPILER_XLA_LITERAL_UTIL_H_
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录