Skip to content

Commit d6e2e22

Browse files
committed
Added more constructors with more convenient default arguments
1 parent 6192106 commit d6e2e22

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

src/extendable.jl

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,48 @@ end
2424
$(TYPEDSIGNATURES)
2525
2626
Create empty ExtendablSparseMatrix.
27+
"""
28+
function ExtendableSparseMatrix{Tv,Ti}(m::Integer, n::Integer) where{Tv,Ti<:Integer}
29+
ExtendableSparseMatrix{Tv,Ti}(spzeros(Tv,Ti,m,n),nothing)
30+
end
31+
32+
"""
33+
$(TYPEDSIGNATURES)
34+
35+
Create empty ExtendablSparseMatrix.
36+
"""
37+
function ExtendableSparseMatrix(::Type{Tv},::Type{Ti},m::Integer, n::Integer) where{Tv,Ti<:Integer}
38+
ExtendableSparseMatrix{Tv,Ti}(m,n)
39+
end
40+
41+
"""
42+
$(TYPEDSIGNATURES)
43+
44+
Create empty ExtendablSparseMatrix.
45+
This is a pendant to spzeros.
46+
"""
47+
ExtendableSparseMatrix(::Type{Tv},m::Integer, n::Integer) where{Tv}=ExtendableSparseMatrix{Tv,Int}(m,n)
48+
49+
50+
"""
51+
$(TYPEDSIGNATURES)
2752
53+
Create empty ExtendablSparseMatrix.
2854
This is a pendant to spzeros.
2955
"""
30-
ExtendableSparseMatrix{Tv,Ti}(m::Integer, n::Integer) where{Tv,Ti<:Integer}=ExtendableSparseMatrix{Tv,Ti}(spzeros(Tv,Ti,m,n),nothing)
56+
ExtendableSparseMatrix(m::Integer, n::Integer)=ExtendableSparseMatrix{Float64,Int}(m,n)
57+
58+
59+
"""
60+
$(TYPEDSIGNATURES)
61+
62+
Create ExtendablSparseMatrix from sparse matrix
63+
"""
64+
function ExtendableSparseMatrix(M::SparseMatrixCSC{Tv,Ti}) where{Tv,Ti<:Integer}
65+
return ExtendableSparseMatrix{Tv,Ti}(M, nothing)
66+
end
67+
68+
3169

3270

3371
"""

test/ExtendableSparseTest.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,20 @@ function benchmark(;n=10000,m=10000,nnz=50000)
6262
sprand!(xextmat,nnz)
6363
@inbounds flush!(xextmat)
6464
end
65+
true
6566
end
6667

68+
function constructors()
69+
println("Constructors:")
70+
m1=ExtendableSparseMatrix(10,10)
71+
m2=ExtendableSparseMatrix(Float16,10,10)
72+
m3=ExtendableSparseMatrix(Float32,Int16,10,10)
6773

74+
csc=sprand(10,10,0.1)
75+
m4=ExtendableSparseMatrix(csc)
76+
sprand!(m4,6)
77+
flush!(m4)
78+
79+
true
80+
end
6881
end

test/runtests.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using Test
22
include("ExtendableSparseTest.jl")
33

4-
ExtendableSparseTest.benchmark()
4+
5+
@test ExtendableSparseTest.constructors()
6+
@test ExtendableSparseTest.benchmark()
57

68

79
@time begin
8-
10+
911

1012
@test ExtendableSparseTest.check(m=10,n=10,nnz=5)
1113
@test ExtendableSparseTest.check(m=100,n=100,nnz=500,nsplice=2)

0 commit comments

Comments
 (0)