Skip to content

Commit

Permalink
Reduce allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer committed Jun 8, 2023
1 parent 2734b9d commit 7ef3cb5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/forest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,15 @@ function _split(

yl = Vector{eltype(y)}(undef, length(y))
yr = Vector{eltype(y)}(undef, length(y))
feat_data = Vector{eltype(X)}(undef, length(y))
for feature in possible_features
data = X[:, feature]
@inbounds for i in eachindex(feat_data)
feat_data[i] = X[i, feature]
end
for cutpoint in cutpoints[feature]
vl = _view_y!(yl, data, y, <, cutpoint)
vl = _view_y!(yl, feat_data, y, <, cutpoint)
isempty(vl) && continue
vr = _view_y!(yr, data, y, , cutpoint)
vr = _view_y!(yr, feat_data, y, , cutpoint)
isempty(vr) && continue
gain = _information_gain(y, vl, vr, classes, starting_impurity)
if best_score gain
Expand Down

0 comments on commit 7ef3cb5

Please sign in to comment.