Skip to content

Commit 02f5218

Browse files
giordanonsajko
andauthored
Add basic tests for some linear algebra operations (#24)
* Add basic tests for some linear algebra operations * fix for `Float32` and `Float64` As suggested by Giordano. xref #25 --------- Co-authored-by: Neven Sajko <[email protected]>
1 parent 8c43170 commit 02f5218

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/FixedSizeArrays.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,8 @@ Base.@propagate_inbounds Base.copyto!(dst::FixedSizeArray, src::FixedSizeArray)
114114
Base.@propagate_inbounds Base.copyto!(dst::FixedSizeArray, src::Memory ) = copyto2!(dst, src)
115115
Base.@propagate_inbounds Base.copyto!(dst::Memory , src::FixedSizeArray) = copyto2!(dst, src)
116116

117+
# unsafe: the native address of the array's storage
118+
119+
Base.unsafe_convert(::Type{Ptr{T}}, a::FixedSizeArray{T}) where {T} = Base.unsafe_convert(Ptr{T}, a.mem)
120+
117121
end # module FixedSizeArrays

test/runtests.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,26 @@ import Aqua
149149
end
150150
end
151151
end
152+
153+
@testset "LinearAlgebra" begin
154+
@testset "$T" for T in (Float16, Float32, Float64)
155+
v = randn(T, 8)
156+
v_fixed = FixedSizeVector(v)
157+
v_sum = @inferred v_fixed + v_fixed
158+
@test v_sum isa FixedSizeVector{T}
159+
@test v_sum v + v
160+
v_mul = @inferred v_fixed * v_fixed'
161+
@test v_mul isa FixedSizeMatrix{T}
162+
@test v_mul v * v'
163+
164+
M = randn(T, 8, 8)
165+
M_fixed = FixedSizeMatrix(M)
166+
M_sum = @inferred M_fixed + M_fixed
167+
@test M_sum isa FixedSizeMatrix{T}
168+
@test M_sum M + M
169+
M_mul = @inferred M_fixed * M_fixed
170+
@test M_mul isa FixedSizeMatrix{T}
171+
@test M_mul M * M
172+
end
173+
end
152174
end

0 commit comments

Comments
 (0)