Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array concatenations produce unexpected results #924

Open
andreasvarga opened this issue Nov 3, 2023 · 1 comment
Open

Array concatenations produce unexpected results #924

andreasvarga opened this issue Nov 3, 2023 · 1 comment

Comments

@andreasvarga
Copy link

The following illustrates the issue:

julia> f = Fun(Fourier(), [1,2,3,4])
Fun(Fourier(【0.0,6.283185307179586❫), [1, 2, 3, 4])

julia> g = Fun(Fourier(), [1,0,0,4])
Fun(Fourier(【0.0,6.283185307179586❫), [1, 0, 0, 4])

julia> Af = [f g]
Fun(1×2 ArraySpace:
ApproxFunBase.SumSpace{Tuple{CosSpace{PeriodicSegment{Float64}, Float64}, SinSpace{PeriodicSegment{Float64}, Float64}}, PeriodicSegment{Float64}, Float64}[Fourier(【0.0,6.283185307179586❫) Fourier(【0.0,6.283185307179586❫)], [1, 2, 1, 0, 3, 4, 0, 4])

julia> [Af Af]
1×2 Matrix{Fun{ApproxFunBase.ArraySpace{ApproxFunBase.SumSpace{Tuple{CosSpace{PeriodicSegment{Float64}, Float64}, SinSpace{PeriodicSegment{Float64}, Float64}}, PeriodicSegment{Float64}, Float64}, 2, PeriodicSegment{Float64}, Float64, Matrix{ApproxFunBase.SumSpace{Tuple{CosSpace{PeriodicSegment{Float64}, Float64}, SinSpace{PeriodicSegment{Float64}, Float64}}, PeriodicSegment{Float64}, Float64}}}, Int64, Vector{Int64}}}:
 Fun(1×2 ArraySpace:
SumSpace{Tuple{CosSpace{PeriodicSegment{Float64}, Float64}, SinSpace{PeriodicSegment{Float64}, Float64}}, PeriodicSegment{Float64}, Float64}[Fourier(【0.0,6.283185307179586❫) Fourier(【0.0,6.283185307179586❫)], [1, 2, 1, 0, 3, 4, 0, 4])  …  Fun(1×2 ArraySpace:
SumSpace{Tuple{CosSpace{PeriodicSegment{Float64}, Float64}, SinSpace{PeriodicSegment{Float64}, Float64}}, PeriodicSegment{Float64}, Float64}[Fourier(【0.0,6.283185307179586❫) Fourier(【0.0,6.283185307179586❫)], [1, 2, 1, 0, 3, 4, 0, 4])

julia> [Af; Af]
Fun(2-element ArraySpace:
ApproxFunBase.ArraySpace{ApproxFunBase.SumSpace{Tuple{CosSpace{PeriodicSegment{Float64}, Float64}, SinSpace{PeriodicSegment{Float64}, Float64}}, PeriodicSegment{Float64}, Float64}, 2, PeriodicSegment{Float64}, Float64, Matrix{ApproxFunBase.SumSpace{Tuple{CosSpace{PeriodicSegment{Float64}, Float64}, SinSpace{PeriodicSegment{Float64}, Float64}}, PeriodicSegment{Float64}, Float64}}}[1×2 ArraySpace:
ApproxFunBase.SumSpace{Tuple{CosSpace{PeriodicSegment{Float64}, Float64}, SinSpace{PeriodicSegment{Float64}, Float64}}, PeriodicSegment{Float64}, Float64}[Fourier(【0.0,6.283185307179586❫) Fourier(【0.0,6.283185307179586❫)], 1×2 ArraySpace:
ApproxFunBase.SumSpace{Tuple{CosSpace{PeriodicSegment{Float64}, Float64}, SinSpace{PeriodicSegment{Float64}, Float64}}, PeriodicSegment{Float64}, Float64}[Fourier(【0.0,6.283185307179586❫) Fourier(【0.0,6.283185307179586❫)]], [1, 2, 1, 0, 1, 2, 1, 0, 3, 4, 0, 4, 3, 4, 0, 4])

[Af Af] is hcat(Af,Af) and I would expect to produce a Fun(1×4 ArraySpace:..., while [Af; Af] is vcat(Af,Af) and I expect to produce a Fun(2×2 ArraySpace:..., as would result using concatenations of usual matrices. In both cases, arrays of matrices are generated, but I need to build the horizonatally or vertically concatenated matrices.

I appologize if I am wrong, and I would appreciate any hint how to obtain the (for me) expected results.

@andreasvarga
Copy link
Author

The following is a possible fix to the above problems:

julia> Fun(t -> [Af(t) Af(t)],Fourier())
Fun(1×4 ArraySpace:
ApproxFunBase.SumSpace{Tuple{CosSpace{PeriodicSegment{Float64}, Float64}, SinSpace{PeriodicSegment{Float64}, Float64}}, PeriodicSegment{Float64}, Float64}[Fourier(【0.0,6.283185307179586❫) Fourier(【0.0,6.283185307179586❫) Fourier(【0.0,6.283185307179586❫) Fourier(【0.0,6.283185307179586❫)], [1.0, 2.0, 1.0, -1.49908e-16, 1.0, 2.0, 1.0, -1.49908e-16, 3.0, 4.0, -4.7375e-16, 4.0, 3.0, 4.0, -4.7375e-16, 4.0])

julia> Fun(t -> [Af(t); Af(t)],Fourier())
Fun(2×2 ArraySpace:
ApproxFunBase.SumSpace{Tuple{CosSpace{PeriodicSegment{Float64}, Float64}, SinSpace{PeriodicSegment{Float64}, Float64}}, PeriodicSegment{Float64}, Float64}[Fourier(【0.0,6.283185307179586❫) Fourier(【0.0,6.283185307179586❫); Fourier(【0.0,6.283185307179586❫) Fourier(【0.0,6.283185307179586❫)], [1.0, 2.0, 1.0, 2.0, 1.0, -1.49908e-16, 1.0, -1.49908e-16, 3.0, 4.0, 3.0, 4.0, -4.7375e-16, 4.0, -4.7375e-16, 4.0])

However, I realize that a more elaborate implementation of hcat and vcat is probably necessary.

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

No branches or pull requests

1 participant