Skip to content

Commit de46330

Browse files
committed
Fix type stability of fill_similar
1 parent cd1fc0c commit de46330

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DynamicExpressions"
22
uuid = "a40a106e-89c9-4ca8-8020-a735e8728b6b"
33
authors = ["MilesCranmer <miles.cranmer@gmail.com>"]
4-
version = "0.13.0"
4+
version = "0.13.1"
55

66
[deps]
77
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"

src/Utils.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ function _add_idmap_to_call(def::Expr, id_map::Expr)
155155
return Expr(:call, def.args[1], def.args[2:end]..., id_map)
156156
end
157157

158-
@inline fill_similar(value, array, args...) = fill!(similar(array, args...), value)
158+
@inline function fill_similar(value, array, args...)
159+
out_array = similar(array, args...)
160+
fill!(out_array, value)
161+
return out_array
162+
end
159163

160164
function deprecate_varmap(variable_names, varMap, func_name)
161165
if varMap !== nothing

test/test_utils.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using DynamicExpressions
2+
using Test
23

34
operators = OperatorEnum(; binary_operators=(+, *, -, /, ^), unary_operators=(exp, sin))
45

@@ -33,3 +34,8 @@ tree = x1 + Node(; val=0.0) - sin(x2 - Node(; val=0.5))
3334
@test get_constants(tree) == [0.0, 0.5]
3435
set_constants!(tree, [1.0, 2.0])
3536
@test repr(tree) == "((x1 + 1.0) - sin(x2 - 2.0))"
37+
38+
# Ensure that fill_similar is type stable
39+
x = randn(Float32, 3, 10)
40+
@inferred fill_similar(0.5f0, x, axes(x, 1))
41+
fill_similar(0.5f0, x, axes(x, 1)) == fill(0.5f0, 3)

0 commit comments

Comments
 (0)