!55718 Delete python object for list convert to dynamic length sequence

Merge pull request !55718 from LiangZhibo/seq_op
This commit is contained in:
i-robot 2023-06-27 03:23:00 +00:00 committed by Gitee
commit 1275f2b17b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 31 additions and 2 deletions

View File

@ -1129,6 +1129,11 @@ ValuePtr AbstractList::RealBuildValue() const {
return ElementsBuildValue<ValueList>();
}
void AbstractList::CheckAndConvertToDynamicLenSequence(bool raise_exception) {
AbstractSequence::CheckAndConvertToDynamicLenSequence(raise_exception);
ClearListUserData();
}
std::shared_ptr<AbstractSequence> AbstractSequence::DynamicLenSequenceJoin(const AbstractSequencePtr &other) {
auto other_dyn_sequence_abs = other;
if (!dynamic_len() || !other->dynamic_len()) {

View File

@ -1084,7 +1084,7 @@ class MS_CORE_API AbstractSequence : public AbstractBase {
void set_dynamic_len_element_abs(const AbstractBasePtr &dynamic_len_element_abs);
/// \brief Check and convert the sequence to dynamic length sequence.
void CheckAndConvertToDynamicLenSequence(bool raise_exception = true);
virtual void CheckAndConvertToDynamicLenSequence(bool raise_exception = true);
std::shared_ptr<AbstractSequence> BroadenToDynamicLenSequence();
@ -1244,6 +1244,9 @@ class MS_CORE_API AbstractList final : public AbstractSequence {
/// \return The corresponding list user data.
UserDataPtr list_user_data() { return list_user_data_; }
/// \brief Check and convert the list to dynamic length list.
void CheckAndConvertToDynamicLenSequence(bool raise_exception = true) override;
protected:
ValuePtr RealBuildValue() const override;

View File

@ -791,7 +791,7 @@ def test_list_inplace_reverse_with_variable_3():
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_x86_ascend_training
@pytest.mark.env_onecard
def test_list_dynamic_len_list_inplace_op():
def test_dynamic_len_list_inplace_op():
"""
Feature: dynamic length list do not run inplace operation.
Description: support list inplace ops.
@ -807,3 +807,24 @@ def test_list_dynamic_len_list_inplace_op():
out = foo()
assert out == [2, 5, 1, 7]
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_x86_ascend_training
@pytest.mark.env_onecard
def test_dynamic_len_list_inplace_op_2():
"""
Feature: dynamic length list do not run inplace operation.
Description: support list inplace ops.
Expectation: No exception.
"""
@jit
def foo(a):
x = [1, 2, 3, 4]
y = x[a::]
return y
input_index = Tensor(2)
out = foo(input_index)
assert out == [3, 4]