Skip to content

Commit 74beaae

Browse files
authored
Merge pull request #26 from MineralsCloud:promote
Promote before constructing
2 parents 16a86ef + 7aa4475 commit 74beaae

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/types.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,20 @@ end
4949
# Constructors
5050
for T in (:EngineeringStress, :EngineeringStrain)
5151
@eval begin
52-
$T(data::AbstractVector) = $T(MVector{6}(data))
53-
$T(values...) = $T(vec(values))
52+
$T(data::AbstractVector) = $T(MVector{6}(promote(data...)))
53+
$T(values...) = $T(collect(values))
5454
end
5555
end
5656
for (T, N) in
5757
zip((:TensorStress, :TensorStrain, :StiffnessMatrix, :ComplianceMatrix), (3, 3, 6, 6))
5858
@eval begin
59-
$T(data::AbstractMatrix{S}) where {S} = $T{S}(MMatrix{$N,$N}(data))
59+
$T(data::AbstractMatrix{S}) where {S} = $T{S}(MMatrix{$N,$N}(promote(data...)))
6060
$T(values...) = $T(SymmetricSecondOrderTensor{$N}(values...))
6161
end
6262
end
6363
for T in (:StiffnessTensor, :ComplianceTensor)
6464
@eval $T(data::AbstractArray{S,4}) where {S} =
65-
$T{S}(SymmetricFourthOrderTensor{3}(data))
65+
$T{S}(SymmetricFourthOrderTensor{3}(promote(data...)))
6666
end
6767

6868
Base.size(::Type{<:TensorVariable}) = (3, 3)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using LinearElasticityBase
22
using Test
33

44
@testset "LinearElasticityBase.jl" begin
5+
include("types.jl")
56
include("similar.jl")
67
include("operations.jl")
78
include("invariants.jl")

test/types.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@testset "Promote all values before constructing types (#25)" begin
2+
e = EngineeringStrain([j == 1 ? 0.005 : 0 for j in 1:6])
3+
@test eltype(e) == Float64
4+
e = EngineeringStrain([j == 1 ? 1//2 : 0 for j in 1:6])
5+
@test eltype(e) == Rational{Int}
6+
end

0 commit comments

Comments
 (0)