Skip to content

Commit

Permalink
Merge pull request #88 from JuliaRobotics/22Q2/enh/update
Browse files Browse the repository at this point in the history
internal _update! function
  • Loading branch information
dehann committed Apr 18, 2022
2 parents fda7f5d + 0eaee7c commit 81b0d3a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Expand Up @@ -2,7 +2,7 @@ name = "KernelDensityEstimate"
uuid = "2472808a-b354-52ea-a80e-1658a3c6056d"
keywords = ["NBP", "nonparametric", "kernel density", "functional products", "multiscale", "Gibbs sampling", "KDE"]
desc = "A modified version of the multiscale Gibbs product and KDE"
version = "0.5.9"
version = "0.5.10"

[deps]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Expand Down
33 changes: 33 additions & 0 deletions src/BallTree01.jl
Expand Up @@ -28,6 +28,39 @@ mutable struct BallTree
end


function _update!(dst::BallTree, src::BallTree)
dst.dims != src.dims && @warn("Updating BallTree with different dims source, this might not always be supported")
dst.num_points != src.num_points && @warn("Updating BallTree with different num_points source, this might not always be supported")

dst.dims = src.dims
dst.num_points = src.num_points
resize!(dst.centers, length(src.centers))
dst.centers .= src.centers
resize!(dst.ranges, length(src.ranges))
dst.ranges .= src.ranges
resize!(dst.weights, length(src.weights))
dst.weights .= src.weights
resize!(dst.left_child, length(src.left_child))
dst.left_child .= src.left_child
resize!(dst.right_child, length(src.right_child))
dst.right_child .= src.right_child
resize!(dst.lowest_leaf, length(src.lowest_leaf))
dst.lowest_leaf .= src.lowest_leaf
resize!(dst.highest_leaf, length(src.highest_leaf))
dst.highest_leaf .= src.highest_leaf
resize!(dst.permutation, length(src.permutation))
dst.permutation .= src.permutation
dst.next = src.next

dst.swapHandle = src.swapHandle
dst.calcStatsHandle = src.calcStatsHandle
dst.data = src.data

dst
end



root() = 1
Ndim(bt::BallTree) = bt.dims
Npts(bt::BallTree) = bt.num_points
Expand Down
23 changes: 23 additions & 0 deletions src/BallTreeDensity01.jl
Expand Up @@ -23,6 +23,29 @@ mutable struct BallTreeDensity <: MixtureDensity
swapHandle::Function
end


function _update!(dst::BallTreeDensity, src::BallTreeDensity)
_update!(dst.bt, src.bt)

dst.KernelType = src.KernelType
dst.multibandwidth = src.multibandwidth

resize!(dst.means, length(src.means))
dst.means .= src.means
resize!(dst.bandwidth, length(src.bandwidth))
dst.bandwidth .= src.bandwidth

resize!(dst.bandwidthMin, length(src.bandwidthMin))
dst.bandwidthMin .= src.bandwidthMin
resize!(dst.bandwidthMax, length(src.bandwidthMax))
dst.bandwidthMax .= src.bandwidthMax

dst.swapHandle = src.swapHandle
dst.calcStatsHandle = src.calcStatsHandle

dst
end

getType(bd::BallTreeDensity) = bd.KernelType

#function Ndim(bd::BallTreeDensity)
Expand Down

0 comments on commit 81b0d3a

Please sign in to comment.