Skip to content

Commit

Permalink
Add method Base.diff(nda::NamedDimsArray; dims) closes #195 (#209)
Browse files Browse the repository at this point in the history
* Add method `Base.diff(nda::NamedDimsArray; dims)`

* Revert "Add method `Base.diff(nda::NamedDimsArray; dims)`"

This reverts commit 651afca.

* Add method `Base.diff(nda::NamedDimsArray; dims)`

* Remove extra empty line in test/functions_math.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Avoid using unname() in diff() test in test/functions_math.jl

Co-authored-by: Glenn Moynihan <glenn.moynihan@invenialabs.co.uk>

* Bump version to 1.2.0

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Glenn Moynihan <glenn.moynihan@invenialabs.co.uk>
  • Loading branch information
3 people authored Oct 24, 2022
1 parent 5d66834 commit a016422
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NamedDims"
uuid = "356022a1-0364-5f58-8944-0da4b18d706f"
authors = ["Invenia Technical Computing Corporation"]
version = "1.1.0"
version = "1.2.0"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
5 changes: 5 additions & 0 deletions src/functions_math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ function Base.inv(nda::NamedDimsArray{L,T,2}) where {L,T}
return NamedDimsArray{names}(data)
end

function Base.diff(nda::NamedDimsArray{L}; dims) where {L}
data = diff(parent(nda); dims=dim(L, dims))
return NamedDimsArray{L}(data)
end

# Statistics
for fun in (:cor, :cov)
@eval function Statistics.$fun(a::NamedDimsArray{L,T,2}; dims=1, kwargs...) where {L,T}
Expand Down
7 changes: 7 additions & 0 deletions test/functions_math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ end
@test inv(nda) * nda NamedDimsArray{(:b, :b)}([1.0 0; 0 1])
end

@testset "diff" begin
arr = [1.0 2; 3 4]
nda = NamedDimsArray{(:a, :b)}(arr)
@test diff(nda; dims=:a) == diff(arr; dims=1)
@test typeof(diff(nda; dims=:a)) == typeof(nda)
@test diff(nda; dims=:b) == diff(nda; dims=2)
end

@testset "cov/cor" begin
@testset "symmetric_names" begin
Expand Down

4 comments on commit a016422

@mjp98
Copy link
Member Author

@mjp98 mjp98 commented on a016422 Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Register Failed
@mjp98, it looks like you are not a publicly listed member/owner in the parent organization (invenia).
If you are a member/owner, you will need to change your membership to public. See GitHub Help

@mjp98
Copy link
Member Author

@mjp98 mjp98 commented on a016422 Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/70944

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.2.0 -m "<description of version>" a01642200a3ecd6a421d1f2295d86b3fb0bce5a7
git push origin v1.2.0

Please sign in to comment.