Skip to content

add zero(::ColVecs) / zero(::RowVecs) definitions #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 7, 2022
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "KernelFunctions"
uuid = "ec8451be-7e33-11e9-00cf-bbf324bd1392"
version = "0.10.33"
version = "0.10.34"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
2 changes: 2 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Base.getindex(D::ColVecs, i) = ColVecs(view(D.X, :, i))
Base.setindex!(D::ColVecs, v::AbstractVector, i) = setindex!(D.X, v, :, i)

Base.vcat(a::ColVecs, b::ColVecs) = ColVecs(hcat(a.X, b.X))
Base.zero(x::ColVecs) = ColVecs(zero(x.X))

dim(x::ColVecs) = size(x.X, 1)

Expand Down Expand Up @@ -163,6 +164,7 @@ Base.getindex(D::RowVecs, i) = RowVecs(view(D.X, i, :))
Base.setindex!(D::RowVecs, v::AbstractVector, i) = setindex!(D.X, v, i, :)

Base.vcat(a::RowVecs, b::RowVecs) = RowVecs(vcat(a.X, b.X))
Base.zero(x::RowVecs) = RowVecs(zero(x.X))

dim(x::RowVecs) = size(x.X, 2)

Expand Down
10 changes: 10 additions & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
@test_throws ArgumentError vec_of_vecs(X; obsdim=0)
@test_throws ArgumentError vec_of_vecs(X; obsdim=3)
end

# Test Matrix data sets.
function test_zero(DX::Union{ColVecs,RowVecs})
zero_DX = zero(DX)
@test all(iszero, zero_DX)
@test zero_DX isa typeof(DX)
@test size(zero_DX.X) == size(DX.X)
end

@testset "ColVecs" begin
DX = ColVecs(X)
@test DX == DX
Expand All @@ -28,6 +36,7 @@
DX[2] = v
@test DX[2] == v
@test X[:, 2] == v
test_zero(DX)

Y = randn(rng, D, N + 1)
DY = ColVecs(Y)
Expand Down Expand Up @@ -85,6 +94,7 @@
DX[2] = w
@test DX[2] == w
@test X[2, :] == w
test_zero(DX)

Y = randn(rng, D + 1, N)
DY = RowVecs(Y)
Expand Down