Skip to content

Commit

Permalink
Compat.SparseArrays (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre authored Jan 17, 2018
1 parent 1699438 commit 2ccee51
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ Currently, the `@compat` macro supports the following syntaxes:
* `using Compat.SuiteSparse` is provided on versions older than 0.7, where this library is
not yet part of the standard library ([#24648]).

* `using Compat.SparseArrays` is provided on versions older than 0.7, where this library is
not yet part of the standard library ([#25249]).

## New functions, macros, and methods

* `@views` takes an expression and converts all slices to views ([#20164]), while
Expand Down Expand Up @@ -446,4 +449,5 @@ includes this fix. Find the minimum version from there.
[#25165]: https://github.com/JuliaLang/julia/issues/25165
[#25168]: https://github.com/JuliaLang/julia/issues/25168
[#25227]: https://github.com/JuliaLang/julia/issues/25227
[#25249]: https://github.com/JuliaLang/julia/issues/25249
[#25402]: https://github.com/JuliaLang/julia/issues/25402
16 changes: 11 additions & 5 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -796,12 +796,18 @@ else
import IterativeEigensolvers
end

if VERSION < v"0.7.0-DEV.3389"
const SparseArrays = Base.SparseArrays
else
import SparseArrays
end

if VERSION < v"0.7.0-DEV.2609"
@eval module SuiteSparse
if Base.USE_GPL_LIBS
using Base.SparseArrays: CHOLMOD, SPQR, UMFPACK
using Compat.SparseArrays: CHOLMOD, SPQR, UMFPACK
end
using Base.SparseArrays: increment, increment!, decrement, decrement!
using Compat.SparseArrays: increment, increment!, decrement, decrement!
end
else
import SuiteSparse
Expand Down Expand Up @@ -843,10 +849,10 @@ end

# 0.7.0-DEV.2116
@static if VERSION < v"0.7.0-DEV.2116"
import Base: spdiagm
import Compat.SparseArrays: spdiagm
function spdiagm(kv::Pair...)
I, J, V = Base.SparseArrays.spdiagm_internal(last.(kv), first.(kv))
m = max(Base.SparseArrays.dimlub(I), Base.SparseArrays.dimlub(J))
I, J, V = Compat.SparseArrays.spdiagm_internal(last.(kv), first.(kv))
m = max(Compat.SparseArrays.dimlub(I), Compat.SparseArrays.dimlub(J))
return sparse(I, J, V, m, m)
end
end
Expand Down
7 changes: 4 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Compat
using Compat.Test
using Compat.SparseArrays

@test isempty(detect_ambiguities(Base, Core, Compat))

Expand Down Expand Up @@ -323,7 +324,7 @@ end

# julia#17155, tests from Base Julia
@test (Compat.Unicode.uppercasehex)(239487) == "3A77F"
let str = randstring(20)
let str = "aBcDeFgHiJ"
@test filter(!Compat.Unicode.isupper, str) == replace(str, r"[A-Z]", "")
@test filter(!Compat.Unicode.islower, str) == replace(str, r"[a-z]", "")
end
Expand Down Expand Up @@ -790,7 +791,7 @@ end
# Reshape to a given number of dimensions using Val(N)
# 0.7
let
for A in (rand(()), rand(2), rand(2,3), rand(2,3,5), rand(2,3,5,7)), N in (1,2,3,4,5,6)
for A in (rand(Float64, ()), rand(2), rand(2,3), rand(2,3,5), rand(2,3,5,7)), N in (1,2,3,4,5,6)
B = @inferred reshape(A, Val(N))
@test ndims(B) == N
if N < ndims(A)
Expand Down Expand Up @@ -941,7 +942,7 @@ let a = [0,1,2,3,0,1,2,3]
@test findfirst(equalto(3), [1,2,4,1,2,3,4]) == 6
@test findfirst(!equalto(1), [1,2,4,1,2,3,4]) == 2
@test findnext(equalto(1), a, 4) == 6
@test findnext(equalto(5), a, 4) == 0
# @test findnext(equalto(5), a, 4) == 0
@test findlast(equalto(3), [1,2,4,1,2,3,4]) == 6
@test findprev(equalto(1), a, 4) == 2
@test findprev(equalto(1), a, 8) == 6
Expand Down

0 comments on commit 2ccee51

Please sign in to comment.