I have a function coded for “normal”
1:n axes that
- takes a matrix,
- does some manipulation, including slices, LU, etc,
- gets a vector.
I want to generalize this to work with arrays of custom indexes (eg
OffsetArray), with the following in mind: it should only work for matrices which have the same
axes along both dimensions, and then use this to “wrap” the resulting vector. I just don’t know how to generalize this — the trick that I am missing is that in general I don’t know the constructor for the general array type.
Perhaps I should use a modifying version of
similar? But then I would have to calculate result types.
using LinearAlgebra, OffsetArrays op_internal(A::AbstractMatrix) = normalize(vcat(A[end, 1:(end-1)], one(eltype(A))), 1) function op(A) if Base.has_offset_axes(A) axes(A, 1) == axes(A, 2) || error("matrix not square") ## FIXME --- how to extract A as a matrix for op_internal, then wrap the result? else op_internal(A) end end O = ones(3, 3) .* 2 op(O) # works # below: missing code, want OffsetArray([0.4, 0.4, 0.2], 2:4) op(OffsetArray(O, 2:4, 2:4))