Skip to content

Commit 187940a

Browse files
committed
add two missing ctors, add issue tests
1 parent 114ed73 commit 187940a

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

src/matrix.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ function GBMatrix(
3939
return A
4040
end
4141

42+
function GBMatrix{T}(
43+
I::AbstractVector, J::AbstractVector, X::AbstractVector{Told};
44+
combine = +, nrows = maximum(I), ncols = maximum(J), fill = nothing
45+
) where {T, Told}
46+
return GBMatrix(I, J, T.(X); combine, ncols, nrows, fill)
47+
end
48+
4249
#iso constructors
4350
"""
4451
GBMatrix(I, J, x; nrows = maximum(I), ncols = maximum(J); fill = nothing)

src/vector.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ function GBVector(I::AbstractVector{U}, X::AbstractVector{T}; combine = +, nrows
3131
return v
3232
end
3333

34+
function GBVector{T}(
35+
I::AbstractVector, X::AbstractVector{Told};
36+
combine = +, nrows = maximum(I), fill = nothing
37+
) where {T, U, Told}
38+
return GBVector(I, T.(X); combine, nrows, fill)
39+
end
3440
#iso valued constructors.
3541
"""
3642
GBVector(I, x; nrows = maximum(I) fill = nothing)

test/issues.jl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@testset "Issues" begin
2+
@testset "#81" begin
3+
# basic issue
4+
B = GBVector([1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7])
5+
A = GBMatrix([1,1,2,2,3,4,4,5,6,7,7,7], [2,4,5,7,6,1,3,6,3,3,4,5], [1:12...])
6+
@test A[:, 2] isa GBVector
7+
@test A[2, :] isa GBVector
8+
@test emul(A[:, 2], B) == GBVector([1], [1])
9+
10+
# test that GBMatrix <ewise> GBVector is allowed
11+
# with correct sizes:
12+
@test GBMatrix(B) .+ B == GBMatrix(B .* 2)
13+
end
14+
15+
@testset "#79" begin
16+
# Indexing GBMatrix with a list of indices
17+
# mutates that parameter
18+
i = [1,2]
19+
A = GBMatrix([1,1,2,2,3,4,4,5,6,7,7,7], [2,4,5,7,6,1,3,6,3,3,4,5], [1:12...])
20+
A[i, :]
21+
@test i == [1,2]
22+
end
23+
24+
@testset "#78" begin
25+
@test GBVector{Int}([1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7]) ==
26+
GBVector([1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7])
27+
28+
@test GBMatrix{Int64}([1,3,5], [1,3,5], [1,3,5]) ==
29+
GBMatrix([1,3,5], [1,3,5], [1,3,5])
30+
31+
@test GBVector{Int128}([1,2,3], [1,2,3])[1] == Int128(1)
32+
end
33+
34+
@testset "#74" begin
35+
# this interface needs its own tests.
36+
# an extra is here for that particular issue.
37+
A = GBMatrix([[1,2] [3,4]])
38+
@test *(Monoid((a, b)->a + b, zero), *)(A, A) == A * A
39+
end
40+
41+
@testset "#71" begin
42+
# segfault with weird ctor
43+
@test_throws ArgumentError GBMatrix{Int, Int}(10, 10)
44+
@test_throws ArgumentError GBVector{Int, Int}(10)
45+
end

0 commit comments

Comments
 (0)