#174 add some math functions begin with letter 'c' to 'l'

Merged
zoulq merged 25 commits from tanh01 into master 1 year ago
kcl commented 1 year ago
zoulq reviewed 1 year ago
@@ -1068,0 +1150,4 @@
return cast_to_adapter_tensor(output)


def angle(input, *, out=None):
zoulq commented 1 year ago
最新版本的mindspore以及支持该接口,建议加上TODO,并在表格中记录
kcl commented 1 year ago
已记录未找到该接口,本地已加上todo后续一并重提
zoulq reviewed 1 year ago
ms_adapter/pytorch/functional.py
@@ -1068,0 +1287,4 @@
def bitwise_and(input, other, *, out=None):
if out is not None:
warnings.warn("do not support parameter out")
if isinstance(input, adapter_tensor):
zoulq commented 1 year ago
cast_to_ms_tensor函数内部已经修改了判断逻辑,如果是adapter_tensor才会做转换,所以这里可以不用再判断一次。
kcl commented 1 year ago
一些if下不止进行了cast_to_ms_tensor,对代码中其他只做转换的部分去除了判断
zoulq reviewed 1 year ago
@@ -1068,0 +1298,4 @@
else:
other_is_bool = isinstance(other, bool)
if input_is_bool and other_is_bool:
input = input.astype(ms.int8)
zoulq commented 1 year ago
这里转int8是什么原因?ops.bitwise_and()接口不支持bool类型的tensor输入吗?
kcl commented 1 year ago
是的,但这里有点问题,已在本地修复
zoulq reviewed 1 year ago
@@ -1068,0 +1365,4 @@
input = cast_to_ms_tensor(input).asnumpy()
if isinstance(other, adapter_tensor):
other = cast_to_ms_tensor(other).asnumpy()
output = ms.Tensor(np.right_shift(input, other))
zoulq commented 1 year ago
建议和mindspore的ops.RightShift对比一下性能,另外也要记录对应接口的需求
kcl commented 1 year ago
没有找到ops.RightShift
zoulq reviewed 1 year ago
ms_adapter/pytorch/functional.py
@@ -1068,0 +1381,4 @@
min = ms.Tensor(min, type)
if max is not None:
max = ms.Tensor(max, type)
output = ms.ops.clip_by_value(input, min, max)
zoulq commented 1 year ago
这个接口现在的逻辑有点复杂,mindspore有Tensor.clip()接口,可以看看是否满足直接调用
kcl commented 1 year ago
已修改
zoulq reviewed 1 year ago
@@ -1068,0 +1413,4 @@
else:
output = output.astype(other_type)
elif is_num or 'Int' in str(other_type):
output = output.astype(input_type)
zoulq commented 1 year ago
最新版本已经有了对应接口,暂时版本写的话可以加上TODO
kcl commented 1 year ago
这个ms接口与pytorch结果不一致,已记录
zoulq reviewed 1 year ago
@@ -1068,0 +1551,4 @@
mantissa, exponent = np.frexp(input)
mantissa = ms.Tensor(mantissa)
exponent = ms.Tensor(exponent)
return cast_to_ms_tensor(mantissa), cast_to_ms_tensor(exponent)
zoulq commented 1 year ago
这里return应该是adapter tensor,另外这两步可合成一步。
kcl commented 1 year ago
已修改
zoulq reviewed 1 year ago
@@ -1068,0 +1554,4 @@
return cast_to_ms_tensor(mantissa), cast_to_ms_tensor(exponent)


def gradient(input, *, spacing=1, dim=None, edge_order=1):
zoulq commented 1 year ago
这个接口建议暂时不对外提供,mindspore暂时没有这个接口对应的功能,可以先提需求
kcl commented 1 year ago
已在表格记录功能不齐
zoulq reviewed 1 year ago
@@ -1068,0 +1591,4 @@
if isinstance(weight, adapter_tensor):
weight = cast_to_ms_tensor(weight)
elif not isinstance(weight, float):
weight = float(weight)
zoulq commented 1 year ago
如果weight已经是float类型,为什么还要做类型转换呢?
kcl commented 1 year ago
pytorch使用int型tensor不可以跑,但int数值做输入可以。ms不支持weight使用int数值,所以在这里转成float
zoulq reviewed 1 year ago
@@ -1068,0 +1668,4 @@
input = ms.ops.clip_by_value(input, eps, 1.0-eps)
input = ms.ops.clip_by_value(input, eps, 1.0-eps)
output = ms.ops.log(input/(1.0-input))
#output = ms.ops.logit(input, eps)
zoulq commented 1 year ago
最新版本已经有ops.logit接口了,现在也可以用Tensor.logit()对标试试。
kcl commented 1 year ago
ms的接口不支持cpu,已记录
zoulq reviewed 1 year ago
@@ -1069,6 +1071,10 @@ def squeeze(input, dim=None):
return cast_to_adapter_tensor(output)


def from_numpy(np_data):
zoulq commented 1 year ago
这个最新仓上已经有了
kcl commented 1 year ago
这个不是我写的,只换了一下位置
zoulq reviewed 1 year ago
ms_adapter/pytorch/functional.py
@@ -992,6 +992,8 @@ def view_as_real(input):
def bincount(input, weights=None, minlength=0):
input = cast_to_ms_tensor(input)
type = 'int64'
if 'UInt' in str(input.dtype):
zoulq commented 1 year ago
input上面已经转成了mindspore tensor,这里是不是可以直接用mindspore.uint8来判断?
kcl commented 1 year ago
已修改
kcl changed title from WIP: add some math functions begin with letter 'c' to 'l' to add some math functions begin with letter 'c' to 'l' 1 year ago
zoulq merged commit 59a8f038ee into master 1 year ago
The pull request has been merged as 59a8f038ee.
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This pull request currently doesn't have any dependencies.

Loading…
There is no content yet.