Skip to content

Commit 4891a29

Browse files
committed
add isapprox and converts from Matrix for Mat3f-like types
1 parent a5ab6fd commit 4891a29

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/mat.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Mat{C, R, T1}(x::NTuple{L, T2}) where {C, R, L, T1, T2} = Mat{C, R, T1}(convert(
8989

9090
Mat{C, R}(x::AbstractMatrix{T}) where {C, R, T} = Mat{C, R, T}(x)
9191
Mat{C, R, T}(x::AbstractMatrix) where {C, R, T} = Mat{C, R, T}(ntuple(i-> convert(T, x[i]), C*R))
92+
Mat{C, R, T, N}(x::AbstractMatrix) where {C, R, T, N} = Mat{C, R, T}(ntuple(i-> convert(T, x[i]), C*R))
9293

9394
Base.convert(::Type{Mat{C, R, T, L}}, from::Mat{C, R}) where {C, R, T, L} = Mat{C, R, T}(from.values)
9495

@@ -220,4 +221,12 @@ end
220221
end
221222

222223
# TODO: Fix Vec(mat) becoming Vec((mat,)) (i.e. restrict eltype to Number?)
223-
(VT::Type{<: StaticVector{N}})(mat::Mat{N, 1}) where {N} = VT(mat.values)
224+
(VT::Type{<: StaticVector{N}})(mat::Mat{N, 1}) where {N} = VT(mat.values)
225+
226+
function Base.isapprox(
227+
a::Mat{R1, C1, T1}, b::Mat{R2, C2, T2};
228+
atol::Real = 0,
229+
rtol::Real = atol > 0 ? 0 : sqrt(max(eps(T1), eps(T2)))
230+
) where {R1, R2, C1, C2, T1, T2}
231+
return (R1 == R2) && (C1 == C2) && norm(a - b) <= max(atol, rtol * max(norm(a), norm(b)))
232+
end

0 commit comments

Comments
 (0)