Skip to content
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

Precompiled trees #12

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ using ExpressionTreeForge:
M_implementation_expr_tree_Expr,
M_implementation_expr_tree,
M_implementation_complete_expr_tree,
M_implementation_pre_compiled_tree,
M_implementation_pre_n_compiled_tree,
M_evaluation_expr_tree,
M_bound_propagations,
M_convexity_detection,
Expand Down Expand Up @@ -51,6 +53,8 @@ makedocs(
M_implementation_expr_tree_Expr,
M_implementation_expr_tree,
M_implementation_complete_expr_tree,
M_implementation_pre_compiled_tree,
M_implementation_pre_n_compiled_tree,
M_evaluation_expr_tree,
M_bound_propagations,
M_convexity_detection,
Expand Down
2 changes: 1 addition & 1 deletion docs/src/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ Pages = ["reference.md"]
```
```@autodocs
Modules = [ExpressionTreeForge, M_abstract_expr_tree, M_trait_expr_tree, M_interface_expr_tree, M_implementation_expression_tree_Expr, M_implementation_expr_tree_Expr, M_implementation_expr_tree, M_implementation_complete_expr_tree, M_evaluation_expr_tree, M_bound_propagations, M_convexity_detection, algo_expr_tree, M_trait_expr_node, M_interface_expr_node, M_variable, M_variables_view, M_variables_n_view, M_times_operator, M_tan_operator, M_sinus_operator, M_simple_operator, M_power_operator, M_plus_operator, M_minus_operator, M_frac_operator, M_exp_operator, M_cos_operator, M_constant, M_abstract_expr_node, M_trait_tree, algo_tree, M_interface_tree, M_implementation_tree, M_implementation_tree_Expr, M_abstract_tree, M_trait_type_expr, M_interface_type_expr, M_implementation_type_expr, M_implementation_convexity_type]
Modules = [ExpressionTreeForge, M_abstract_expr_tree, M_trait_expr_tree, M_interface_expr_tree, M_implementation_expression_tree_Expr, M_implementation_expr_tree_Expr, M_implementation_expr_tree, M_implementation_complete_expr_tree, M_evaluation_expr_tree, M_implementation_pre_compiled_tree M_implementation_pre_n_compiled_tree, M_bound_propagations, M_convexity_detection, algo_expr_tree, M_trait_expr_node, M_interface_expr_node, M_variable, M_variables_view, M_variables_n_view, M_times_operator, M_tan_operator, M_sinus_operator, M_simple_operator, M_power_operator, M_plus_operator, M_minus_operator, M_frac_operator, M_exp_operator, M_cos_operator, M_constant, M_abstract_expr_node, M_trait_tree, algo_tree, M_interface_tree, M_implementation_tree, M_implementation_tree_Expr, M_abstract_tree, M_trait_type_expr, M_interface_type_expr, M_implementation_type_expr, M_implementation_convexity_type]
```
3 changes: 2 additions & 1 deletion src/ExpressionTreeForge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ include("expr_tree/ordered_include.jl")

using .algo_expr_tree, .M_evaluation_expr_tree, .M_trait_expr_tree, .M_implementation_type_expr
using .algo_tree
using .M_implementation_complete_expr_tree
using .M_implementation_complete_expr_tree,
.M_implementation_pre_compiled_tree, .M_implementation_pre_n_compiled_tree
using .M_bound_propagations, .M_convexity_detection

include("export.jl")
Expand Down
50 changes: 50 additions & 0 deletions src/export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ A `Complete_expr_tree` has fields:
"""
Complete_expr_tree{T <: Number} = M_implementation_complete_expr_tree.Complete_expr_tree{T}

"""
Pre_compiled_tree{T} <: AbstractExprTree

Implementation of an expression tree where the value of the children is accessible from the parent using `MyRef`.
A `Pre_compiled_tree` has fields:

* `root::New_node{Y}` representing an expression tree;
* `x::AbstractVector{Y}` the vector evaluating `root`.
"""
Pre_compiled_tree{T <: Number} = M_implementation_pre_compiled_tree.Pre_compiled_tree{T}

"""
Pre_n_compiled_tree{Y <: Number} <: AbstractExprTree

Represent an expression tree that can be evaluate simultaneously by several points.
It has the fields:

* `root::Eval_n_node{Y}` the root of the expression tree;
* `multiple_x::Vector{AbstractVector{Y}}` the multiple inputs `x` of the `Pre_n_compiled_tree`
* `multiple::Int` the number of simultaneous evaluation supported;
* `vec_tmp::Vector{M_abstract_expr_node.MyRef{Y}}` the result of the `multiple` evaluations.
"""
Pre_n_compiled_tree{T <: Number} = M_implementation_pre_n_compiled_tree.Pre_n_compiled_tree{T}

"""
Type_calculus_tree

Expand Down Expand Up @@ -204,6 +228,29 @@ Create a `complete_tree::Complete_expr_tree` from `expression_tree` (`::Type_exp
@inline create_complete_tree(tree) =
M_implementation_complete_expr_tree.create_complete_expr_tree(tree)

"""
precompiled_tree = create_pre_compiled_tree(expression_tree, x::AbstractVector)

Create a `precompiled_tree::Pre_compiled_tree` from `expression_tree` (`::Type_expr_tree` for now).
"""
@inline create_pre_compiled_tree(tree, x::AbstractVector) =
M_implementation_pre_compiled_tree.create_pre_compiled_tree(tree, x)

"""
pre_n_compiled_tree = create_pre_n_compiled_tree(tree, x::Vector{Vector{T}}) where {T <: Number}
pre_n_compiled_tree = create_pre_n_compiled_tree(tree, multiple_x_view::Vector{SubArray{T, 1, Array{T, 1}, N, false}}) where {N} where {T <: Number}

Create a `pre_n_compiled_tree::Pre_n_compiled_tree` from `expression_tree` (`::Type_expr_tree` for now).
"""
@inline create_pre_n_compiled_tree(tree, x::Vector{Vector{T}}) where {T <: Number} =
M_implementation_pre_n_compiled_tree.create_pre_n_compiled_tree(tree, x)

@inline create_pre_n_compiled_tree(
tree,
multiple_x_view::Vector{SubArray{T, 1, Array{T, 1}, N, false}},
) where {N} where {T <: Number} =
M_implementation_pre_n_compiled_tree.create_pre_n_compiled_tree(tree, multiple_x_view)

"""
bool = is_constant(type::Type_calculus_tree)

Expand Down Expand Up @@ -378,6 +425,9 @@ Evaluate the `expression_tree` with several points, represented as `x`.
@inline evaluate_expr_tree_multiple_points(expression_tree::Any, x::AbstractVector) =
M_evaluation_expr_tree.evaluate_expr_tree_multiple_points(expression_tree, x)

@inline evaluate_expr_tree_multiple_points(expression_tree::Any) =
M_implementation_pre_n_compiled_tree.evaluate_pre_n_compiled_tree(expression_tree)

"""
gradient = gradient_expr_tree_forward(expr_tree, x)

Expand Down
21 changes: 20 additions & 1 deletion src/expr_tree/eval_expr_tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module M_evaluation_expr_tree
using ForwardDiff, ReverseDiff

using ..M_trait_expr_tree, ..M_trait_expr_node
using ..M_implementation_expr_tree, ..M_implementation_complete_expr_tree
using ..M_implementation_expr_tree,
..M_implementation_complete_expr_tree
using ..M_implementation_pre_compiled_tree, ..M_implementation_pre_n_compiled_tree
using ..M_abstract_expr_node

# IMPORTANT The fonction evaluate_expr_tree keep the type of x
Expand Down Expand Up @@ -100,6 +102,11 @@ end
end
end

@inline _evaluate_expr_tree(
tree::M_implementation_pre_compiled_tree.Pre_compiled_tree{T},
x::AbstractVector{T},
) where {T <: Number} = M_implementation_pre_compiled_tree.evaluate_pre_compiled_tree(tree, x)

@inline evaluate_expr_tree_multiple_points(a::Any, x::Array{Array{T, 1}, 1}) where {T <: Number} =
_evaluate_expr_tree_multiple_points(a, M_trait_expr_tree.is_expr_tree(a), x)

Expand Down Expand Up @@ -177,6 +184,18 @@ end
end
end

@inline evaluate_expr_tree_multiple_points(
tree::M_implementation_pre_n_compiled_tree.Pre_n_compiled_tree{T},
multiple_x::Vector{Vector{T}},
) where {T <: Number} =
M_implementation_pre_n_compiled_tree.evaluate_pre_n_compiled_tree(tree, multiple_x)

@inline evaluate_expr_tree_multiple_points(
tree::M_implementation_pre_n_compiled_tree.Pre_n_compiled_tree{T},
multiple_x_view::Array{SubArray{T, 1, Array{T, 1}, N, false}, 1},
) where {N} where {T <: Number} =
M_implementation_pre_n_compiled_tree.evaluate_pre_n_compiled_tree(tree, multiple_x_view)

function _evaluate_expr_tree_multiple_points(
expr_tree_cmp::M_implementation_complete_expr_tree.Complete_expr_tree,
xs::Array{SubArray{T, 1, Array{T, 1}, N, true}, 1},
Expand Down
Loading