Thanks to visit codestin.com
Credit goes to github.com

Skip to content

How to declare a local array #5

Closed
@certik

Description

@certik

The requirement is that it works with CPython and NumPy, but also compiles using LPython. One option is:

def main():
    a: f32[10000] = numpy.empty(10000, dtype=numpy.float32)
    b: f32[10000] = numpy.empty(10000, dtype=numpy.float32)
    c: f32[10000] = numpy.empty(10000, dtype=numpy.float32)
    scalar: f32
    i: i32
    nsize: i32
    scalar = 10
    nsize = size(a)
    for i in range(nsize): # type: parallel
        a[i] = 5
        b[i] = 5
    triad(a, b, scalar, c)
    print("End Stream Triad")

So the syntax is:

    a: f32[10000] = numpy.empty(10000, dtype=numpy.float32)

But this is redundant, as the size 10000 is repeated twice and the type f32 and numpy.float32 is also repeated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    numpyBugs and feature requests regarding NumPy support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions