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

Promote all values before constructing types? #25

Closed
singularitti opened this issue Feb 22, 2023 · 2 comments · Fixed by #26
Closed

Promote all values before constructing types? #25

singularitti opened this issue Feb 22, 2023 · 2 comments · Fixed by #26

Comments

@singularitti
Copy link
Member

For example, in the following code:

e = EngineeringStrain([j == 1 ? 0.005 : 0 for j in 1:6]);

julia> eltype(e)
Real

e will have Real as its element type, not Float64. However, Real is not a bits type:

julia> isbitstype(Real)
false

which will cause the following error when setting indices:

julia> e[2] = 1
ERROR: setindex!() with non-isbitstype eltype is not supported by StaticArrays. Consider using SizedArray.
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] setindex!
   @ ~/.julia/packages/StaticArrays/pTgFe/src/MArray.jl:39 [inlined]
 [3] setindex!(A::EngineeringStrain{Real}, v::Int64, i::Int64)
   @ LinearElasticityBase ~/.julia/dev/LinearElasticityBase/src/types.jl:79

So we must promote the element type before constructing any of EngineeringStrain, etc.

@singularitti
Copy link
Member Author

We need to add promote in the following line.

@singularitti
Copy link
Member Author

singularitti added a commit that referenced this issue Feb 22, 2023
singularitti added a commit to MineralsCloud/LinearElasticity.jl that referenced this issue Feb 22, 2023
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 a pull request may close this issue.

1 participant