Science Score: 67.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 3 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (7.4%) to scientific vocabulary
Repository
Multidimensional Array Containers
Basic Info
- Host: GitHub
- Owner: irukoa
- License: gpl-3.0
- Language: Fortran
- Default Branch: main
- Size: 85.9 KB
Statistics
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 4
Metadata Files
README.md
MAC
Multidimensional Array Containers.
This is a tiny modern Fortran library to create and manipulate arrays of any rank. The library is meant to serve as a building block for codes that expand on "rank-agnostic" programming. See, e.g., this thread.
API
The following derived types are defined:
fortran
type, public :: container_specifier
type, extends(container_specifier), public :: container
The former is an array handle, which stores the rank, shape, bounds and the layout of the multidimensional array. The latter is an extension for the handle, which provides the storage for the actual array.
type(container_specifier) :: a
Procedure | Description | Parameters
--- | --- | ---
Constructor subroutine.
Usage:
call a%specify(dimension_specifier [, lower_bounds, layout]) | Initializes the array handle. | integer, intent(in) :: dimension_specifier(:) : 1D array containing the shape of the multidimensional array. integer, intent(in) :: lower_bounds(size(dimension_specifier)) (optional) : 1D array containing the lower bounds of the multidimensional array. Default is an array of 1-s. character(len=*)/integer, intent(in) :: layout (optional) : specifies which dimension should contain contiguous indexes upon traversal of the array. The options are "F"/0: leftmost dimension; and "C"/1: rightmost dimension. Default is "F". See also.
class(container_specifier), intent(out) :: a: initialized array handle.
Size handle.
Usage:
sz = a%size()| Returns the size of the represented array.| class(container_specifier), intent(in) :: a: initialized array handle.
integer, intent(out) :: sz: size of the represented array.
Rank handle.
Usage:
rk = a%rank()| Returns the rank of the represented array.| class(container_specifier), intent(in) :: a: initialized array handle.
integer, intent(out) :: rk: rank of the represented array.
Shape handle.
Usage:
spc = a%shape()| Returns the shape of the represented array.| class(container_specifier), intent(in) :: a: initialized array handle.
integer, intent(out) :: spc(size(dimension_specifier)): shape of the represented array.
Lower bounds handle.
Usage:
lb = a%lbounds()| Returns the lower bounds of the represented array.| class(container_specifier), intent(in) :: a: initialized array handle.
integer, intent(out) :: lb(size(dimension_specifier)): lower bounds of the represented array.
Upper bounds handle.
Usage:
ub = a%ubounds()| Returns the upper bounds of the represented array.| class(container_specifier), intent(in) :: a: initialized array handle.
integer, intent(out) :: ub(size(dimension_specifier)): upper bounds of the represented array.
Layout handle.
Usage:
lyt = a%layout()| Returns the layout of the represented array.| class(container_specifier), intent(in) :: a: initialized array handle.
integer, intent(out) :: lyt: layout of the represented array. lyt = 0 means "F" layout and lyt = 1, "C" layout.
Specifier initialization checker.
Usage:
init = a%spec_init()| Defines whether the container specifier is initialized.| class(container_specifier), intent(in) :: a: array handle.
logical, intent(out) :: init: initialization status of the specifier.
Indexing functions.
Usage:
[arr], {mem} = a%ind([mem], {arr}) | Shifts between memory layout representation and array layout representation. | class(container_specifier), intent(in) :: a: initialized array handle.
Given mem:
integer, intent(in) :: mem: integer referencing a memory layout address. Must be in the range mem$\in[1,$ a%size()$]$.
integer, intent(out) :: arr(:): 1D integer array referencing the corresponding array layout address. The number of components is equal to the rank of the represented array. Each component arr(i) is in the range arr(i)$\in[$ lb(i) $,$ lb(i) + spc(i) - 1$]$. Where lb(i) and spc(i) are the lower bounds and number of elements for dimension i of the represented array, respectively.
Given arr(:):
integer, intent(in) :: arr(:): 1D integer array referencing an array layout address. Each component arr(i) must be the range arr(i)$\in[$ lb(i) $,$ lb(i) + spc(i) - 1$]$.
integer, intent(out) :: mem: integer array referencing the corresponding memory layout address. Will be in the range mem$\in[1,$ a%size()$]$.
Partial permutation utility.
Usage:
dictionary = a%partial_permutation(dims) | Defines a dictionary containing the partial permutations of a set of dimensions { spc(i) } given by their set of labels dims = { $i$ }. The dictionary is a 2-dimensional array containing the particular partial permutation label and the corresponding array layout reference. The array dimensions spc(j) that have not been permuted are fixed to lbs(j).| class(container_specifier), intent(in) :: a: initialized array handle.
integer, intent(in) :: dims(:): 1D array with size(dims) $\in [1,$ size(spc) $]$ containing the labels of the dimensions to permute on.
integer, allocatable, intent(out) :: dictionary(:, :): 2D array with the first index labelling the permutation label and the second the array layout component value of the permutation. Thus, dictionary(i, :) is an array layout reference of a which references the $i$-th partial permutation of dimensions dims. In the case of a having "F" layout, the permutation labels contiguous in the dictionary are those which permute the dimension label given in dims(1) first. In the case of "C" layout, the dimension label given in dims(size(dims)) is permuted first.
type(container) :: b
Procedure() | Description | Parameters
--- | --- | ---
Constructor subroutine.
Usage:
call b%construct(container_type, dimension_specifier [, lower_bounds, layout]) | Initializes the array handle and array. | `character(len=)/integer, intent(in) :: containertype: data type to allocate storage for. Options arelogical/1,integer/2,real/3,complex/4,realdp/5,complexdp/6where the last two are double precision kinds. <br />integer, intent(in) :: dimensionspecifier(:): 1D array containing the shape of the multidimensional array. <br />integer, intent(in) :: lowerbounds(:)(optional) : 1D array containing the shape of the multidimensional array. Default is an array of 1-s. <br />character(len = *), intent(in) :: layout(optional) : specifies which dimension should contain contiguous indexes upon traversal of the array. The options are"F": leftmost dimension; and"C": rightmost dimension. Default is"F". <br />class(container), intent(out) :: b: initialized array.
Layout handle. <br /> Usage: <br />lyt = a%lbounds()| Returns the layout of the represented array.|class(containerspecifier), intent(in) :: a: initialized array handle. <br />integer, intent(out) :: lyt: layout of the represented array.lyt = 0means"F"layout andlyt = 1,"C"layout.
Container type handle. <br /> Usage: <br />typ = b%conttype()| Retrieves container type and kind.|class(container), intent(in) :: b: initialized array. <br />integer, intent(out) :: typ: container type, possible values are $[1, 6]$ corresponding tological,integer,real,complex,realdpandcomplexdp, respectively.
Setter subroutine. <br /> Usage: <br />call b%set(value [, at = [mem], {arr}]). | Sets the value of the represented array (component). |class(container), intent(in) :: b: initialized array. <br />$kind$, intent(in) :: value: variable to set the data from. The type and kind of this value must be compatible with the container's type and kind. <br />integer, intent(in) :: mem<br /> or <br />integer, intent(in) :: arr(:)<br /> The memory or array layout index where the value is to be set. The restrictions onmemandarr(:)are the same as for the indexing function. Ifatis not present it sets the value of all components of the represented array.
Getter subroutine. <br /> Usage: <br />call b%get(value, at = [mem], {arr}). | Retrieves the value of the represented array component. |class(container), intent(in) :: b: initialized array. <br />$kind$, intent(out) :: value: variable to retrieve the data to. The type and kind of this value must be compatible with the container's type and kind. <br />integer, intent(in) :: mem<br /> or <br />integer, intent(in) :: arr(:)<br /> The memory or array layout index of the value is to be retrieved. The restrictions onmemandarr(:)are the same as for the indexing function.
Array section/slice utility. <br /> Usage: <br />c = b%section(dims, at).| Retrieves an array section from a container and stores it in another container. |class(container), intent(in) :: b: initialized array. <br />integer, intent(in) :: dims(n): specifies which dimension labels are to be sliced. <br />integer, intent(in) :: at(b%rank()-n): the array layout index corresponding to the dimensions not present indimswhere to evaluateb. The index is given in sequential order, such that each component belongs to the corresponding dimension ofbnot present indims. <br />type(container), intent(out) :: c: an initialized container with the same characteristics asbexcept thatc%shape()isdims.
Reduction utility. <br /> Usage: <br />c = b%reduce(op [, dim]). | Implements a user defined reduction operation along one or all dimensions of the container. |class(container), intent(in) :: b: initialized array. <br />procedure(intfc), intent(in) :: op: user defined array operation with interface [intfc](#intfc). <br />integer, intent(in) :: dim(optional): specifies which dimension label is to be reduced.type(container)/type(b%conttype()), intent(out) :: c: ifdimis present, is atype(container)object withc%rank() = b%rank() - 1andc%shape()similar tob%shape()with dimensiondimdropped and otherwise the same specifiers asb. Ifdimis absent, is atype(b%cont_type())` scalar object.
Interface intfc
User defined array operations must comply with the interface
fortran
interface
function op(array)
type(b%cont_type()), intent(in) :: array(:)
type(b%cont_type()) :: op
end function op
end interface
(*)Additionally to the procedures that apply to type(container_specifier) :: a.
Component | Description
--- | ---
Logical storage.
b%l_storage(:) | Memory layout array representing b. Will only be allocated if the container type has been defined of logical type.
Integer storage.
b%i_storage(:) | Memory layout array representing b. Will only be allocated if the container type has been defined of integer type.
Real storage.
b%r_storage(:) | Memory layout array representing b. Will only be allocated if the container type has been defined of real type.
Complex storage.
b%c_storage(:) | Memory layout array representing b. Will only be allocated if the container type has been defined of complex type.
Real double precision storage.
b%rdp_storage(:) | Memory layout array representing b. Will only be allocated if the container type has been defined of real_dp type.
Complex double precision storage.
b%cdp_storage(:) | Memory layout array representing b. Will only be allocated if the container type has been defined of complex_dp type.
Limitations
The only serious limitation of this approach to rank-agnostic programming is integer overflow. The default integer type is 4-byte, which means that the largest array possible to be represented can have only up to $2^{31} - 1 = 2147483647$ components (or $\approx$ 8 GB for a real array). The library will set a runtime error if this number of components is exceeded upon initialization of the array or array handle by the constructor routines.
Build
An automated build is available for Fortran Package Manager users. This is the recommended way to build and use MAC in your projects. You can add MAC to your project dependencies by including
[dependencies]
MAC = { git="https://github.com/irukoa/MAC.git" }
in the fpm.toml file.
Owner
- Name: Álvaro R. Puente-Uriona
- Login: irukoa
- Kind: user
- Location: Donostia
- Company: CFM/MPC-UPV/EHU
- Website: https://cfm.ehu.es/team/56452/
- Repositories: 2
- Profile: https://github.com/irukoa
PhD Student in Solid State Physics, check my CV at https://irukoa.github.io/
Citation (CITATION.cff)
cff-version: 1.2.0
title: MAC
message: Multidimensional Array Containers
type: software
authors:
- given-names: Álvaro
family-names: R. Puente-Uriona
email: alvaro.ruiz@ehu.eus
affiliation: UPV/EHU
orcid: 'https://orcid.org/0000-0003-1915-8804'
identifiers:
- type: doi
value: 10.5281/zenodo.10615838
description: Zenodo
repository-code: 'https://github.com/irukoa/MAC'
url: 'https://github.com/irukoa/MAC'
abstract: >-
Multidimensional Array Containers. A Fortran library with
utilities to create and manipulate arrays of generic rank.
keywords:
- Fortran
- Generic programming
- Data structures
license: GPL-3.0
GitHub Events
Total
Last Year
Dependencies
- actions/checkout v2 composite
- fortran-lang/setup-fpm v5 composite