Skip to content

Commit 1422e36

Browse files
committed
refactor: clean up extensions
1 parent 9f49619 commit 1422e36

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

ext/DynamicExpressionsCUDAExt.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ function eval_tree_array(
5151
## the GPU kernel, with size equal to the number of rows
5252
## in the input data by the number of nodes in the tree.
5353
## It has one extra row to store the constant values.
54-
gworkspace = if gpu_workspace === nothing
55-
similar(gcX, num_elem + 1, num_nodes)
56-
else
57-
gpu_workspace
58-
end
54+
gworkspace = @something(gpu_workspace, similar(gcX, num_elem + 1, num_nodes))
5955
gval = @view gworkspace[end, :]
6056
if _update_buffers
6157
copyto!(gval, val)

src/AsArray.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ module AsArrayModule
22

33
using ..NodeModule: AbstractExpressionNode, tree_mapreduce, count_nodes
44

5+
function as_array(
6+
::Type{I}, trees::N; buffer=nothing
7+
) where {T,N<:AbstractExpressionNode{T},I}
8+
return as_array(I, (trees,); buffer=buffer)
9+
end
10+
511
function as_array(
612
::Type{I},
7-
trees::Union{N,Tuple{N,Vararg{N}},AbstractVector{N}};
13+
trees::Union{Tuple{N,Vararg{N}},AbstractVector{N}};
814
buffer::Union{AbstractArray,Nothing}=nothing,
915
) where {T,N<:AbstractExpressionNode{T},I}
10-
if trees isa N
11-
return as_array(I, (trees,); buffer=buffer)
12-
end
1316
each_num_nodes = (t -> count_nodes(t; break_sharing=Val(true))).(trees)
1417
num_nodes = sum(each_num_nodes)
1518

@@ -25,7 +28,7 @@ function as_array(
2528
val = Array{T}(undef, num_nodes)
2629

2730
## Views of the same matrix:
28-
buffer = buffer === nothing ? Array{I}(undef, 8, num_nodes) : buffer
31+
buffer = @something(buffer, Array{I}(undef, 8, num_nodes))
2932
degree = @view buffer[1, :]
3033
feature = @view buffer[2, :]
3134
op = @view buffer[3, :]

0 commit comments

Comments
 (0)