Skip to content

Results of concatenating an offset array #326

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

Closed
KeithWM opened this issue Feb 20, 2023 · 2 comments
Closed

Results of concatenating an offset array #326

KeithWM opened this issue Feb 20, 2023 · 2 comments

Comments

@KeithWM
Copy link

KeithWM commented Feb 20, 2023

Hi there,

I'm using OffsetArrays in image manipulation, and I've come across something where the behaviour of an OffsetArray is a bit disappointing. When concatenating a vector to the end (or beginning) of an offset matrix, I expect this to still return an OffsetArray.

oa = OffsetArrays.OffsetArray([1 2; 3 4], -1:0, 3:4)
hcat(oa, oa[:, begin]) |> axes  # (Base.OneTo(2), Base.OneTo(3))

I think I can get the desired behaviour by implementing

function Base.hcat(
	mat::OffsetMatrix{T, Matrix{T}}, vec::OffsetVector{T, Vector{T}}
) where {T}
	ax = axes(mat, 2)
	new_ax = first(ax):(last(ax)+1)
	content = hcat(mat.parent, vec)
	result = OffsetMatrix{T, Matrix{T}}(content, axes(mat, 1), new_ax)
end
hcat(oa, oa[:, begin]) |> axes  # (IdOffsetRange(values=-1:0, indices=-1:0), IdOffsetRange(values=3:5, indices=3:5))

Is this something worth implementing? It would also have to be done for hcat(vec, mat) and both vcat options. What do you think?

@jishnub
Copy link
Member

jishnub commented Feb 21, 2023

See JuliaLang/julia#37629

@KeithWM
Copy link
Author

KeithWM commented Feb 21, 2023

Thanks. Obviously I did a poor job of researching whether this issue was already known. My apologies. Keep up the good work all!

@KeithWM KeithWM closed this as not planned Won't fix, can't repro, duplicate, stale Feb 21, 2023
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

2 participants