Unexpected behavior of VECTOR values assignment
Description
When initializing a vector one can assing the values to the vector in different (presummably wrong) ways and some of them will silently pass as ok but not with the expected behavior.
VECTOR x1 SIZE 2
VECTOR x2 SIZE 2
VECTOR x3 SIZE 2
VECTOR x4[2] DATA 1/sqrt(2) 1/sqrt(2)
x1 = {1/sqrt(2), 1/sqrt(2)}
x2 = (1/sqrt(2), 1/sqrt(2))
x3 = 1/sqrt(2) 1/sqrt(2)
print "x1= " x1 "\nx2= " x2 "\nx3= " x3 "\nx4= " x4
>>>x1= 0.5 0.5
x2= 0.5 0.5
x3= 0.707107 0.707107
x4= 0.707107 0.707107
Expected Behavior
Either the vectors having assigned the right values or a Syntax error.
Steps to Reproduce
- Run the code block in FeenoX.
Additional Information
- FeenoX version: FeenoX v1.0.64-g8c2e75b Build architecture : linux-gnu x86_64 Compiler version : gcc (Spack GCC) 12.1.0 Compiler expansion : /usr/local/pace-apps/spack/packages/linux-rhel7-x86_64_v3/gcc-4.8.5/gcc-12.1.0-qgxpzkq64xukc4zdq2cucb5pw5iqrzjg/bin/gcc Compiler flags : -O3 -flto=auto -no-pie Builder : [email protected] GSL version : 2.8 SUNDIALS version : N/A PETSc version : N/A SLEPc version : N/A
Also tried using
- FeenoX version: FeenoX v0.2-dirty Build architecture : cygwin x86_64 Compiler : gcc (GCC) 10.2.0 Compiler flags : -Ofast -DLD_STATIC Builder : jerem@DESKTOP-CSOL4OE GSL version : 2.7 SUNDIALS version : N/A PETSc version : Petsc Release Version 3.16.2, Dec 07, 2021 PETSc arch : cygwin-serial-static PETSc options : PETSC_DIR=/home/jerem/feenox/dist/petsc-3.16.2 PETSC_ARCH=cygwin-serial-static --with-mpi=0 --with-fc=0 --with-cxx=0 --with-fortran-bindings=0 --with-fc=0 --with-c2html=0 --with-x=0 --with-debugging=0 --with-shared-libraries=0 --download-f2cblaslapack --COPTFLAGS=-Ofast SLEPc version : SLEPc Release Version 3.16.1, Nov 17, 2021
Thank you for looking into this!
Good catch. This input better illustrates what is going on:
VECTOR x1[2]
VECTOR x2[2]
VECTOR x3[2]
VECTOR x4[2] DATA 1 2
x1 = {3, 4}
x2 = (5, 6)
x3 = 7 8
PRINT x1
PRINT x2
PRINT x3
PRINT x4
The current (bad) output is
3 3
5 5
7 7
1 2
- The right way (so far) is
x4 - The braces work as multi-line wrappers so
x1is the same asx1 = 3,4
What do you think should the alternate to x4 be @ignaciobartol so I implement it? x2 seems good to me...
Thanks for reviewing this. That better reflects the error, mine wasn't catching x3. I think x2 it's good as long as there is any kind of warning when trying any other of the alternatives.
Out of curiosity, where is VECTOR defined?
Out of curiosity, where is VECTOR defined?
What do you mean? In FeenoX source code? Or what?
What do you mean? In FeenoX source code? Or what?
Yes, I was trying to find the #define VECTOR line or something similar but I guess it's inherited from other library? I didn't dig too much into the code, but are you planning on modifying src/math/expressions.c#L160 to handle this?
Not sure what you mean by #define VECTOR or "inherited from other library."
FeenoX's parser detects a keyword VECTOR here https://github.com/seamplex/feenox/blob/main/src/parser/parser.c#L173 and then proceeds to feenox_parse_vector().
I plan to modify this block: https://github.com/seamplex/feenox/blob/main/src/parser/parser.c#L401
@ignaciobartol can you check if PR #21 does what you expect?
I got
error: ../problem_bug.fee: 6: right hand side for vector initialization has to be inside brackets '(' and ')' .
which looks good to me! Thanks a lot for this! Feel free to close this issue.
Cool. If you do add the brackets, do you get the expected result?