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

Deprecate ==, etc., add isequivalent & #12

Merged
merged 3 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export TensorStress,
EngineeringStress,
EngineeringStrain,
ComplianceMatrix,
StiffnessMatrix
StiffnessMatrix,
isequivalent,

abstract type Stress{T,N} <: AbstractArray{T,N} end
abstract type Strain{T,N} <: AbstractArray{T,N} end
Expand Down Expand Up @@ -91,17 +93,17 @@ for T in (:TensorStress, :TensorStrain)
@eval Base.similar(A::$T, ::Type{S}) where {S} = $T(Matrix{S}(undef, size(A)))
end

# See https://discourse.julialang.org/t/how-to-compare-two-vectors-whose-elements-are-equal-but-their-types-are-not-the-same/
# See https://discourse.julialang.org/t/how-to-compare-two-vectors-whose-elements-are-equal-but-their-types-are-not-the-same/94309/6
for (S, T) in (
(:EngineeringStress, :EngineeringStrain),
(:TensorStress, :TensorStrain),
(:StiffnessTensor, :ComplianceTensor),
(:StiffnessMatrix, :ComplianceMatrix),
)
for op in (:(==), :isequal, :isapprox)
@eval begin
Base.$op(s::$S, t::$T) = false
Base.$op(t::$T, s::$S) = false
end
@eval begin
isequivalent(s::$S, t::$T) = false
isequivalent(t::$T, s::$S) = isequivalent(s, t)
end
end
isequivalent(x, y) = x == y # Fallback
const ⩵ = isequivalent
4 changes: 1 addition & 3 deletions test/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
@testset "Test equality" begin
@test EngineeringStrain(1:6) == EngineeringStrain(1:6)
@test EngineeringStrain(1:6) !== EngineeringStrain(1:6)
@test EngineeringStrain(1:6) != EngineeringStress(1:6) # Different types
@test !(EngineeringStrain(1:6) EngineeringStress(1:6)) # Different types
@test EngineeringStrain(1:6) !== EngineeringStrain(float(1:6))
@test !isequal(EngineeringStrain(1:6), EngineeringStress(1:6)) # Different types
@test EngineeringStrain(1:6) ≉ EngineeringStress(1:6) # Different types
end