lcompilers / lc

C++ compiler
MIT License
26 stars 7 forks source link

Adding `xt::reshape` like `reshape` intrinsic in Fortran #44

Open czgdp1807 opened 10 months ago

czgdp1807 commented 10 months ago

So here is one thing I noticed in xtensor. xtensor has no intrinsic like reshape. reshape intrinsic in Fortran doesn't modify the input array but creates a new array with the shape specified in second argument. It has no restrictions like the new array must have same rank as the input array. The only restriction it has is that the shape argument must be of fixed size. xtensor has a method called, .reshape but it modifies the array/tensor itself. Doesn't behave like reshape in Fortran. Also it has the restriction that the new shape must be of same size as the rank of input array (obviously because it is modifying the input array). xtensor has xt::reshape_view which comes close to reshape but again it just shallow copies and doesn't work like reshape at all. If you try to use it like reshape intrinsic it won't be compiled by clang/gcc. @certik So would it be possible to discuss with xtensor team to add an intrinsic like, xt::reshape which would accept two arguments. First one, xt::xtensor or xt::xtensor_fixed or xt::array- the input array. Second one, would be an xt::xtensor_fixed or {...} (array constant in C++). And return xt::xtensor object? We will be able to port tests like, integration_tests/arrays_reshape_14.f90 from LFortran?

https://github.com/xtensor-stack/xtensor/issues/2760

certik commented 10 months ago

Yes, go ahead and open up an issue at xtensor to discuss this.

I don't think we need to have exactly the same reshape function though.

czgdp1807 commented 10 months ago

Opened an issue in xtensor.

czgdp1807 commented 10 months ago

https://github.com/xtensor-stack/xtensor/issues/2760