Skip to content

Commit

Permalink
Merge pull request #12 from MineralsCloud:isequivalent
Browse files Browse the repository at this point in the history
Deprecate `==`, etc., add `isequivalent` & `⩵`
  • Loading branch information
singularitti authored Feb 10, 2023
2 parents 2eafb33 + c239602 commit 5d20197
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
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

0 comments on commit 5d20197

Please sign in to comment.