Closed EmilyBourne closed 2 weeks ago
At first glance this seems to just be a kind mismatch. You have defined the vector using default integers (usually this is INT32), but your attempt to use the container is with INT64. Your example programs do not actually define a value of i64
so presumably do not compile as written above.
If my analysis is correct then you should either change the declaration of T to be:
#define T integer(i64)
or change the usage to be
a = [1,2,3]
Ah - another problem may be that you have not indicated to the templating layer that your type has certain necessary properties (listable) to be used in your context. There is special support for intrinsics to spare you the details:
Either use:
#define T __INTEGER
or
#define T __INTEGER64
Thank you very much for the speedy reply. By changing the usage to:
a = [1,2,3]
I get the linker error:
test_program.F90:(.text+0x16f): undefined reference to `__vector_integer_mod_MOD_vector_new_vector_initializer_list'
which is presumably due to the fact that I haven't indicated to the templating layer that the type is listable.
I also tried:
#define T integer(8)
however I couldn't get this to compile. The error is:
/home/emily/Code/pyccel/pyccel/extensions/gFTL/include/v2/parameters/define_derived_macros.m4:64:0:
64 | #if __T() > 0
|
Error: missing binary operator before token "("
/home/emily/Code/pyccel/pyccel/extensions/gFTL/include/v2/parameters/define_derived_macros.m4:64:0:
64 | #if __T() > 0
|
Error: missing binary operator before token "("
/home/emily/Code/pyccel/pyccel/extensions/gFTL/include/v2/parameters/define_derived_macros.m4:64:0:
64 | #if __T() > 0
|
Error: missing binary operator before token "("
/home/emily/Code/pyccel/pyccel/extensions/gFTL/include/v2/parameters/define_derived_macros.m4:64:0:
64 | #if __T() > 0
|
Error: missing binary operator before token "("
I also didn't manage to use the intrinsics. Using #define T __INTEGER64
I get quite a long error message.
The crux of which seems to be:
Symbol ‘int64’ at (1) has no IMPLICIT type
I found this example: https://github.com/Goddard-Fortran-Ecosystem/gFTL/blob/main/include/v2/examples/integer64.m4
which may be relevant but it includes types/integer.inc
which seems to be a file from v1.
Actually the linker error is just because I forgot to link the .o file. Using a = [1,2,3]
works correctly. It seems that gFTL is able to deduce the fact that it is listable in this case.
For the kind parameter I found the KINDLEN
keyword here:
https://github.com/Goddard-Fortran-Ecosystem/gFTL/blob/45b4d4a044f2a2796f07c6e69e01847d2b0d7228/include/v2/examples/integer64.m4#L7-L8
If I include the first line then the file Vector_integer_mod.F90
compiles but if I also include the second line then I get the warning:
gFTL_extensions/Vector_integer_mod.F90:5:0:
5 | #define _T()_kindlen_string "(kind=8)"
|
Warning: "_T" redefined
gFTL_extensions/Vector_integer_mod.F90:4:0:
4 | #define _T()_KINDLEN(context) (kind=8)
|
note: this is the location of the previous definition
regardless this doesn't seem to affect the kind of the integer stored in the vector as I still get the error:
test_program.F90:10:7:
10 | b = Vector_integer(a)
| 1
Error: Component ‘elements’ at (1) is a PRIVATE component of ‘vector_integer’
when compiling the program that uses the type
After some digging I have found this:
module Vector_integer_mod
#define T integer
#define T_KINDLEN(context) (kind=8)
#define Vector Vector_integer
#define VectorIterator Vector_integer_Iterator
#include <vector/template.inc>
end module Vector_integer_mod
which seems to work. This is actually documented. It just wasn't clear to me how it should be used. I must have either missed it or tried a different syntax that didn't work.
Would you like me to create a PR to add an example for this? If so should it go directly in the docs or should it go here: https://github.com/Goddard-Fortran-Ecosystem/gFTL/blob/main/include/v2/examples ? Or somewhere else?
@EmilyBourne I am glad you found a combination that you are happy with. And I'm more than happy to accept contributions to the examples. The directory you suggest above is a bit weird in that it really is a collection of m4 definitions that allows cmake to build a variety of include files. Not really full fledged examples. (And I should note that it includes integer.m4, which is your use case.)
I would also like to point out that if you are primarily interested in containers with intrinsic types, there is a separate repo: https://github.com/Goddard-Fortran-Ecosystem/gFTL-shared that creates templates for most common cases (and then some). This is especially useful when you want to pass containers between multiple layers in a large project.
What is really needed is a v2 replacement for these examples. I can probably meet you half way if you want to start a new v2-examples directory. I'm loathe to write documentation on my own but can easily be prodded to collaborate.
@tclune
I have created a PR #239 adding the v2 examples for vectors. I am happy to give you a hand with documentation if you can help me fill in the gaps
Hi @EmilyBourne . My apologies - I meant to look at this over the weekend. I hope to get back to you later in the week on this.
According to the documentation it should be possible to create a Vector from an array of elements. However I cannot get a MRE to work. My code is:
I also tried:
In both cases I get the error:
I don't know if I am using the function wrong or if this is simply a bug. I could not find a test for this function here.
Compiler: GNU Fortran 11.4.0 OS: Ubuntu 22.04