JuliaApproximation / QuasiArrays.jl

A package for representing quasi-arrays
MIT License
12 stars 2 forks source link

Add new index styles #104

Open putianyi889 opened 3 months ago

putianyi889 commented 3 months ago

Since quasiarrays use non-classical indexing, IndexStyle should not fall back to IndexCartesian which assumes continuous integer indexing.

The index style of a quasiarray could be like IndexHybrid{IndexStyle(axes1),IndexStyle(axes2),...}. The index style of a general axes is IndexSet{typeof(union(axes))}. For example, IndexStyle(::ChebyshevU) = IndexHybrid{IndexSet{ChebyshevInterval},IndexInfLinear}.

By defining index styles, concatenation and set operations can be well defined. A concatenation over IndexInfLinear assumes interlacing. A concatenation over IndexSet assumes overlay. Adding or taking average in the intersecion is not generic as + is not defined for some types.

If one wants piecewise function, one can define IndexElementSet that allows splicing sets.

dlfivefifty commented 3 months ago

I'm not entirely convinced about using IndexStyle for concatenation but a specialised ConcatStyle(axis) would be a great solution! This would be like BroadcastStyle where different ConcatStyles could be combined. Eg we have

  1. AppendConcatStyle. This is the current default.
  2. BlockConcatStyle this is for block arrays
  3. InfConcatStyle for infinite axes
  4. ConcatStyle(::InfStyle, ::InfStyle) = BlockInterlaceConcatStyle()?
  5. UnionConcatStyle for Inclusion?

I think the last one would somehow correspond to UnionVcat and UnionHcat, but where we some over the arguments. Eg UnionVcat would handle both piecewise and sums as in:

T = chebyshevt(0..2)
U = chebyshevu(1..3)
f = expand(T, exp)
g = expand(U, cos)
h = [f; g] # since concat style of `axes(f,1)` and `axes(g,1)` are `UnionConcatStyle` this makes a `UnionVcat`
@test h[0.1] == f[0.1]
@test h[1.1] == f[1.1] + g[1.1]
@test h[2.1] == g[2.1]

For basis we have UnionHcat:

H = [T U] # since concat style of `axes(T,1)` and `axes(T,1)` are `UnionConcatStyle` this makes a `UnionHcat`. But since `axes(T,2)` and `axes(U,2)` are `InfConcatStyle` this block-interlaces

@test H[0.1, Block(2)] == [T[0.1,2],0]
@test H[1.1, Block(2)] == [T[1.1,2],U[1.1,2]]
@test H[2.1, Block(2)] == [0,U[2.1,2]]

Note in this setup h could be re-expanded in H:

@test h == H * BlockBroadcastArray(vcat, unitblocks(coefficients(f)), unitblocks(coefficients(g)))

Probably more thought would be needed whether this relationship between UnionVcat and UnionHcat actually makes sense...