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

Support diff #103

Open
fredcallaway opened this issue Mar 3, 2022 · 1 comment
Open

Support diff #103

fredcallaway opened this issue Mar 3, 2022 · 1 comment

Comments

@fredcallaway
Copy link

e.g.

x = KeyedArray(rand(10, 20), x=1:10, y=1:20)
diff(x; dims=:x)

Currently, diff(x; dims=1) errors because diff changes the size of the array. There is some ambiguity about the correct way to handle keys in the result. In some strict sense, the keys should be something like "Δ(1, 2)". But I think the most natural/useful thing would probably be to just use the lower label (so, drop 10).

@takbal
Copy link

takbal commented Mar 6, 2022

I use this:

function Base.diff(K::KeyedArray; dims, removefirst::Bool=true)

    range = removefirst ? (2:size(K, dims)) : (1:size(K,dims)-1)
    out = similar(selectdim(K, dims, range) )
    out[:] = Base.diff(parent(parent(K)); dims=NamedDims.dim(parent(K),dims))
    return out
end

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