Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.+ operator fails when substitute() with fold=true #1433

Open
RobbesU opened this issue Feb 8, 2025 · 0 comments
Open

.+ operator fails when substitute() with fold=true #1433

RobbesU opened this issue Feb 8, 2025 · 0 comments

Comments

@RobbesU
Copy link

RobbesU commented Feb 8, 2025

.+ operator throws an error when substituteing a symbolic equation containing (only?) .+ and with fold=true.
Example below: All equations work apart from a1b, which fails with

MethodError: no method matching +(::Vector{Float64}, ::Float64)
For element-wise addition, use broadcasting with dot syntax: array .+ scalar
The function `+` exists, but no method is defined for this combination of argument types.

And oddly, f3 which also contains .+ but preceded with a .* does work!
and, as in f4, if specifying the variable as being of length c[1:3] it also works, but folds irrespective of the fold= flag.

Example:

a0 = [1., 2.25, 3.]
b0 = 1.

@variables a b c[1:3] # `a` fails in .+ when folding
f1 = 2a .+ b
f2 = 2a .* b
f3 = 2a .* b .+ a
f4 = 2c .+ b

a1a = substitute( f1, Dict([a=>a0, b=>b0]); fold=false)  
# this works # 1 + 2[1.0, 2.25, 3.0]	
a1b = substitute( f1, Dict([a=>a0, b=>b0]); fold=true)  
# this fails      
	
a2a = substitute( f2, Dict([a=>a0, b=>b0]); fold=false)  
# this works   # [2.0, 4.5, 6.0][Base.OneTo(3)]
a2b = substitute( f2, Dict([a=>a0, b=>b0]); fold=true)   
# this works   # [2.0, 4.5, 6.0][Base.OneTo(3)]
	
a3a = substitute( f3, Dict([a=>a0, b=>b0]); fold=false)  
# this works  # [1.0, 2.25, 3.0] + 2[1.0, 2.25, 3.0]*1
a3b = substitute( f3, Dict([a=>a0, b=>b0]); fold=true)   
# this works   # [3.0, 6.75, 9.0][Base.OneTo(3)]
	
a4b = substitute( f4, Dict([c=>a0, b=>b0]); fold=false)   
# this works but folds  # [3.0, 5.5, 7.0][Base.OneTo(3)]
a4b = substitute( f4, Dict([c=>a0, b=>b0]); fold=true)   
# this works   # [3.0, 5.5, 7.0][Base.OneTo(3)]
		
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

No branches or pull requests

1 participant