Skip to content

Adding vcat and tests #349

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
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.14"
version = "0.10.15"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
10 changes: 10 additions & 0 deletions src/mokernels/moinput.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ end

Base.size(inp::IsotopicMOInputs) = (inp.out_dim * length(inp.x),)

function Base.vcat(x::MOInputIsotopicByFeatures, y::MOInputIsotopicByFeatures)
x.out_dim == y.out_dim || throw(DimensionMismatch("out_dim mismatch"))
return MOInputIsotopicByFeatures(vcat(x.x, y.x), x.out_dim)
end

function Base.vcat(x::MOInputIsotopicByOutputs, y::MOInputIsotopicByOutputs)
x.out_dim == y.out_dim || throw(DimensionMismatch("out_dim mismatch"))
return MOInputIsotopicByOutputs(vcat(x.x, y.x), x.out_dim)
end

"""
MOInput(x::AbstractVector, out_dim::Integer)

Expand Down
9 changes: 6 additions & 3 deletions test/mokernels/moinput.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
type_2 = AbstractVector{Tuple{AbstractVector{Vector{Float64}},Int}}

@testset "isotopicbyoutputs" begin
ibo = MOInput(x, 3)
ibo = KernelFunctions.MOInputIsotopicByOutputs(x, 3)
ibo2 = KernelFunctions.MOInputIsotopicByOutputs(x, 2)

@test ibo == KernelFunctions.MOInputIsotopicByOutputs(x, 3)
@test_throws DimensionMismatch vcat(ibo, ibo2)

@test ibo == MOInput(x, 3)
@test isa(ibo, type_1) == true
@test isa(ibo, type_2) == false

Expand All @@ -18,6 +20,7 @@
@test lastindex(ibo) == 12
@test firstindex(ibo) == 1
@test_throws BoundsError ibo[0]
@test vcat(ibo, ibo) == MOInput(vcat(x, x), 3)

@test ibo[2] == (x[2], 1)
@test ibo[5] == (x[1], 2)
Expand All @@ -30,14 +33,14 @@

@test isa(ibf, type_1) == true
@test isa(ibf, type_2) == false

@test length(ibf) == 12
@test size(ibf) == (12,)
@test size(ibf, 1) == 12
@test size(ibf, 2) == 1
@test lastindex(ibf) == 12
@test firstindex(ibf) == 1
@test_throws BoundsError ibf[0]
@test vcat(ibf, ibf) == KernelFunctions.MOInputIsotopicByFeatures(vcat(x, x), 3)

@test ibf[2] == (x[1], 2)
@test ibf[5] == (x[2], 2)
Expand Down