Skip to content
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
7 changes: 4 additions & 3 deletions test/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ isdefined(Main, :pruned_old_LA) || @eval Main include("prune_old_LA.jl")

using Test, LinearAlgebra

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
const BASE_TEST_PATH = joinpath(dirname(pathof(LinearAlgebra)), "..", "test")
const TESTHELPERS = joinpath(BASE_TEST_PATH, "testhelpers")

isdefined(Main, :OffsetArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "OffsetArrays.jl"))
isdefined(Main, :OffsetArrays) || @eval Main include(joinpath($TESTHELPERS, "OffsetArrays.jl"))
using .Main.OffsetArrays

isdefined(Main, :ImmutableArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "ImmutableArrays.jl"))
isdefined(Main, :ImmutableArrays) || @eval Main include(joinpath($TESTHELPERS, "ImmutableArrays.jl"))
using .Main.ImmutableArrays

@testset "Adjoint and Transpose inner constructor basics" begin
Expand Down
15 changes: 8 additions & 7 deletions test/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ isdefined(Main, :pruned_old_LA) || @eval Main include("prune_old_LA.jl")
using Test, LinearAlgebra, Random
using LinearAlgebra: BlasReal, BlasFloat

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
const BASE_TEST_PATH = joinpath(dirname(pathof(LinearAlgebra)), "..", "test")
const TESTHELPERS = joinpath(BASE_TEST_PATH, "testhelpers")

isdefined(Main, :Quaternions) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Quaternions.jl"))
isdefined(Main, :Quaternions) || @eval Main include(joinpath($TESTHELPERS, "Quaternions.jl"))
using .Main.Quaternions

isdefined(Main, :InfiniteArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "InfiniteArrays.jl"))
isdefined(Main, :InfiniteArrays) || @eval Main include(joinpath($TESTHELPERS, "InfiniteArrays.jl"))
using .Main.InfiniteArrays

isdefined(Main, :FillArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "FillArrays.jl"))
isdefined(Main, :FillArrays) || @eval Main include(joinpath($TESTHELPERS, "FillArrays.jl"))
using .Main.FillArrays

isdefined(Main, :OffsetArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "OffsetArrays.jl"))
isdefined(Main, :OffsetArrays) || @eval Main include(joinpath($TESTHELPERS, "OffsetArrays.jl"))
using .Main.OffsetArrays

isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
isdefined(Main, :SizedArrays) || @eval Main include(joinpath($TESTHELPERS, "SizedArrays.jl"))
using .Main.SizedArrays

isdefined(Main, :ImmutableArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "ImmutableArrays.jl"))
isdefined(Main, :ImmutableArrays) || @eval Main include(joinpath($TESTHELPERS, "ImmutableArrays.jl"))
using .Main.ImmutableArrays

include("testutils.jl") # test_approx_eq_modphase
Expand Down
5 changes: 3 additions & 2 deletions test/cholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ using Test, LinearAlgebra, Random
using LinearAlgebra: BlasComplex, BlasFloat, BlasReal, QRPivoted,
PosDefException, RankDeficientException, chkfullrank

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
const BASE_TEST_PATH = joinpath(dirname(pathof(LinearAlgebra)), "..", "test")
const TESTHELPERS = joinpath(BASE_TEST_PATH, "testhelpers")

isdefined(Main, :Quaternions) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Quaternions.jl"))
isdefined(Main, :Quaternions) || @eval Main include(joinpath($TESTHELPERS, "Quaternions.jl"))
using .Main.Quaternions

function unary_ops_tests(a, ca, tol; n=size(a, 1))
Expand Down
8 changes: 5 additions & 3 deletions test/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ using Test, LinearAlgebra, Random
using LinearAlgebra: BlasComplex, BlasFloat, BlasReal
using Test: GenericArray

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
isdefined(Main, :FillArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "FillArrays.jl"))
const BASE_TEST_PATH = joinpath(dirname(pathof(LinearAlgebra)), "..", "test")
const TESTHELPERS = joinpath(BASE_TEST_PATH, "testhelpers")

isdefined(Main, :FillArrays) || @eval Main include(joinpath($TESTHELPERS, "FillArrays.jl"))
import Main.FillArrays

isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
isdefined(Main, :SizedArrays) || @eval Main include(joinpath($TESTHELPERS, "SizedArrays.jl"))
using Main.SizedArrays

@testset "Check that non-floats are correctly promoted" begin
Expand Down
13 changes: 7 additions & 6 deletions test/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ isdefined(Main, :pruned_old_LA) || @eval Main include("prune_old_LA.jl")
using Test, LinearAlgebra, Random
using LinearAlgebra: BlasFloat, BlasComplex

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
const BASE_TEST_PATH = joinpath(dirname(pathof(LinearAlgebra)), "..", "test")
const TESTHELPERS = joinpath(BASE_TEST_PATH, "testhelpers")

isdefined(Main, :OffsetArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "OffsetArrays.jl"))
isdefined(Main, :OffsetArrays) || @eval Main include(joinpath($TESTHELPERS, "OffsetArrays.jl"))
using .Main.OffsetArrays

isdefined(Main, :InfiniteArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "InfiniteArrays.jl"))
isdefined(Main, :InfiniteArrays) || @eval Main include(joinpath($TESTHELPERS, "InfiniteArrays.jl"))
using .Main.InfiniteArrays

isdefined(Main, :FillArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "FillArrays.jl"))
isdefined(Main, :FillArrays) || @eval Main include(joinpath($TESTHELPERS, "FillArrays.jl"))
using .Main.FillArrays

isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
isdefined(Main, :SizedArrays) || @eval Main include(joinpath($TESTHELPERS, "SizedArrays.jl"))
using .Main.SizedArrays

isdefined(Main, :ImmutableArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "ImmutableArrays.jl"))
isdefined(Main, :ImmutableArrays) || @eval Main include(joinpath($TESTHELPERS, "ImmutableArrays.jl"))
using .Main.ImmutableArrays

const n=12 # Size of matrix problem to test
Expand Down
13 changes: 7 additions & 6 deletions test/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ using Test, LinearAlgebra, Random
using Test: GenericArray
using LinearAlgebra: isbanded

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
const BASE_TEST_PATH = joinpath(dirname(pathof(LinearAlgebra)), "..", "test")
const TESTHELPERS = joinpath(BASE_TEST_PATH, "testhelpers")

isdefined(Main, :Quaternions) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Quaternions.jl"))
isdefined(Main, :Quaternions) || @eval Main include(joinpath($TESTHELPERS, "Quaternions.jl"))
using .Main.Quaternions

isdefined(Main, :OffsetArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "OffsetArrays.jl"))
isdefined(Main, :OffsetArrays) || @eval Main include(joinpath($TESTHELPERS, "OffsetArrays.jl"))
using .Main.OffsetArrays

isdefined(Main, :DualNumbers) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "DualNumbers.jl"))
isdefined(Main, :DualNumbers) || @eval Main include(joinpath($TESTHELPERS, "DualNumbers.jl"))
using .Main.DualNumbers

isdefined(Main, :FillArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "FillArrays.jl"))
isdefined(Main, :FillArrays) || @eval Main include(joinpath($TESTHELPERS, "FillArrays.jl"))
using .Main.FillArrays

isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
isdefined(Main, :SizedArrays) || @eval Main include(joinpath($TESTHELPERS, "SizedArrays.jl"))
using .Main.SizedArrays

Random.seed!(123)
Expand Down
8 changes: 5 additions & 3 deletions test/hessenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ isdefined(Main, :pruned_old_LA) || @eval Main include("prune_old_LA.jl")

using Test, LinearAlgebra, Random

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
const BASE_TEST_PATH = joinpath(dirname(pathof(LinearAlgebra)), "..", "test")
const TESTHELPERS = joinpath(BASE_TEST_PATH, "testhelpers")

isdefined(Main, :SizedArrays) || @eval Main include(joinpath($TESTHELPERS, "SizedArrays.jl"))
using .Main.SizedArrays

isdefined(Main, :ImmutableArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "ImmutableArrays.jl"))
isdefined(Main, :ImmutableArrays) || @eval Main include(joinpath($TESTHELPERS, "ImmutableArrays.jl"))
using .Main.ImmutableArrays

# for tuple tests below
Expand Down
5 changes: 3 additions & 2 deletions test/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ using Base: rtoldefault
using Test, LinearAlgebra, Random
using LinearAlgebra: mul!, Symmetric, Hermitian

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
const BASE_TEST_PATH = joinpath(dirname(pathof(LinearAlgebra)), "..", "test")
const TESTHELPERS = joinpath(BASE_TEST_PATH, "testhelpers")

isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
isdefined(Main, :SizedArrays) || @eval Main include(joinpath($TESTHELPERS, "SizedArrays.jl"))
using .Main.SizedArrays

## Test Julia fallbacks to BLAS routines
Expand Down
6 changes: 4 additions & 2 deletions test/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ isdefined(Main, :pruned_old_LA) || @eval Main include("prune_old_LA.jl")
using Test, LinearAlgebra, Random
using LinearAlgebra: rmul!, BandIndex

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
const BASE_TEST_PATH = joinpath(dirname(pathof(LinearAlgebra)), "..", "test")
const TESTHELPERS = joinpath(BASE_TEST_PATH, "testhelpers")

isdefined(Main, :SizedArrays) || @eval Main include(joinpath($TESTHELPERS, "SizedArrays.jl"))
using .Main.SizedArrays

n= 10 #Size of matrix to test
Expand Down
6 changes: 4 additions & 2 deletions test/structuredbroadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ isdefined(Main, :pruned_old_LA) || @eval Main include("prune_old_LA.jl")

using Test, LinearAlgebra

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
const BASE_TEST_PATH = joinpath(dirname(pathof(LinearAlgebra)), "..", "test")
const TESTHELPERS = joinpath(BASE_TEST_PATH, "testhelpers")

isdefined(Main, :SizedArrays) || @eval Main include(joinpath($TESTHELPERS, "SizedArrays.jl"))
using .Main.SizedArrays

@testset "broadcast[!] over combinations of scalars, structured matrices, and dense vectors/matrices" begin
Expand Down
9 changes: 5 additions & 4 deletions test/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ isdefined(Main, :pruned_old_LA) || @eval Main include("prune_old_LA.jl")

using Test, LinearAlgebra, Random

const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
const BASE_TEST_PATH = joinpath(dirname(pathof(LinearAlgebra)), "..", "test")
const TESTHELPERS = joinpath(BASE_TEST_PATH, "testhelpers")

isdefined(Main, :Quaternions) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Quaternions.jl"))
isdefined(Main, :Quaternions) || @eval Main include(joinpath($TESTHELPERS, "Quaternions.jl"))
using .Main.Quaternions

isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
isdefined(Main, :SizedArrays) || @eval Main include(joinpath($TESTHELPERS, "SizedArrays.jl"))
using .Main.SizedArrays

isdefined(Main, :ImmutableArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "ImmutableArrays.jl"))
isdefined(Main, :ImmutableArrays) || @eval Main include(joinpath($TESTHELPERS, "ImmutableArrays.jl"))
using .Main.ImmutableArrays

Random.seed!(1010)
Expand Down
46 changes: 46 additions & 0 deletions test/testhelpers/DualNumbers.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

module DualNumbers

export Dual

# Dual numbers type with minimal interface
# example of a (real) number type that subtypes Number, but not Real.
# Can be used to test generic linear algebra functions.

struct Dual{T<:Real} <: Number
val::T
eps::T
end
Base.:+(x::Dual, y::Dual) = Dual(x.val + y.val, x.eps + y.eps)
Base.:-(x::Dual, y::Dual) = Dual(x.val - y.val, x.eps - y.eps)
Base.:*(x::Dual, y::Dual) = Dual(x.val * y.val, x.eps * y.val + y.eps * x.val)
Base.:*(x::Number, y::Dual) = Dual(x*y.val, x*y.eps)
Base.:*(x::Dual, y::Number) = Dual(x.val*y, x.eps*y)
Base.:/(x::Dual, y::Dual) = Dual(x.val / y.val, (x.eps*y.val - x.val*y.eps)/(y.val*y.val))

Base.:(==)(x::Dual, y::Dual) = x.val == y.val && x.eps == y.eps

Base.promote_rule(::Type{Dual{T}}, ::Type{T}) where {T} = Dual{T}
Base.promote_rule(::Type{Dual{T}}, ::Type{S}) where {T,S<:Real} = Dual{promote_type(T, S)}
Base.promote_rule(::Type{Dual{T}}, ::Type{Dual{S}}) where {T,S} = Dual{promote_type(T, S)}

Base.convert(::Type{Dual{T}}, x::Dual{T}) where {T} = x
Base.convert(::Type{Dual{T}}, x::Dual) where {T} = Dual(convert(T, x.val), convert(T, x.eps))
Base.convert(::Type{Dual{T}}, x::Real) where {T} = Dual(convert(T, x), zero(T))

Base.float(x::Dual) = Dual(float(x.val), float(x.eps))
# the following two methods are needed for normalize (to check for potential overflow)
Base.typemax(x::Dual) = Dual(typemax(x.val), zero(x.eps))
Base.prevfloat(x::Dual{<:AbstractFloat}) = prevfloat(x.val)

Base.abs2(x::Dual) = x*x
Base.abs(x::Dual) = sqrt(abs2(x))
Base.sqrt(x::Dual) = Dual(sqrt(x.val), x.eps/(2sqrt(x.val)))

Base.isless(x::Dual, y::Dual) = x.val < y.val
Base.isless(x::Real, y::Dual) = x < y.val
Base.isinf(x::Dual) = isinf(x.val) & isfinite(x.eps)
Base.real(x::Dual) = x # since we currently only consider Dual{<:Real}

end # module
66 changes: 66 additions & 0 deletions test/testhelpers/FillArrays.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module FillArrays

struct Fill{T, N, S<:NTuple{N,Integer}} <: AbstractArray{T,N}
value::T
size::S
end

Fill(v, size::Vararg{Integer}) = Fill(v, size)

Base.size(F::Fill) = F.size

Base.copy(F::Fill) = F

Base.AbstractArray{T,N}(F::Fill{<:Any,N}) where {T,N} = Fill(T(F.value), F.size)

@inline getindex_value(F::Fill) = F.value

@inline function Base.getindex(F::Fill{<:Any,N}, i::Vararg{Int,N}) where {N}
@boundscheck checkbounds(F, i...)
getindex_value(F)
end

@inline function Base.setindex!(F::Fill, v, k::Integer)
@boundscheck checkbounds(F, k)
v == getindex_value(F) || throw(ArgumentError("Cannot setindex! to $v for a Fill with value $(getindex_value(F))."))
F
end

@inline function Base.fill!(F::Fill, v)
v == getindex_value(F) || throw(ArgumentError("Cannot fill! with $v a Fill with value $(getindex_value(F))."))
F
end

Base.zero(F::Fill) = Fill(zero(F.value), size(F))

Base.show(io::IO, F::Fill) = print(io, "Fill($(F.value), $(F.size))")
Base.show(io::IO, ::MIME"text/plain", F::Fill) = show(io, F)

_first_or_one(t::Tuple) = t[1]
_first_or_one(t::Tuple{}) = 1

_match_size(sz::Tuple{}, inner::Tuple{}, outer::Tuple{}) = ()
function _match_size(sz::Tuple, inner::Tuple, outer::Tuple)
t1 = (_first_or_one(sz), _first_or_one(inner), _first_or_one(outer))
t2 = _match_size(sz[2:end], inner[2:end], outer[2:end])
(t1, t2...)
end

function _repeat_size(sz::Tuple, inner::Tuple, outer::Tuple)
t = _match_size(sz, inner, outer)
map(*, getindex.(t, 1), getindex.(t, 2), getindex.(t, 3))
end

function Base.repeat(A::Fill; inner=ntuple(x->1, ndims(A)), outer=ntuple(x->1, ndims(A)))
Base.require_one_based_indexing(A)
length(inner) >= ndims(A) ||
throw(ArgumentError("number of inner repetitions $(length(inner)) cannot be "*
"less than number of dimensions of input array $(ndims(A))"))
length(outer) >= ndims(A) ||
throw(ArgumentError("number of outer repetitions $(length(outer)) cannot be "*
"less than number of dimensions of input array $(ndims(A))"))
sz = _repeat_size(size(A), Tuple(inner), Tuple(outer))
Fill(getindex_value(A), sz)
end

end
Loading