2024-07-21 13:45:57 +02:00
|
|
|
using CUDA
|
2024-07-14 15:08:05 +02:00
|
|
|
using .ExpressionProcessing
|
|
|
|
using .Interpreter
|
|
|
|
|
2024-07-21 13:45:57 +02:00
|
|
|
expressions = Vector{Expr}(undef, 2)
|
|
|
|
variables = Matrix{Float64}(undef, 2,2)
|
|
|
|
parameters = Vector{Vector{Float64}}(undef, 2)
|
2024-07-14 15:08:05 +02:00
|
|
|
|
2024-07-24 14:42:26 +02:00
|
|
|
# Resulting value should be 10 for the first expression
|
2024-07-14 15:08:05 +02:00
|
|
|
expressions[1] = :(x1 + 1 * x2 + p1)
|
2024-07-21 13:45:57 +02:00
|
|
|
expressions[2] = :(5 + x1 + 1 * x2 + p1 + p2)
|
|
|
|
variables[1,1] = 2.0
|
2024-08-03 12:11:43 +02:00
|
|
|
variables[2,1] = 3.0
|
|
|
|
variables[1,2] = 0.0
|
2024-07-24 14:42:26 +02:00
|
|
|
variables[2,2] = 5.0
|
2024-07-14 15:08:05 +02:00
|
|
|
parameters[1] = Vector{Float64}(undef, 1)
|
2024-07-21 13:45:57 +02:00
|
|
|
parameters[2] = Vector{Float64}(undef, 2)
|
|
|
|
parameters[1][1] = 5.0
|
|
|
|
parameters[2][1] = 5.0
|
|
|
|
parameters[2][2] = 0.0
|
2024-07-14 15:08:05 +02:00
|
|
|
|
|
|
|
@testset "Test interpretation" begin
|
|
|
|
postfixExpr = expr_to_postfix(expressions[1])
|
2024-07-21 13:45:57 +02:00
|
|
|
postfixExprs = Vector([postfixExpr])
|
|
|
|
push!(postfixExprs, expr_to_postfix(expressions[2]))
|
2024-07-14 15:08:05 +02:00
|
|
|
|
2024-07-21 13:45:57 +02:00
|
|
|
CUDA.@sync interpret(postfixExprs, variables, parameters)
|
|
|
|
end
|
|
|
|
|
|
|
|
@testset "Test conversion to matrix" begin
|
|
|
|
reference = Matrix{Float64}(undef, 2, 2)
|
|
|
|
reference[1,1] = 5.0
|
|
|
|
reference[2,1] = NaN64
|
|
|
|
reference[1,2] = 5.0
|
|
|
|
reference[2,2] = 0.0
|
|
|
|
# fill!(reference, [[], [5.0, 0.0]])
|
|
|
|
# reference = Matrix([5.0, NaN],
|
|
|
|
# [5.0, 0.0])
|
|
|
|
result = Interpreter.convert_to_matrix(parameters, NaN64)
|
|
|
|
|
|
|
|
@test isequal(result, reference)
|
2024-08-08 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# TODO: Add several tests fo the mathematical expressions
|
|
|
|
# One test for each operator. A second test if the operation order matters
|
|
|
|
# And some more complicated expressions, with some only having variables, some only having parameters and some having both
|