Open certik opened 1 year ago
The following seems to work:
from lpython import f32
from numpy import empty, float32
def main():
a: f32[3] = empty(3, dtype=float32)
b: f32[3] = empty(3, dtype=float32)
a[0] = f32(1)
a[1] = f32(2)
a[2] = f32(3)
b = a
# b[:] = a[:]
print(a, b)
main()
We need to support b[:] = a[:]
I checked this in LFortran:
program name
implicit none
integer:: x(2) = [1,2]
integer:: y(2)
y(:) = x(:)
print *, x, y
end program name
$ lfortran examples/expr2.f90
1 2
0 0
$ gfortran examples/expr2.f90 && ./a.out
1 2 1 2
It seems both have the same issue .i.e., ArraySection
is replaced to Associate
in array_op
pass:
(=
(ArraySection
(Var 2 y)
[((ArrayBound
(Var 2 y)
(IntegerConstant 1 (Integer 4))
(Integer 4)
LBound
(IntegerConstant 1 (Integer 4))
)
(ArrayBound
(Var 2 y)
(IntegerConstant 1 (Integer 4))
(Integer 4)
UBound
(IntegerConstant 2 (Integer 4))
)
(IntegerConstant 1 (Integer 4)))]
(Array
(Integer 4)
[(()
())]
DescriptorArray
)
()
)
(ArraySection
(Var 2 x)
[((ArrayBound
(Var 2 x)
(IntegerConstant 1 (Integer 4))
(Integer 4)
LBound
(IntegerConstant 1 (Integer 4))
)
(ArrayBound
(Var 2 x)
(IntegerConstant 1 (Integer 4))
(Integer 4)
UBound
(IntegerConstant 2 (Integer 4))
)
(IntegerConstant 1 (Integer 4)))]
(Array
(Integer 4)
[(()
())]
DescriptorArray
)
()
)
()
)
After arrayop pass
(=>
(Var 2 __libasr__created__var__0__array_section_pointer_)
(ArraySection
(Var 2 x)
[((ArrayBound
(Var 2 x)
(IntegerConstant 1 (Integer 4))
(Integer 4)
LBound
(IntegerConstant 1 (Integer 4))
)
(ArrayBound
(Var 2 x)
(IntegerConstant 1 (Integer 4))
(Integer 4)
UBound
(IntegerConstant 2 (Integer 4))
)
(IntegerConstant 1 (Integer 4)))]
(Array
(Integer 4)
[(()
())]
DescriptorArray
)
()
)
)
program name
implicit none
integer:: x(2) = [1,2]
integer:: y(2)
y = x(:)
print *, x, y
end program name
LFortran
$ lfortran examples/expr2.f90
1 2
0 0
@czgdp1807, I came across this: https://github.com/lcompilers/lpython/issues/1599#issuecomment-1621157646 issue again in LFortran! Why do we replace the assignment statement to associate? Do I miss anything? Should this be handled in some other pass?
gives: