updated all to 32-bit to save registers and boost performance
Some checks failed
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.10) (push) Has been cancelled
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.6) (push) Has been cancelled
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, pre) (push) Has been cancelled

This commit is contained in:
2024-11-01 11:23:58 +01:00
parent 9fc55c4c15
commit 68cedd75fc
7 changed files with 113 additions and 106 deletions

View File

@ -3,8 +3,8 @@ using .ExpressionProcessing
using .Interpreter
expressions = Vector{Expr}(undef, 2)
variables = Matrix{Float64}(undef, 2,2)
parameters = Vector{Vector{Float64}}(undef, 2)
variables = Matrix{Float32}(undef, 2,2)
parameters = Vector{Vector{Float32}}(undef, 2)
# Resulting value should be 10 for the first expression
expressions[1] = :(x1 + 1 * x2 + p1)
@ -13,34 +13,36 @@ variables[1,1] = 2.0
variables[2,1] = 3.0
variables[1,2] = 0.0
variables[2,2] = 5.0
parameters[1] = Vector{Float64}(undef, 1)
parameters[2] = Vector{Float64}(undef, 2)
parameters[1] = Vector{Float32}(undef, 1)
parameters[2] = Vector{Float32}(undef, 2)
parameters[1][1] = 5.0
parameters[2][1] = 5.0
parameters[2][2] = 0.0
function testHelper(expression::Expr, variables::Matrix{Float64}, parameters::Vector{Vector{Float64}}, expectedResult::Float64)
function testHelper(expression::Expr, variables::Matrix{Float32}, parameters::Vector{Vector{Float32}}, expectedResult)
postfix = Vector([expr_to_postfix(expression)])
result = Interpreter.interpret(postfix, variables, parameters)
@test isequal(result[1,1], expectedResult)
expectedResult32 = convert(Float32, expectedResult)
@test isequal(result[1,1], expectedResult32)
end
@testset "Test conversion to matrix" begin
reference = Matrix{Float64}(undef, 2, 2)
reference = Matrix{Float32}(undef, 2, 2)
reference[1,1] = 5.0
reference[2,1] = NaN64
reference[2,1] = NaN32
reference[1,2] = 5.0
reference[2,2] = 0.0
# reference = Matrix([5.0, NaN],
# [5.0, 0.0])
result = Interpreter.convert_to_matrix(parameters, NaN64)
result = Interpreter.convert_to_matrix(parameters, NaN32)
@test isequal(result, reference)
end
@testset "Test commutative interpretation" begin
var = Matrix{Float64}(undef, 2, 1)
param = Vector{Vector{Float64}}(undef, 1)
var = Matrix{Float32}(undef, 2, 1)
param = Vector{Vector{Float32}}(undef, 1)
expectedResult = 8.0 # Not using "eval" because the variables are not stored in global scope
var[1,1] = 3.0
@ -59,8 +61,8 @@ end
end
@testset "Test non commutative interpretation" begin
var = Matrix{Float64}(undef, 2, 1)
param = Vector{Vector{Float64}}(undef, 1)
var = Matrix{Float32}(undef, 2, 1)
param = Vector{Vector{Float32}}(undef, 1)
expectedResult = -2.0 # Not using "eval" because the variables are not stored in global scope
var[1,1] = 3.0
@ -89,8 +91,8 @@ end
end
@testset "Test single value operator interpretation" begin
var = Matrix{Float64}(undef, 1, 1)
param = Vector{Vector{Float64}}(undef, 1)
var = Matrix{Float32}(undef, 1, 1)
param = Vector{Vector{Float32}}(undef, 1)
expectedResult = 3.0 # Not using "eval" because the variables are not stored in global scope
var[1,1] = -3.0
@ -108,8 +110,8 @@ end
end
@testset "Test complex expressions" begin
var = Matrix{Float64}(undef, 2, 2)
param = Vector{Vector{Float64}}(undef, 2)
var = Matrix{Float32}(undef, 2, 2)
param = Vector{Vector{Float32}}(undef, 2)
# var set 1
var[1,1] = 3.0