diff --git a/.travis.yml b/.travis.yml index 6e4d4e4..c82cd7e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,17 @@ -language: cpp -compiler: - - clang +language: julia +os: + - linux + - osx +julia: + - 0.6 + - 1.0 + - nightly notifications: - email: false -env: - matrix: - - JULIAVERSION="juliareleases" - - JULIAVERSION="julianightlies" -before_install: - - sudo add-apt-repository ppa:staticfloat/julia-deps -y - - sudo add-apt-repository ppa:staticfloat/${JULIAVERSION} -y - - sudo apt-get update -qq -y - - sudo apt-get install libpcre3-dev julia -y -script: - - julia -e 'Pkg.init(); run(`ln -s $(pwd()) $(Pkg.dir())/SpecialMatrices`); Pkg.pin("SpecialMatrices"); Pkg.resolve()' - - julia -e 'using SpecialMatrices; @assert isdefined(:SpecialMatrices); @assert typeof(SpecialMatrices) === Module' - - if [ $JULIAVERSION = "julianightlies" ]; then julia --code-coverage test/runtests.jl; fi - - if [ $JULIAVERSION = "juliareleases" ]; then julia test/runtests.jl; fi + email: false + +matrix: + allow_failures: + - julia: nightly + after_success: - - if [ $JULIAVERSION = "julianightlies" ]; then julia -e 'cd(Pkg.dir("SpecialMatrices")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'; fi + - julia -e 'VERSION >= v"0.7.0-DEV.5183" && using Pkg; Pkg.add("Coverage"); cd(Pkg.dir("SpecialMatrices")); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())' diff --git a/README.md b/README.md index 17ab763..5fb53d7 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,12 @@ - - # Special Matrices A [Julia](http://julialang.org) package for working with special matrix types. -Use `Pkg.checkout("SpecialMatrices")` to access latest version. - -This package extends the `Base.LinAlg` library with support for special +This package extends the `LinearAlgebra` library with support for special matrices which are used in linear algebra. Every special matrix has its own type. -The full matrix is accessed by the command `full(A)`. +The full matrix is accessed by the command `Matrix(A)`. -[![Build Status](https://travis-ci.org/jiahao/SpecialMatrices.jl.svg)](https://travis-ci.org/jiahao/SpecialMatrices.jl) [![Coverage Status](https://img.shields.io/coveralls/jiahao/SpecialMatrices.jl.svg)](https://coveralls.io/r/jiahao/SpecialMatrices.jl) +[![Build Status](https://travis-ci.org/JuliaMatrices/SpecialMatrices.jl.svg)](https://travis-ci.org/JuliaMatrices/SpecialMatrices.jl) [![Coverage Status](https://img.shields.io/coveralls/jiahao/SpecialMatrices.jl.svg)](https://coveralls.io/r/jiahao/SpecialMatrices.jl) ## Currently supported special matrices @@ -39,7 +35,7 @@ julia> Cauchy(pi) ## `Circulant` matrix ```julia -julia> Circulant([1:4]) +julia> Circulant([1,2,3,4]) 4x4 Circulant{Int64}: 1 4 3 2 2 1 4 3 @@ -61,14 +57,14 @@ Also, directly from a polynomial: ```julia julia> using Polynomials -julia> P=Poly([2,3,4,5]) +julia> P=Poly([2.0,3,4,5]) Poly(2 + 3x + 4x^2 + 5x^3) julia> C=Companion(P) -3x3 Companion{Number}: - 0 0 -0.4 - 1 0 -0.6 - 0 1 -0.8 +3×3 Companion{Float64}: + 0.0 0.0 -0.4 + 1.0 0.0 -0.6 + 0.0 1.0 -0.8 ``` ## [`Frobenius`](http://en.wikipedia.org/wiki/Frobenius_matrix) matrix @@ -78,7 +74,7 @@ Example ```julia julia> using SpecialMatrices -julia> F=Frobenius(3, [1.0:3.0]) #Specify subdiagonals of column 3 +julia> F=Frobenius(3, [1.0,2.0,3.0]) #Specify subdiagonals of column 3 6x6 Frobenius{Float64}: 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 @@ -105,7 +101,7 @@ julia> F*F #Special form preserved if the same column has the subdiagonals 0.0 0.0 4.0 0.0 1.0 0.0 0.0 0.0 6.0 0.0 0.0 1.0 -julia> F*Frobenius(2, [5.0:-1.0:2.0]) #Promotes to Matrix +julia> F*Frobenius(2, [5.0,4.0,3.0,2.0]) #Promotes to Matrix 6x6 Array{Float64,2}: 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 @@ -114,7 +110,7 @@ julia> F*Frobenius(2, [5.0:-1.0:2.0]) #Promotes to Matrix 0.0 13.0 2.0 0.0 1.0 0.0 0.0 17.0 3.0 0.0 0.0 1.0 -julia> F*[10.0:10.0:60.0] +julia> F*[10.0,20,30,40,50,60.0] 6-element Array{Float64,1}: 10.0 20.0 @@ -129,7 +125,7 @@ julia> F*[10.0:10.0:60.0] Input is a vector of odd length. ```julia -julia> Hankel([-4:4]) +julia> Hankel(collect(-4:4)) 5x5 Hankel{Int64}: -4 -3 -2 -1 0 -3 -2 -1 0 1 @@ -144,7 +140,7 @@ julia> Hankel([-4:4]) julia> A=Hilbert(5) Hilbert{Rational{Int64}}(5,5) -julia> full(A) +julia> Matrix(A) 5x5 Array{Rational{Int64},2}: 1//1 1//2 1//3 1//4 1//5 1//2 1//3 1//4 1//5 1//6 @@ -152,7 +148,7 @@ julia> full(A) 1//4 1//5 1//6 1//7 1//8 1//5 1//6 1//7 1//8 1//9 -julia> full(Hilbert(5)) +julia> Matrix(Hilbert(5)) 5x5 Array{Rational{Int64},2}: 1//1 1//2 1//3 1//4 1//5 1//2 1//3 1//4 1//5 1//6 @@ -248,7 +244,7 @@ julia> Strang(6) Input is a vector of odd length. ```julia -julia> Toeplitz([-4:4]) +julia> Toeplitz(collect(-4:4)) 5x5 Toeplitz{Int64}: 0 -1 -2 -3 -4 1 0 -1 -2 -3 @@ -260,7 +256,7 @@ julia> Toeplitz([-4:4]) ```julia -julia> Vandermonde([1:5]) +julia> Vandermonde(collect(1:5)) 5x5 Vandermonde{Int64}: 1 1 1 1 1 1 2 4 8 16 diff --git a/REQUIRE b/REQUIRE index 504539c..954084b 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,3 @@ julia 0.4 -Polynomials +Polynomials 0.4.0 +Compat 1.4.0 diff --git a/src/SpecialMatrices.jl b/src/SpecialMatrices.jl index 58ebfa1..210b4b6 100644 --- a/src/SpecialMatrices.jl +++ b/src/SpecialMatrices.jl @@ -1,6 +1,14 @@ module SpecialMatrices -import Base: A_mul_B!, full, getindex, inv, isassigned, size, * +using Compat +using Compat.LinearAlgebra + +import Compat.LinearAlgebra: Matrix, inv +if VERSION >= v"0.7.0" + import Compat.LinearAlgebra: mul! +end + +import Base: getindex, isassigned, size, * include("cauchy.jl") #Cauchy matrix include("companion.jl") #Companion matrix diff --git a/src/cauchy.jl b/src/cauchy.jl index 32fa375..0e4528f 100644 --- a/src/cauchy.jl +++ b/src/cauchy.jl @@ -2,13 +2,13 @@ export Cauchy -immutable Cauchy{T} <: AbstractMatrix{T} +struct Cauchy{T} <: AbstractMatrix{T} x::Vector{T} # y::Vector{T} # end # immutable function Cauchy(k::Number) - Cauchy([1:k],[1:k]) + Cauchy(collect(1:k),collect(1:k)) end function Cauchy(x::Vector) @@ -26,4 +26,4 @@ function getindex(A::Cauchy,i::Integer,j::Integer) end # getindex # Dense version of Cauchy -full(A::Cauchy) =[A[i,j] for i=1:size(A,1), j=1:size(A,2)] +Matrix(A::Cauchy) = [A[i,j] for i=1:size(A,1), j=1:size(A,2)] diff --git a/src/companion.jl b/src/companion.jl index e1f8394..77e3f68 100644 --- a/src/companion.jl +++ b/src/companion.jl @@ -8,9 +8,9 @@ end using Polynomials #Generate companion matrix from a polynomial -function Companion{T}(P::Poly{T}) +function Companion(P::Poly{T}) where T n = length(P) - c = Array{T}(n-1) + c = Array{T}(undef, n-1) d=P.a[n] for i=1:n-1 c[i]=P.a[i]/d @@ -28,13 +28,13 @@ function size(C::Companion) end #XXX Inefficient but works -# getindex(C::Companion, i, j) = getindex(full(C), i, j) -# isassigned(C::Companion, i, j) = isassigned(full(C), i, j) -getindex{T}(C::Companion{T}, i::Int, j::Int) = (j==length(C.c)) ? -C.c[i] : (i==j+1 ? one(T) : zero(T) ) +# getindex(C::Companion, i, j) = getindex(Matrix(C), i, j) +# isassigned(C::Companion, i, j) = isassigned(Matrix(C), i, j) +getindex(C::Companion{T}, i::Int, j::Int) where T = (j==length(C.c)) ? -C.c[i] : (i==j+1 ? one(T) : zero(T) ) isassigned(C::Companion, i::Int, j::Int) = (j==length(C.c)) ? isassigned(C.c,i) : true -function full{T}(C::Companion{T}) +function Matrix(C::Companion{T}) where T M = zeros(T, size(C)...) M[:,end]=-C.c for i=1:size(C,1)-1 @@ -44,17 +44,17 @@ function full{T}(C::Companion{T}) end #Linear algebra stuff -function A_mul_B!{T}(C::Companion{T}, b::Vector{T}) +function mul!(C::Companion{T}, b::Vector{T}) where T x = b[end] y = -C.c[1]*x b[2:end] = b[1:end-1]-C.c[2:end]*x b[1] = y b end -*{T}(C::Companion{T}, b::Vector{T}) = A_mul_B!(C, copy(b)) +*(C::Companion{T}, b::Vector{T}) where T = mul!(C, copy(b)) -function A_mul_B!{T}(A::Matrix{T}, C::Companion{T}) - v = Array(T, size(A,1)) +function mul!(A::Matrix{T}, C::Companion{T}) where T + v = Array{T}(undef, size(A,1)) for i=1:size(A,1) v[i] =dot(vec(A[i,:]),-C.c) end @@ -64,9 +64,9 @@ function A_mul_B!{T}(A::Matrix{T}, C::Companion{T}) A[:,end] = v A end -*{T}(A::Matrix{T}, C::Companion{T}) = A_mul_B!(copy(A), C) +*(A::Matrix{T}, C::Companion{T}) where T = mul!(copy(A), C) -function inv{T}(C::Companion{T}) +function inv(C::Companion{T}) where T M = zeros(T, size(C)...) for i=1:size(C,1)-1 M[i, i+1] = one(T) diff --git a/src/frobenius.jl b/src/frobenius.jl index 7c5ffa7..ba40f42 100644 --- a/src/frobenius.jl +++ b/src/frobenius.jl @@ -19,7 +19,7 @@ export Frobenius #dense vector, so that the size can be inferred automatically as j+k where j is #the index of the column and k is the number of subdiagonal elements. -immutable Frobenius{T} <: AbstractArray{T, 2} +struct Frobenius{T} <: AbstractArray{T, 2} colidx :: Int c :: Vector{T} end @@ -34,31 +34,31 @@ function size(F::Frobenius) end #XXX Inefficient but works -getindex(F::Frobenius, i, j) = getindex(full(F), i, j) -isassigned(F::Frobenius, i, j) = isassigned(full(F), i, j) +getindex(F::Frobenius, i, j) = getindex(Matrix(F), i, j) +isassigned(F::Frobenius, i::Integer, j::Integer) = isassigned(Matrix(F), i, j) -function full{T}(F::Frobenius{T}) - M = eye(T, size(F, 1)) +function Matrix(F::Frobenius{T}) where T + M = Matrix{T}(I, size(F)) M[F.colidx+1:end, F.colidx] = F.c M end #Linear algebra stuff -function A_mul_B!{T}(F::Frobenius{T}, b::Vector{T}) +function mul!(F::Frobenius{T}, b::Vector{T}) where T (n = size(F, 2)) == length(b) || throw(DimensionMismatch("$n $(length(b))")) for i=F.colidx+1:n b[i] += F.c[i-F.colidx] * b[F.colidx] end b end -*{T}(F::Frobenius{T}, b::Vector{T}) = A_mul_B!(F, copy(b)) +*(F::Frobenius{T}, b::Vector{T}) where T = mul!(F, copy(b)) -function *{T}(F::Frobenius{T}, G::Frobenius{T}) +function *(F::Frobenius{T}, G::Frobenius{T}) where T (n = size(F, 2)) == size(G, 2) || throw(DimensionMismatch("")) if F.colidx == G.colidx #Answer is still expressible as a Frobenius return Frobenius(F.colidx, F.c + G.c) else - M = full(F) + M = Matrix(F) M[G.colidx+1:end, G.colidx] = F.colidx < G.colidx ? G.c : Frobenius(F.colidx-G.colidx, F.c) * G.c return M diff --git a/src/hankel.jl b/src/hankel.jl index e782d39..a6e2b3f 100644 --- a/src/hankel.jl +++ b/src/hankel.jl @@ -14,18 +14,18 @@ size(H::Hankel, r::Int) = (r==1 || r==2) ? 1 + div(length(H.c),2) : size(H::Hankel) = size(H,1), size(H,2) # Fast matrix x vector via fft() -function *{T}(A::Hankel{T},x::Vector{T}) +function *(A::Hankel{T},x::Vector{T}) where T Toeplitz(A.c)*reverse(x) end -function A_mul_B!{T}(y::StridedVector{T},A::Hankel{T},x::StridedVector{T}) +function mul!(y::StridedVector{T},A::Hankel{T},x::StridedVector{T}) where T xx=reverse(x) - return A_mul_B!(y,Toeplitz(A.c),xx) + return mul!(y,Toeplitz(A.c),xx) end -function full{T}(H::Hankel{T}) +function Matrix(H::Hankel{T}) where T n=size(H, 1) - M=Array{T}(n, n) + M=Array{T}(undef, n, n) for i=1:n M[:,i] = H.c[i:i+n-1] end diff --git a/src/hilbert.jl b/src/hilbert.jl index 7b45323..a30f084 100644 --- a/src/hilbert.jl +++ b/src/hilbert.jl @@ -1,9 +1,8 @@ #The m-by-n Hilbert matrix has matrix elements # H_{ij} = 1/(i+j-1) -import Base: full export Hilbert -type Hilbert{T} +struct Hilbert{T} m :: Int n :: Int end @@ -11,7 +10,7 @@ Hilbert(T::Type, m::Integer, n::Integer) = Hilbert{T}(m, n) Hilbert(m::Integer, n::Integer) = Hilbert{Rational{Int}}(m, n) Hilbert(n::Integer) = Hilbert(n, n) -function full{T}(H::Hilbert{T}) +function Matrix(H::Hilbert{T}) where T Hf = zeros(T, H.m, H.n) for i=1:H.m, j=1:H.n Hf[i, j] = one(T)/(i+j-1) @@ -19,7 +18,7 @@ function full{T}(H::Hilbert{T}) Hf end -function inv{T}(H::Hilbert{T}) +function inv(H::Hilbert{T}) where T invH=zeros(T,H.m,H.m) for i=1:H.m, j=1:H.m invH[i,j]=(-1)^(i+j)*(i+j-1)*binomial(H.m+i-1,H.m-j)* diff --git a/src/kahan.jl b/src/kahan.jl index 680d6c6..8646d31 100644 --- a/src/kahan.jl +++ b/src/kahan.jl @@ -2,7 +2,7 @@ export Kahan -immutable Kahan{T<:Number,T1<:Number} <: AbstractMatrix{T} +struct Kahan{T<:Number,T1<:Number} <: AbstractMatrix{T} m::Int # dimension n::Int # dimension theta::T # angle @@ -27,7 +27,7 @@ function getindex(A::Kahan,i::Integer,j::Integer) end # getindex # Dense version of Kahan -full(A::Kahan) =[A[i,j] for i=1:size(A,1), j=1:size(A,2)] +Matrix(A::Kahan) =[A[i,j] for i=1:size(A,1), j=1:size(A,2)] diff --git a/src/riemann.jl b/src/riemann.jl index 43c4d99..3e755d9 100644 --- a/src/riemann.jl +++ b/src/riemann.jl @@ -2,7 +2,7 @@ import Base: size export Riemann -immutable Riemann{Int} <: AbstractMatrix{Int} +struct Riemann{Int} <: AbstractMatrix{Int} n::Int end # immutable @@ -22,5 +22,5 @@ function getindex(A::Riemann,i::Integer,j::Integer) end # getindex # Dense version of Riemann -full(A::Riemann) =[A[i,j] for i=1:size(A,1), j=1:size(A,2)] +Matrix(A::Riemann) =[A[i,j] for i=1:size(A,1), j=1:size(A,2)] diff --git a/src/strang.jl b/src/strang.jl index 3b3f2de..33f10c3 100644 --- a/src/strang.jl +++ b/src/strang.jl @@ -1,19 +1,19 @@ export Strang -immutable Strang{T} <: AbstractArray{T, 2} +struct Strang{T} <: AbstractArray{T, 2} n :: Int end Strang(n::Int) = Strang{Float64}(n) strang(T, n)= n >1 ? SymTridiagonal(2ones(T, n),-ones(T, n-1)) : n==1 ? Diagonal([2one(T)]) : error("Invalid dimension ", n) -function getindex{T}(S::Strang{T}, i, j) +function getindex(S::Strang{T}, i, j) where T i == j && return 2 abs(i - j) == 1 && return -1 0 end -getindex{T}(S::Strang{T}, I...) = getindex(S,ind2sub(size(S),I...)...) +getindex(S::Strang{T}, I...) where T = getindex(S,ind2sub(size(S),I...)...) size(S::Strang, r::Int) = r==1 || r==2 ? S.n : throw(ArgumentError("Invalid dimension $r")) size(S::Strang) = S.n, S.n -full{T}(S::Strang{T}) = full(strang(T, S.n)) -*{T}(A::VecOrMat{T}, S::Strang{T}) = A*full(strang(T, S.n)) -*{T}(S::Strang{T}, A::VecOrMat{T}) = full(strang(T, S.n))*A +Matrix(S::Strang{T}) where T = Matrix(strang(T, S.n)) +*(A::VecOrMat{T}, S::Strang{T}) where T = A*Matrix(S) +*(S::Strang{T}, A::VecOrMat{T}) where T = Matrix(S)*A diff --git a/src/toeplitz.jl b/src/toeplitz.jl index 6b7accf..31b6a91 100644 --- a/src/toeplitz.jl +++ b/src/toeplitz.jl @@ -12,26 +12,26 @@ size(T::Toeplitz, r::Int) = (r==1 || r==2) ? 1 + div(length(T.c),2) : size(T::Toeplitz) = size(T,1), size(T,2) # Fast matrix x vector multiplication via embedding Toeplitz() into Circulant() -function *{T}(A::Toeplitz{T},x::Vector{T}) +function *(A::Toeplitz{T},x::Vector{T}) where T n=length(A.c) k=div(n+1,2) C=Circulant([A.c[k:n];A.c[1:k-1]]) (C*[x;zeros(T,k-1)])[1:k] end -function A_mul_B!{T}(y::StridedVector{T},A::Toeplitz{T},x::StridedVector{T}) +function mul!(y::StridedVector{T},A::Toeplitz{T},x::StridedVector{T}) where T n=length(A.c) k=div(n+1,2) C=Circulant([A.c[k:n];A.c[1:k-1]]) xx=[x;zeros(T,k-1)] - yy=A_mul_B!(similar(xx),C,xx) + yy=mul!(similar(xx),C,xx) copy!(y, 1, yy, 1, length(y)) return y end -function full{T}(To::Toeplitz{T}) +function Matrix(To::Toeplitz{T}) where T n=size(To, 1) - M=Array{T}(n,n) + M=Array{T}(undef,n,n) for i=1:n M[i:n,i] = To.c[n:2n-i] M[1:i-1,i] = To.c[n-i+1:n-1] @@ -51,14 +51,14 @@ size(C::Circulant) = size(C,1), size(C,2) # Fast matrix x vector via fft() # see Golub, van Loan, Matrix Computations, John Hopkins, Baltimore, 1996, p. 202 -function *{T}(C::Circulant{T},x::Vector{T}) +function *(C::Circulant{T},x::Vector{T}) where T xt=fft(x) vt=fft(C.c) yt=vt.*xt - typeof(x[1])==Int ? map(Int,round.(real(ifft(yt)))): ( (T <: Real) ? map(T,real(ifft(yt))) : ifft(yt)) + typeof(x[1])==Int ? map(Int,round.(real(ifft(yt)))) : ( (T <: Real) ? map(T,real(ifft(yt))) : ifft(yt)) end -function A_mul_B!{T}(y::StridedVector{T},C::Circulant{T},x::StridedVector{T}) +function mul!(y::StridedVector{T},C::Circulant{T},x::StridedVector{T}) where T xt=fft(x) vt=fft(C.c) yt=ifft(vt.*xt) @@ -72,9 +72,9 @@ function A_mul_B!{T}(y::StridedVector{T},C::Circulant{T},x::StridedVector{T}) return y end -function full{T}(C::Circulant{T}) +function Matrix(C::Circulant{T}) where T n=size(C, 1) - M=Array{T}(n,n) + M=Array{T}(undef,n,n) for i=1:n M[i:n,i] = C.c[1:n-i+1] M[1:i-1,i] = C.c[n-i+2:n] @@ -82,6 +82,6 @@ function full{T}(C::Circulant{T}) M end -function embed{T}(To::Toeplitz{T}) +function embed(To::Toeplitz{T}) where T return Circulant([To.c[div(end+1,2):end];To.c[1:div(end-1,2)]]) -end \ No newline at end of file +end diff --git a/src/vandermonde.jl b/src/vandermonde.jl index 3e35575..ccece4a 100644 --- a/src/vandermonde.jl +++ b/src/vandermonde.jl @@ -1,6 +1,6 @@ export Vandermonde -immutable Vandermonde{T} <: AbstractArray{T, 2} +struct Vandermonde{T} <: AbstractArray{T, 2} c :: Vector{T} end @@ -11,9 +11,9 @@ size(V::Vandermonde, r::Int) = (r==1 || r==2) ? length(V.c) : throw(ArgumentError("Invalid dimension $r")) size(V::Vandermonde) = length(V.c), length(V.c) -function full{T}(V::Vandermonde{T}) +function Matrix(V::Vandermonde{T}) where T n=size(V, 1) - M=Array{T}(n, n) + M=Array{T}(undef, n, n) for i=1:n M[:,i] = V.c.^(i-1) end diff --git a/test/companion.jl b/test/companion.jl index 61622b6..b976c4c 100644 --- a/test/companion.jl +++ b/test/companion.jl @@ -2,12 +2,12 @@ n = rand(1:10) Z = Companion(randn(n)) #Special properties -@test_approx_eq full(inv(Z)) inv(full(Z)) +@test Matrix(inv(Z)) ≈ inv(Matrix(Z)) #Matvec product b = randn(n) -@test_approx_eq Z*b full(Z)*b +@test Z*b ≈ Matrix(Z)*b m = rand(1:10) A = randn(m, n) -@test_approx_eq A*Z A*full(Z) +@test A*Z ≈ A*Matrix(Z) diff --git a/test/frobenius.jl b/test/frobenius.jl index d36385e..0cc2626 100644 --- a/test/frobenius.jl +++ b/test/frobenius.jl @@ -3,16 +3,16 @@ n=rand(1:10) Z = Frobenius(m, randn(n)) #size m+n #Special properties -@test_approx_eq full(inv(Z)) inv(full(Z)) +@test Matrix(inv(Z)) ≈ inv(Matrix(Z)) #Matvec product b = randn(m+n) -@test_approx_eq Z*b full(Z)*b +@test Z*b ≈ Matrix(Z)*b #Matmul product Y1 = Frobenius(m, randn(n)) #Another one of the same column -@test_approx_eq full(Y1*Z) full(Y1)*full(Z) +@test Matrix(Y1*Z) ≈ Matrix(Y1)*Matrix(Z) n2=rand(1:(m+n-1)) Y2 = Frobenius(m+n-n2, randn(n2)) #Probably not the same column -@test_approx_eq full(Y2*Z) full(Y2)*full(Z) +@test Matrix(Y2*Z) ≈ Matrix(Y2)*Matrix(Z) diff --git a/test/hankel.jl b/test/hankel.jl index d0b083a..1cde973 100644 --- a/test/hankel.jl +++ b/test/hankel.jl @@ -1,3 +1,3 @@ n=rand(1:10) H = Hankel(collect(-n:n)) -@test diag(full(H)) == collect(-n:2:n) +@test diag(Matrix(H)) == collect(-n:2:n) diff --git a/test/hilbert.jl b/test/hilbert.jl index f5fcb4f..c3a3b34 100644 --- a/test/hilbert.jl +++ b/test/hilbert.jl @@ -1,3 +1,3 @@ H = Hilbert(10) -@test full(H)[10,10] == 1//(10+10-1) +@test Matrix(H)[10,10] == 1//(10+10-1) diff --git a/test/runtests.jl b/test/runtests.jl index 10e8316..98cdb91 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,6 @@ using SpecialMatrices -using Base.Test +using Compat.Test +using Compat.LinearAlgebra include("companion.jl") #Companion matrix include("frobenius.jl") #Frobenius matrix diff --git a/test/strang.jl b/test/strang.jl index 1c374b9..9adffea 100644 --- a/test/strang.jl +++ b/test/strang.jl @@ -1,5 +1,5 @@ Z = Strang(1) -@test full(Z) == reshape([2.0],(1,1)) +@test Matrix(Z) == reshape([2.0],(1,1)) n = rand(1:10) Z = Strang(n) @@ -12,14 +12,12 @@ end A = Strang(10) u = ones(10) -v = similar(u) -A_mul_B!(v,A,u) -@test v == [1.0;zeros(8);1.0] +@test A*u == [1.0;zeros(8);1.0] #Matvec product b = randn(n) -@test_approx_eq Z*b full(Z)*b +@test Z*b ≈ Matrix(Z)*b m = rand(1:10) A = randn(m, n) -@test_approx_eq A*Z A*full(Z) +@test A*Z ≈ A*Matrix(Z) diff --git a/test/toeplitz.jl b/test/toeplitz.jl index dcb359d..aad95c1 100644 --- a/test/toeplitz.jl +++ b/test/toeplitz.jl @@ -1,2 +1,2 @@ n=rand(1:10) - @test diag(full(Toeplitz(collect(-n:n)))) == zeros(n+1) + @test diag(Matrix(Toeplitz(collect(-n:n)))) == zeros(n+1)