Skip to content

Conversation

@daviehh
Copy link
Contributor

@daviehh daviehh commented Aug 18, 2025

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

current code at

function get_tmp(dc::FixedSizeDiffCache, u::Union{Number, AbstractArray})
if promote_type(eltype(dc.du), eltype(u)) <: eltype(dc.du)
dc.du
else
if length(dc.du) > length(dc.any_du)
resize!(dc.any_du, length(dc.du))
end
_restructure(dc.du, dc.any_du)
end
end

just calls

function get_tmp(dc::FixedSizeDiffCache, ::Type{T}) where {T <: Number}
if promote_type(eltype(dc.du), T) <: eltype(dc.du)
dc.du
else
if length(dc.du) > length(dc.any_du)
resize!(dc.any_du, length(dc.du))
end
_restructure(dc.du, dc.any_du)
end
end

with eltype(u), no need to write it separately?

@daviehh
Copy link
Contributor Author

daviehh commented Aug 18, 2025

(format check warnings seems to be not from this PR change but one file in the extension)

@ChrisRackauckas
Copy link
Member

don't run the formatter

This reverts commit e10c6ce.
@ChrisRackauckas
Copy link
Member

Wait why would that call the other one? I'm confused. Those dispatches are hit by different inputs.

@daviehh
Copy link
Contributor Author

daviehh commented Aug 22, 2025

current code is duplicate: the first is the same as the second with T -> eltype(u)?

function get_tmp(dc::FixedSizeDiffCache, u::Union{Number, AbstractArray})
if promote_type(eltype(dc.du), eltype(u)) <: eltype(dc.du)
dc.du
else
if length(dc.du) > length(dc.any_du)
resize!(dc.any_du, length(dc.du))
end
_restructure(dc.du, dc.any_du)
end
end
function get_tmp(dc::FixedSizeDiffCache, ::Type{T}) where {T <: Number}
if promote_type(eltype(dc.du), T) <: eltype(dc.du)
dc.du
else
if length(dc.du) > length(dc.any_du)
resize!(dc.any_du, length(dc.du))
end
_restructure(dc.du, dc.any_du)
end
end

@ChrisRackauckas
Copy link
Member

No, the first is dispatching on u being a value, the latter is if a type is given.

@daviehh
Copy link
Contributor Author

daviehh commented Aug 22, 2025

this pr just changes: when dispatched when u is a value, it just calls the 2nd function get_tmp(dc, u::Union{Number, AbstractArray}) = get_tmp(dc, eltype(u)) so the function body is not duplicated

@ChrisRackauckas
Copy link
Member

oh good point...

@ChrisRackauckas ChrisRackauckas merged commit deb294a into SciML:master Aug 23, 2025
13 of 16 checks passed
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

Successfully merging this pull request may close these issues.

2 participants