Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
c1a53d3f
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c1a53d3f
编写于
7月 02, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
7月 02, 2020
浏览文件
操作
浏览文件
下载
差异文件
!2822 Fix bool tensor problem
Merge pull request !2822 from hewei/fix_bool_tensor
上级
0cd9e4cc
a0623e15
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
15 addition
and
22 deletion
+15
-22
mindspore/ccsrc/ir/tensor.cc
mindspore/ccsrc/ir/tensor.cc
+1
-18
tests/ut/python/ir/test_tensor.py
tests/ut/python/ir/test_tensor.py
+14
-4
未找到文件。
mindspore/ccsrc/ir/tensor.cc
浏览文件 @
c1a53d3f
...
...
@@ -30,8 +30,6 @@
namespace
mindspore
{
namespace
tensor
{
using
Bool
=
unsigned
char
;
static
std
::
string
MakeId
()
{
// Use atomic to make id generator thread safe.
static
std
::
atomic
<
uint64_t
>
last_id
{
1
};
...
...
@@ -50,10 +48,7 @@ template <typename T>
std
::
vector
<
T
>
CopyData
(
const
std
::
vector
<
int
>
&
shape
,
void
*
data
,
TypeId
data_type
)
{
const
size_t
count
=
SizeOf
(
shape
);
switch
(
data_type
)
{
case
kNumberTypeBool
:
{
auto
buf
=
static_cast
<
Bool
*>
(
data
);
return
std
::
vector
<
T
>
(
buf
,
buf
+
count
);
}
case
kNumberTypeBool
:
case
kNumberTypeUInt8
:
{
auto
buf
=
static_cast
<
uint8_t
*>
(
data
);
return
std
::
vector
<
T
>
(
buf
,
buf
+
count
);
...
...
@@ -104,14 +99,6 @@ std::vector<T> CopyData(const std::vector<int> &shape, void *data, TypeId data_t
MS_LOG
(
EXCEPTION
)
<<
"Cannot construct Tensor because of unsupported data type: "
<<
data_type
<<
"."
;
}
// Convert to bool is not allowed.
template
<
>
std
::
vector
<
Bool
>
CopyData
<
Bool
>
(
const
std
::
vector
<
int
>
&
shape
,
void
*
data
,
TypeId
data_type
)
{
MS_LOG
(
EXCEPTION
)
<<
"Cannot convert from "
<<
TypeIdLabel
(
data_type
)
<<
" to "
<<
TypeIdLabel
(
kNumberTypeBool
)
<<
"."
;
return
{};
}
template
<
typename
T
>
std
::
vector
<
T
>
CopyData
(
const
std
::
vector
<
int
>
&
shape
,
void
*
data
,
size_t
data_len
)
{
size_t
size
=
SizeOf
(
shape
);
...
...
@@ -192,10 +179,6 @@ template <typename... Args>
TensorDataPtr
MakeTensorData
(
TypeId
data_type
,
const
std
::
vector
<
int
>
&
shape
,
Args
...
args
)
{
switch
(
data_type
)
{
case
kNumberTypeBool
:
// std::vector<bool> is a specialization of std::vector,
// it may use single bit instead of sizeof(bool) bytes,
// so we use std::vector<Bool> for bool tensors.
return
std
::
make_shared
<
TensorDataImpl
<
Bool
>>
(
shape
,
args
...);
case
kNumberTypeUInt8
:
return
std
::
make_shared
<
TensorDataImpl
<
uint8_t
>>
(
shape
,
args
...);
case
kNumberTypeInt8
:
...
...
tests/ut/python/ir/test_tensor.py
浏览文件 @
c1a53d3f
...
...
@@ -430,10 +430,20 @@ def test_tensor_dtype_np_int64():
def
test_tensor_dtype_fp32_to_bool
():
with
pytest
.
raises
(
RuntimeError
):
input_
=
np
.
random
.
randn
(
2
,
3
,
4
,
5
).
astype
(
np
.
float32
)
input_
=
ms
.
Tensor
(
input_
)
_
=
ms
.
Tensor
(
input_
,
dtype
=
ms
.
bool_
)
input_
=
np
.
random
.
randn
(
2
,
3
,
4
,
5
).
astype
(
np
.
float32
)
input_
=
ms
.
Tensor
(
input_
)
t
=
ms
.
Tensor
(
input_
,
dtype
=
ms
.
bool_
)
assert
isinstance
(
t
,
ms
.
Tensor
)
assert
t
.
shape
==
(
2
,
3
,
4
,
5
)
assert
t
.
dtype
==
ms
.
bool_
def
test_tensor_dtype_fp64_to_uint8
():
array
=
np
.
array
([[
1
,
2
,
3
],
[
4
,
5
,
6
]],
dtype
=
np
.
float64
)
t
=
ms
.
Tensor
(
array
,
ms
.
uint8
)
assert
isinstance
(
t
,
ms
.
Tensor
)
assert
t
.
shape
==
(
2
,
3
)
assert
t
.
dtype
==
ms
.
uint8
def
test_tensor_operation
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录