Skip to content

Commit ad97847

Browse files
committed
Switch to unsigned integers
1 parent f6099a6 commit ad97847

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/Equation.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ nodes, you can evaluate or print a given expression.
1616
1717
# Fields
1818
19-
- `degree::Int8`: Degree of the node. 0 for constants, 1 for
19+
- `degree::UInt8`: Degree of the node. 0 for constants, 1 for
2020
unary operators, 2 for binary operators.
2121
- `constant::Bool`: Whether the node is a constant.
2222
- `val::T`: Value of the node. If `degree==0`, and `constant==true`,
2323
this is the value of the constant. It has a type specified by the
2424
overall type of the `Node` (e.g., `Float64`).
25-
- `feature::Int16` (optional): Index of the feature to use in the
25+
- `feature::UInt16`: Index of the feature to use in the
2626
case of a feature node. Only used if `degree==0` and `constant==false`.
2727
Only defined if `degree == 0 && constant == false`.
28-
- `op::Int8`: If `degree==1`, this is the index of the operator
28+
- `op::UInt8`: If `degree==1`, this is the index of the operator
2929
in `operators.unaops`. If `degree==2`, this is the index of the
3030
operator in `operators.binops`. In other words, this is an enum
3131
of the operators, and is dependent on the specific `OperatorEnum`
@@ -37,23 +37,23 @@ nodes, you can evaluate or print a given expression.
3737
argument to the binary operator.
3838
"""
3939
mutable struct Node{T}
40-
degree::Int8 # 0 for constant/variable, 1 for cos/sin, 2 for +/* etc.
40+
degree::UInt8 # 0 for constant/variable, 1 for cos/sin, 2 for +/* etc.
4141
constant::Bool # false if variable
4242
val::Union{T,Nothing} # If is a constant, this stores the actual value
4343
# ------------------- (possibly undefined below)
44-
feature::Int16 # If is a variable (e.g., x in cos(x)), this stores the feature index.
45-
op::Int8 # If operator, this is the index of the operator in operators.binary_operators, or operators.unary_operators
44+
feature::UInt16 # If is a variable (e.g., x in cos(x)), this stores the feature index.
45+
op::UInt8 # If operator, this is the index of the operator in operators.binary_operators, or operators.unary_operators
4646
l::Node{T} # Left child node. Only defined for degree=1 or degree=2.
4747
r::Node{T} # Right child node. Only defined for degree=2.
4848

4949
#################
5050
## Constructors:
5151
#################
52-
Node(d::Integer, c::Bool, v::_T) where {_T} = new{_T}(Int8(d), c, v)
53-
Node(::Type{_T}, d::Integer, c::Bool, v::_T) where {_T} = new{_T}(Int8(d), c, v)
54-
Node(::Type{_T}, d::Integer, c::Bool, v::Nothing, f::Integer) where {_T} = new{_T}(Int8(d), c, v, Int16(f))
55-
Node(d::Integer, c::Bool, v::Nothing, f::Integer, o::Integer, l::Node{_T}) where {_T} = new{_T}(Int8(d), c, v, Int16(f), Int8(o), l)
56-
Node(d::Integer, c::Bool, v::Nothing, f::Integer, o::Integer, l::Node{_T}, r::Node{_T}) where {_T} = new{_T}(Int8(d), c, v, Int16(f), Int8(o), l, r)
52+
Node(d::Integer, c::Bool, v::_T) where {_T} = new{_T}(UInt8(d), c, v)
53+
Node(::Type{_T}, d::Integer, c::Bool, v::_T) where {_T} = new{_T}(UInt8(d), c, v)
54+
Node(::Type{_T}, d::Integer, c::Bool, v::Nothing, f::Integer) where {_T} = new{_T}(UInt8(d), c, v, UInt16(f))
55+
Node(d::Integer, c::Bool, v::Nothing, f::Integer, o::Integer, l::Node{_T}) where {_T} = new{_T}(UInt8(d), c, v, UInt16(f), UInt8(o), l)
56+
Node(d::Integer, c::Bool, v::Nothing, f::Integer, o::Integer, l::Node{_T}, r::Node{_T}) where {_T} = new{_T}(UInt8(d), c, v, UInt16(f), UInt8(o), l, r)
5757

5858
end
5959
################################################################################
@@ -138,7 +138,7 @@ end
138138
139139
Create a variable node, using the format `"x1"` to mean feature 1
140140
"""
141-
Node(var_string::String) = Node(; feature=parse(Int16, var_string[2:end]))
141+
Node(var_string::String) = Node(; feature=parse(UInt16, var_string[2:end]))
142142

143143
"""
144144
Node(var_string::String, variable_names::Array{String, 1})
@@ -258,7 +258,7 @@ Convert an equation to a string.
258258
259259
# Keyword Arguments
260260
- `bracketed`: (optional) whether to put brackets around the outside.
261-
- `f_variable`: (optional) function to convert a variable to a string, of the form `(feature::Int8, variable_names)`.
261+
- `f_variable`: (optional) function to convert a variable to a string, of the form `(feature::UInt8, variable_names)`.
262262
- `f_constant`: (optional) function to convert a constant to a string, of the form `(val, bracketed::Bool)`
263263
- `variable_names::Union{Array{String, 1}, Nothing}=nothing`: (optional) what variables to print for each feature.
264264
"""

src/EvaluateEquationDerivative.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function eval_grad_tree_array(
200200
)::Tuple{AbstractVector{T},AbstractMatrix{T},Bool} where {T<:Number}
201201
assert_autodiff_enabled(operators)
202202
n_gradients = variable ? size(cX, 1) : count_constants(tree)
203-
index_tree = index_constants(tree, 0)
203+
index_tree = index_constants(tree, Int16(0))
204204
return eval_grad_tree_array(
205205
tree,
206206
Val(n_gradients),

0 commit comments

Comments
 (0)