Skip to content

Commit

Permalink
de-duplicates per default, remove drop_duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
lungben committed Aug 5, 2021
1 parent 419d890 commit dc61375
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Curves"
uuid = "9bed79ab-e35b-4b7a-8527-918872a9571e"
authors = ["Benjamin Lungwitz <[email protected]>"]
version = "0.2.8"
version = "0.3.0"

[deps]
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
Expand Down
4 changes: 4 additions & 0 deletions src/Curves.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ Valid choices for ˋextrapolationˋ are:
* ˋEtpLine()ˋ, corresponds to Interpolation.jl ˋLine()ˋ
If the curve consists only of a single point, always constant extrapolation is used.
* `sort=true`: per default, the input points are sorted and duplicate x-values are removed. `sort=true` is unsafe and intended to be used for Curves.jl internal operations only, where it can be guaranteed that the points are sorted and not duplicate.
"""
function Curve(x:: AbstractVector, y:: AbstractVector;
method=ItpLinear(), extrapolation=EtpFlat(), logx=false, logy=false, sort=true)
Expand All @@ -85,6 +88,7 @@ function Curve(x:: AbstractVector, y:: AbstractVector;
return Curve(x, y, nothing, logx, logy)
else
if sort
x, y = uniquexy(x, y)
perm = sortperm(x)
x = x[perm]
y = y[perm]
Expand Down
20 changes: 2 additions & 18 deletions src/curve_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,6 @@ Merges two pairs of arrays x, y into a combined (along x-values) array pair.
"""
mergexy(x1:: AbstractArray, y1:: AbstractArray, x2:: AbstractArray, y2:: AbstractArray) = vcat(x1, x2), vcat(y1, y2)

"""
drop_duplicates(c1:: Curve)
Removes duplicate x values from the curve.
Note that it is not checked if the corresponding y values are identical, just an arbitrary one is kept.
The output Curve is constructed using default settings, alternative settings can be passed to the Curve constructor
using the ˋkwargs...ˋ
"""
function drop_duplicates(c1:: Curve)
x, y = uniquexy(c1.x, c1.y)
Curve(x, y, sort=false, method=getitpm(c1), logx=c1.logx, logy=c1.logy, extrapolation=getetpm(c1))
end

"""
concat(c1:: Curve, c2:: Curve; drop_dup=true, kwargs...)
Expand All @@ -216,11 +202,9 @@ Element type is inferred by promotion. Dulicate points are dropped by default, u
The output Curve is constructed using default settings, alternative settings can be passed to the Curve constructor
using the ˋkwargs...ˋ
"""
function concat(c1:: Curve, c2:: Curve; drop_dup=true, kwargs...)
function concat(c1:: Curve, c2:: Curve; kwargs...)
x_all, y_all = mergexy(c1.x, c1.y, c2.x, c2.y)
if drop_dup
x_all, y_all = uniquexy(x_all, y_all)
end
x_all, y_all = uniquexy(x_all, y_all)
return Curve(x_all, y_all; sort=true, kwargs...)
end

Expand Down
5 changes: 3 additions & 2 deletions test/test_curves.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ c_add = +(c1, 2, logy=true)

# Merges
c1d = Curve([1, 3, 3, 7, 9], [2, 4, 4, 8, 10])
@test drop_duplicates(c1d).x == [1, 3, 7, 9]
@test c1d.x == [1, 3, 7, 9]
@test c1d.y == [2, 4, 8, 10]
@test concat(c1, c1d).x == [1, 3, 7, 9, 18, 30, 91]
@test concat(Curve(5.5, 42.1), c1) == Curve([3, 5.5, 9, 18, 30, 91], [1.01, 42.1, 1.204, 1.54, 1.81, 2.12])

# Operations on Curves
c_sum = c1+c1d
@test c_sum.x == sort(unique(hcat(c1.x, c1d.x)))
@test c_sum.x == sort(unique(vcat(c1.x, c1d.x)))

sumc1 = c1+c1
@test sumc1.y == (2*c1).y # tests correctness of result
Expand Down

2 comments on commit dc61375

@lungben
Copy link
Owner Author

@lungben lungben commented on dc61375 Aug 5, 2021

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/42221

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 v0.3.0 -m "<description of version>" dc61375a6d2a3d32ad68e5c2db35b3053e1ade6e
git push origin v0.3.0

Please sign in to comment.