Skip to content

Commit

Permalink
Merge commit 'ccfdc13cbaad4d52a64633b672376f815583f21f' into value-no…
Browse files Browse the repository at this point in the history
…thing
  • Loading branch information
simsurace committed Feb 6, 2024
2 parents d65911b + ccfdc13 commit 40f8641
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 41 deletions.
34 changes: 2 additions & 32 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,12 @@ jobs:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
- x86
exclude:
# Test 32-bit only on Linux
- os: macOS-latest
arch: x86
- os: windows-latest
arch: x86
include:
# Add a 1.5 job because that's what Invenia actually uses
- os: ubuntu-latest
version: 1.5
arch: x64
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
arch: x64
- uses: actions/cache@v2
env:
cache-name: cache-artifacts
Expand All @@ -58,22 +44,6 @@ jobs:
with:
file: lcov.info

slack:
name: Notify Slack Failure
needs: test
runs-on: ubuntu-latest
if: always() && github.event_name == 'schedule'
steps:
- uses: technote-space/workflow-conclusion-action@v2
- uses: voxmedia/github-action-slack-notify-build@v1
if: env.WORKFLOW_CONCLUSION == 'failure'
with:
channel: nightly-rse
status: FAILED
color: danger
env:
SLACK_BOT_TOKEN: ${{ secrets.RSE_SLACK_BOT_TOKEN }}

docs:
name: Documentation
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ParameterHandling"
uuid = "2412ca09-6db7-441c-8e3a-88d5709968c5"
authors = ["Invenia Technical Computing Corporation"]
version = "0.4.8"
version = "0.4.9"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
20 changes: 12 additions & 8 deletions src/flatten.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,20 @@ function flatten(::Type{T}, x::SparseMatrixCSC) where {T<:Real}
end

function flatten(::Type{T}, x::Tuple) where {T<:Real}
x_vecs_and_backs = map(val -> flatten(T, val), x)
x_vecs, x_backs = first.(x_vecs_and_backs), last.(x_vecs_and_backs)
lengths = map(length, x_vecs)
sz = _cumsum(lengths)
vec1, back1 = flatten(T, first(x))
vec2, back2 = flatten(T, Base.tail(x))
l1 = length(vec1)
l2 = length(vec2)
function unflatten_to_Tuple(v::Vector{T})
map(x_backs, lengths, sz) do x_back, l, s
return x_back(v[(s - l + 1):s])
end
return (back1(v[1:l1]), back2(v[(l1 + 1):(l1 + l2)])...)
end
return reduce(vcat, x_vecs), unflatten_to_Tuple
return vcat(vec1, vec2), unflatten_to_Tuple
end

function flatten(::Type{T}, x::Tuple{}) where {T<:Real}
v = T[]
unflatten_to_empty_Tuple(::Vector{T}) = x
return v, unflatten_to_empty_Tuple
end

function flatten(::Type{T}, x::NamedTuple) where {T<:Real}
Expand Down
7 changes: 7 additions & 0 deletions test/flatten.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
test_flatten_interface((1.0, 2.0); check_inferred=tuple_infers)

test_flatten_interface((1.0, (2.0, 3.0), randn(5)); check_inferred=tuple_infers)

# Prevent regression of PR #67
@testset "Type stability of unflatten" begin
θ = (1.0, ((2.0, 3.0), 4.0))
x, unflatten = flatten(θ)
@test (@inferred unflatten(x)) == θ
end
end

@testset "NamedTuple" begin
Expand Down

0 comments on commit 40f8641

Please sign in to comment.