Skip to content

Commit

Permalink
simplify and upstream to AccessorsExtra
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin committed Dec 18, 2024
1 parent a4ab065 commit 0000000
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
7 changes: 5 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
name = "AccessibleOptimization"
uuid = "d88a00a0-4a21-4fe4-a515-e2123c37b885"
authors = ["Alexander Plavin <alexander@plav.in>"]
version = "0.1.2"
version = "0.1.3"

[deps]
AccessorsExtra = "33016aad-b69d-45be-9359-82a41f556fd4"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
DataPipes = "02685ad9-2d12-40c3-9f73-c6aeda6a7ff5"
FlexiMaps = "6394faf6-06db-4fa8-b750-35ccc60383f7"
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
AccessorsExtra = "0.1.43"
AccessorsExtra = "0.1.89"
ConstructionBase = "1.5.1"
DataPipes = "0.3.5"
FlexiMaps = "0.1.27"
Optimization = "3,4"
Reexport = "1.2.2"
Statistics = "1"
julia = "1.6"
24 changes: 7 additions & 17 deletions src/AccessibleOptimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using Reexport
@reexport using Optimization
@reexport using AccessorsExtra
using DataPipes
using FlexiMaps
using ConstructionBase
using Statistics: mean

Expand All @@ -29,31 +30,20 @@ _intbound(o) = nothing
optic(v::OptArgs) = AccessorsExtra.ConcatOptics(map(_optic, v.specs))

rawu(x0, v::OptArgs) = getall(x0, optic(v))
fromrawu(u, x0, v::OptArgs) = setall(x0, optic(v), u)
rawu(x0::Type, v::OptArgs) = @p v.specs |> map(_intbound) |> map(mean)

fromrawu(u, x0, v::OptArgs) = AccessorsExtra.setall_or_construct(x0, optic(v), u)

rawfunc(f, x0, v::OptArgs) = (u, p) -> f(fromrawu(u, x0, v), p)
rawbounds(x0, v::OptArgs, AT=nothing) =
if @p v.specs |> any(isnothing(_intbound(_)))
@assert @p v.specs |> all(isnothing(_intbound(_)))
return ()
else
@p let
v.specs
map(fill(_intbound(_), length(getall(x0, _optic(_)))))
reduce(vcat)
(lb=_convert(AT, minimum.(__)), ub=_convert(AT, maximum.(__)))
end
end

rawu(x0::Type, v::OptArgs) = @p v.specs |> map(_intbound) |> map(mean)
fromrawu(u, x0::Type, v::OptArgs) = @p map(_optic(_1) => _2, v.specs, u) |> construct(x0, __...)
rawbounds(x0::Type, v::OptArgs, AT=nothing) =
rawbounds(x0, v::OptArgs, AT=nothing) =
if @p v.specs |> any(isnothing(_intbound(_)))
@assert @p v.specs |> all(isnothing(_intbound(_)))
return ()
else
@p let
v.specs
map(_intbound(_))
flatmap(fill(_intbound(_), AccessorsExtra.nvals_optic(x0, _optic(_))))
(lb=_convert(AT, minimum.(__)), ub=_convert(AT, maximum.(__)))
end
end
Expand Down

4 comments on commit 0000000

@aplavin
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@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/121605

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.1.3 -m "<description of version>" 000000004900bc9921cb09209d5c05cd322db54c
git push origin v0.1.3

@aplavin
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@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 updated: JuliaRegistries/General/121605

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.1.3 -m "<description of version>" 000000004900bc9921cb09209d5c05cd322db54c
git push origin v0.1.3

Please sign in to comment.