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

SVector construction not working when the input is Int32 #1189

Closed
ducanh-le opened this issue Jul 26, 2023 · 3 comments
Closed

SVector construction not working when the input is Int32 #1189

ducanh-le opened this issue Jul 26, 2023 · 3 comments

Comments

@ducanh-le
Copy link

ducanh-le commented Jul 26, 2023

Hello,
When trying to improve the performance of my program, I changed all of my variables and input data from Int to Int32. After doing so, I encountered an error with the SVector construction method:

neededResource = usedResource .+ SVector{md.nbM, Int32}(md.r[md.ct[v]][a])

The error description:

ERROR: TypeError: in typeassert, expected Tuple{Vararg{Union{StaticArraysCore.Dynamic, Int64}}}, got a value of type Tuple{Int32}
Stacktrace:
[1] Size
@ ~/.julia/packages/StaticArraysCore/U2Z1K/src/StaticArraysCore.jl:464 [inlined]
[2] Size(s::Type{Tuple{40}})
@ StaticArraysCore ~/.julia/packages/StaticArraysCore/U2Z1K/src/StaticArraysCore.jl:470
[3] Size(#unused#::Type{SVector{40, Int32}})
@ StaticArraysCore ~/.julia/packages/StaticArraysCore/U2Z1K/src/StaticArraysCore.jl:492
[4] length(a::Type{SVector{40, Int32}})
@ StaticArrays ~/.julia/packages/StaticArrays/9KYrc/src/abstractarray.jl:2
[5] convert(#unused#::Type{SVector{40, Int32}}, a::Vector{Int32})
@ StaticArrays ~/.julia/packages/StaticArrays/9KYrc/src/convert.jl:200
[6] StaticArray
@ ~/.julia/packages/StaticArrays/9KYrc/src/convert.jl:174 [inlined]
[7] resourceAvailable(v::Int32, a::Int32, s::Solution, t::Int32, md::ModelData)
@ Main ~/stage-ONERA/model-metaheuristic/GreedyHeuristic.jl:23

How to get rid of this error when using Int32 please?

@mateuszbaran
Copy link
Collaborator

Hi,
AFAIK sizes need to be Int64. It shouldn't be too much of a problem though because they are used primarily at compilation time.

@mateuszbaran
Copy link
Collaborator

This: SVector{md.nbM, Int32}(md.r[md.ct[v]][a]) is likely suboptimal. If md.nbM can't be constant-propagated (and almost surely it can't), there will be a lot of dynamic conversions and dispatch. You need to carefully profile it to see if this isn't slower than just using Vector.

@ducanh-le
Copy link
Author

Hi, AFAIK sizes need to be Int64. It shouldn't be too much of a problem though because they are used primarily at compilation time.

You are right, this solved the problem:

nbM::Int = md.nbM
SVector{nbM, Int32}(md.r[md.ct[v]][a])

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

2 participants