Skip to content

Commit

Permalink
changed tensor init to expression
Browse files Browse the repository at this point in the history
= committed Dec 11, 2024
1 parent bbd99a4 commit e533e6b
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Galley/ExecutionEngine/execution-engine.jl
Original file line number Diff line number Diff line change
@@ -143,8 +143,10 @@ function execute_query(alias_dict, q::PlanNode, verbose, cannonicalize, return_p
|> Finch.dataflow
|> Finch.unquote_literals)
verbose >= 2 && println("Expected Output Size: $(estimate_nnz(agg_expr.stats))")

if return_prgm
return :($output_name = $output_tensor), prgm_instance
output_tensor_init = tensor_initializer(output_formats, output_dimensions, output_default)
return :($output_name = $output_tensor_init), prgm_instance
end
start_time = time()
Finch.execute(prgm_instance, mode=:fast)
2 changes: 1 addition & 1 deletion src/Galley/PlanAST/plan.jl
Original file line number Diff line number Diff line change
@@ -200,7 +200,7 @@ function Base.setproperty!(node::PlanNode, sym::Symbol, v)
elseif node.kind === Query && sym === :expr node.children[2] = v
elseif node.kind === Query && sym === :loop_order begin node.children = [node.name, node.expr, v...] end
elseif node.kind === Outputs && sym === :names node.children = v
elseif node.kind === Plan && sym === :queries begin println([v...]); node.children = [v...] end
elseif node.kind === Plan && sym === :queries begin node.children = [v...] end

Check warning on line 203 in src/Galley/PlanAST/plan.jl

Codecov / codecov/patch

src/Galley/PlanAST/plan.jl#L203

Added line #L203 was not covered by tests
else
error("type PlanNode($(node.kind), ...) has no property $sym")
end
18 changes: 18 additions & 0 deletions src/Galley/utility-funcs.jl
Original file line number Diff line number Diff line change
@@ -74,6 +74,24 @@ function initialize_tensor(formats, dims, default_value; copy_data = nothing, st
end
end

function tensor_initializer(formats, dims, default_value)
B = :(Element($default_value))
for i in range(1, length(dims))
DT = get_dim_type(dims[i])
if formats[i] == t_sparse_list
B = :(SparseList($B, $(DT(dims[i]))))
elseif formats[i] == t_dense
B = :(Dense($B, $(DT(dims[i]))))
elseif formats[i] == t_bytemap
B = :(SparseByteMap($B, $(DT(dims[i]))))

Check warning on line 86 in src/Galley/utility-funcs.jl

Codecov / codecov/patch

src/Galley/utility-funcs.jl#L86

Added line #L86 was not covered by tests
elseif formats[i] == t_hash
B = :(SparseDict($B, $(DT(dims[i]))))
else
println("Error: Attempted to initialize invalid level format type.")

Check warning on line 90 in src/Galley/utility-funcs.jl

Codecov / codecov/patch

src/Galley/utility-funcs.jl#L90

Added line #L90 was not covered by tests
end
end
return :(Tensor($B))
end

# Generates a tensor whose non-default entries are distributed uniformly randomly throughout.
function uniform_tensor(shape, sparsity; formats = [], default_value = 0, non_default_value = 1)

0 comments on commit e533e6b

Please sign in to comment.