Skip to content

[Hidet Script] Add in and not in expression in hidet script#255

Merged
yaoyaoding merged 1 commit intohidet-org:mainfrom
yaoyaoding:if-then-else
May 29, 2023
Merged

[Hidet Script] Add in and not in expression in hidet script#255
yaoyaoding merged 1 commit intohidet-org:mainfrom
yaoyaoding:if-then-else

Conversation

@yaoyaoding
Copy link
Copy Markdown
Member

Usage:

def test_if_then_else():
    from hidet.lang import attrs, tensor

    dims = [2, 3]

    with hidet.script_module() as script_module:

        @hidet.script
        def launch():
            attrs.func_kind = 'public'

            a = tensor('default', 'float32', shape=[2, 3, 4, 5])
            indices = [0, 1, 2, 3]
            updated_indices = [indices[i] if i in dims else 0 for i in range(len(indices))]
            a[updated_indices] = 1.0

            updated_indices = [indices[i] if i not in dims else 0 for i in range(len(indices))]
            a[updated_indices] = 2.0

    cm = script_module.build()
    cm()

IRModule:

def launch()
    # func_kind: public
    declare a: tensor(float32, [2, 3, 4, 5])
    a[0, 0, 2, 3] = 1.0f
    a[0, 1, 0, 0] = 2.0f

@yaoyaoding yaoyaoding merged commit cfd2ff9 into hidet-org:main May 29, 2023
@yaoyaoding yaoyaoding deleted the if-then-else branch May 29, 2023 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant