- Fortran array is in column-first order
- for a 2d array, it means when initializing a 1d array by sequence, it follows the order of
a(1)(1) -> a(2)(1) -> a(1)(2) -> a(1)(2) - similarly, for a nd array, index increase from the left-most to the right-most
- for details refer to
array_builderrule in /src/grammar/for90.y
- for a 2d array, it means when initializing a 1d array by sequence, it follows the order of
- Fortran array is 1-indexed array, and it can be negative; each dimension of C++ style array is 0-indexed array
- Fortran array rank(also called dim in Fortran standard, but called fordim in order to distinguish with C++'s dimension) start from 1, C++ array dimension start from 0
- parameter for most
for-functions use rank other than dimension, in order to be compactable with Fortran source codes.
- parameter for most
#define USE_FORARRAYto use Fortran style array,#define USE_CARRAYto use c style arrayfarrayset no limit to rank, in Fortran90, the maximun rank is 7
struct slice_info<T> implement for a slice in Fortran
slice_info<T>{T x}: stands for the scalarx,xis an index not a rangeslice_info<T>{T x, T y}:x,ystands for a range of [x, y] of default step 1slice_info<T>{T x, T y, T z}:x,y,zstands for a range of [x, y] stepz
template <typename T, int X> auto forslice(const farray<T> & farr, const slice_info<fsize_t>(&tp)[X]) returns an array section by tp, an array of slice_info<fsize_t>
tp has length X, represents slice_info<fsize_t> data of the first X dimension, X is not always equal to farr.dimension
farray is a multi-dimentional array defined in /for90std/farray.h.
DON'T call member function of farray directly
-
Construct an array
-
Construct an array by given lower bound and size of each dimension
farray<T>(int dimension, Iterator lower_bound, Iterator size) farray<T>(const size_type(&lower_bound)[D], const size_type(&size)[D]) -
Construct an array by given lower bound and size of each dimension, and assign an 1d list to the array
farray<T>(const size_type(&lower_bound)[D], const size_type(&size)[D], Iterator begin, Iterator end) farray<T>(const size_type(&lower_bound)[D], const size_type(&size)[D], const T(&values)[X]) -
Implicitly construct an 1d array from a scalar
farray<T>(const T & scalar) -
Construct an array by given lower bound and size of each dimension, and assign another array's value(NOT including shape) to the array
farray(const size_type(&lower_bound)[D], const size_type(&size)[D], const farray<T> & m) -
Construct an array by given lower bound and size of each dimension, and assign another array's value(AND shape) to the array
farray(const farray<T> & m) // copy constructor
-
-
Assign value to an array without chaning shape
ALL these functions do NOT change the shape of
farritself. They all calloperator=by implemetation.-
Assign from a list:
farr = make_init_list(Iterator list_begin, Iterator list_end) farr = make_init_list(const T(&values)[X]) -
Assign from implied
do-loop Important:fromandtoarguments do NOT indicate the shape of farr. they indicate the implieddo-loop will loop fromfrom[dimension]toto[dimension]in each dimensionfarr = make_init_list(const fsize_t(&from)[D], const fsize_t(&size)[D], F f) -
Assign from a scalar
farr = make_init_list(const T & scalar) -
Assign from a list of a scalar repeated by
repeattimesfarr = make_init_list(int repeat, const T & scalar) -
Assign from a
farrayThis function will return exactly a copy of mfarr = make_init_list(const farray<T> & m) -
Assign from a list of
farrays Allfarrsmust be of the same typefarray<T>forconcat(const farray<T>(&farrs)[X])
-
-
Assign value to an array and change its shape
Set
farr's shape and value equal to given argumentxfarr.copy_from(const farray<T> & x) -
Create a view from an array A view
varrof arrayfarris anotherfarray<T>, it shares physical storage with originalfarr. iffarris destructed, accessing data ofvarrus undefined behaviourThe only way to create a view is by several constructor, and pass optional argument
isview = truefarray(const size_type(&lower_bound)[D], const size_type(&size)[D], const farray<T> & m, bool isview = false) -
Array traits
| Function | Usage |
|---|---|
.flatsize() |
Get total number of elements in the array |
forconcat(x, y) |
Concat array x and y |
| Fortran | C++ | Explanation |
|---|---|---|
| get | a(1, 2, 3, 4) or a({1, 2, 3, 4}) or a[{1, 2, 3, 4}] or a(1)(2)(3)(4) |
|
| forslice | a[{{1, 3, 1}, {1, 4}, {5}, {}}] or forslice(a, {{1, 3, 1}, {1, 4}, {5}}, {}) |
|
| reshape | forreshape | |
| spread | not implemented yet | |
| transpose | fortranspose | Fortran standard only defined rank 2 situation, for this implementation, the result will be a array with reversed rank |
| maxloc, minloc, maxval, minval | formaxloc, forminloc, formaxval, formaxloc | |
| sum, product | forsum, forproduct | call operator+ and operator* |
| any, all, count | forany, forall, forcount | forall is NOT Fortran95's forall, which is renamed to forforall |
| pack, unpack | not implemented yet | |
| merge | formerge | |
| size, lbound, ubound | forsize, forlbound, forubound | |
| matmul, dot_product | not implemented yet | |
| eoshift, cshift | not implemented yet |
Though Fortran-style array is different from c-style array, only need to consider relationship with flattened 1d array
- Handle a named array: /src/target/gen_vardef.cpp
- Define a array variable: /src/target/gen_vardef.cpp
- Handle array slice: /src/target/gen_callable.cpp