|
|
There is one generic array container object while the underlying data may be one of various basic types:
real)complex)double precision*)double complex*)float) unless otherwise specified. Some examples: type(array) res res = randu(3, 3) ! Uniformly distributed random matrix res = randn(3, 3) ! Normally distributed random matrix res = constant(1,5, 5, f32) ! Single precision matrix of all ones res = constant(0,4, 4, f64)! Double precision matrix of all zeros res = identity(2, 2) ! Identity Matrix
type(array) arr real, dimension(2, 2) :: a a(1,1) = 1 a(2,2) = 1 ! a is now identity matrix of width 2 arr = a ! Data is now on device
type(array) arr real, dimension(:,:), allocatable :: b arr = randu(5,5) ! Generate matrix on device b = log(arr) ! Return log(arr) to host
Matrix operations allow you to process your data and extract the information needed. The can be broadly classified into the following
Statistical operations
type(array) A, sm, mn, mx ! Generate random system A = randu(5,5) sm = sum(A) ! Get sum of elements value mn = min(A) ! Get minimum of elements value mx = max(A) ! Get maximum of elements value
Manipulation operations
type(array) A, T, L, U A = randu(4, 5) ! Random matrix T = transpose(A) ! Matrix transpose L = lower(A) ! Extract lower matrix U = upper(A) ! Extract upper matrix
type(arr) A, L, U, p A = randu(5,5) call lu(L,U,p,A) ! Results are stored in L, U, p call lu(A) ! L is the same as lower triangle of A, U the upper triangle of A
Some more code snippets
type(array) A, B, X0, X, Y type(array) S, V, U A = randu(5,5) ! Generavte random matrix X0 = randu(5,1) ! Generate random matrix call singular(S, U, V, A) ! singular value decomposition B = matmul(A, X0) ! Generate a random system X = solve(A, B) ! Solve the system Y = matmul(inverse(A), B) ! Solve using inverse print(max(X0 - X)) ! Display max error print(max(X0 - Y)) ! Display max error
Indexing up to four dimensions is supported with the following limitations
The following functions are provided to help with array indexing
Code snippet to showcase indexing support
3D indexing A1 = randu(3,3,2) A2 = constant(1,3,3,2) I1 = (/ 1, 3 /) I2 = (/ 2, 3 /) tmp = get(A1, idx(I1), seq(1,3,2), 1) ! Get rows 1 and 3 for columns 1 and 3, tile 1 call set(A2, tmp, idx(I2), seq(1,2), 2) ! Set rows 2 and 3 for columns 1 and 2, tile 2 with tmp call print(A1, "A1") call print(tmp, "tmp") call print(A2, "A2")