forsyde-atom-0.3.0.0: Shallow-embedded DSL for modeling cyber-physical systems
Copyright(c) George Ungureanu KTH/EECS/ESY 2019-2020
LicenseBSD-style (see the file LICENSE)
Maintainerugeorge@kth.se
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

ForSyDe.Atom.Skel.Vector.Cube

Description

This module exports an alias Cube and a couple of patterns and utilities to work with data cubes constructed as 3D vectors. Since names might overlap, this library is recommended to be imported qualified.

Synopsis

Documentation

type Cube a = Vector (Vector (Vector a)) Source #

Cube is a type synonym for vector of vectors. This means that any function on Vector works also on Cube.

pretty Source #

Arguments

:: Show a 
=> String

separator string

-> Cube a

input cube

-> IO () 

Prints out to the terminal a cube in a readable format, where all elements are right-aligned and separated by a custom separator.

>>> let m = cube 2 2 2 [1,2,3,3,100,4,12,32]
>>> pretty "|" m
--------
1|2
3|3
--------
100| 4
 12|32
--------

isNull :: Cube a -> Bool Source #

Checks if a cube is null. <>, <> and > are all null cubes.

size :: Cube a -> (Int, Int, Int) Source #

Returns the X and Y dimensions of cube and checks if it is well formed.

wellFormed :: Cube a -> Cube a Source #

Checks if a cube is well-formed, meaning that all its rows are of equal length. Returns the same cube in case it is well-formed or throws an exception if it is ill-formed.

cube Source #

Arguments

:: Int

number of columns (X dimension) = x

-> Int

number of rows (Y dimension) = y

-> Int

depth (Z dimension) = z

-> [a]

list of values; length = x * y * z

-> Cube a

Cube of values; size = (x,y,z)

Converts a list into a Cube. See example from pretty.

fromCube Source #

Arguments

:: Cube a

size = (x,y)

-> [a]

length = x * y

Converts a cube back to a list.

unit Source #

Arguments

:: a 
-> Cube a

size = (1,1)

Creates a unit (i.e. singleton) cube, which is a cube with only one element.

fanout :: a -> Cube a Source #

Creates an infinite cube which repeats one element

indexes :: Cube (Int, Int, Int) Source #

Returns an infinite cube with (X,Y) index pairs. You need to zip it against another (finite) cube or to extract a finite subset in order to be useful (see example below).

>>> pretty " " $ take 3 4 2 indexes
(0,0) (1,0) (2,0)
(0,1) (1,1) (2,1)
(0,2) (1,2) (2,2)
(0,3) (1,3) (2,3)

transpose Source #

Arguments

:: Cube a

dimensions (Z,Y,X)

-> Cube a

dimensions (Y,X,Z)

Transposes a cube from (Z,Y,X) to (Y,X,Z).

transpose' Source #

Arguments

:: Cube a

dimensions (Y,X,Z)

-> Cube a

dimensions (Z,Y,X)

Transposes a cube from (Z,Y,X) to (Z,Y,X).

farm11 Source #

Arguments

:: (a -> b) 
-> Cube a

size = (xa,ya)

-> Cube b

size = (xa,ya)

Maps a function on every value of a cube.

OBS: this function does not check if the output cube is well-formed.

farm21 Source #

Arguments

:: (a -> b -> c) 
-> Cube a

size = (xa,ya)

-> Cube b

size = (xb,yb)

-> Cube c

size = (minimum [xa,xb], minimum [ya,yb])

Applies a binary function pair-wise on each element in two matrices.

OBS: this function does not check if the output cube is well-formed.

farm31 Source #

Arguments

:: (a -> b -> c -> d) 
-> Cube a

size = (xa,ya)

-> Cube b

size = (xb,yb)

-> Cube c

size = (xc,yc)

-> Cube d

size = (minimum [xa,xb,xc], minimum [ya,yb,yc])

Applies a function 3-tuple-wise on each element in three matrices.

OBS: this function does not check if the output cube is well-formed.

reduce :: (a -> a -> a) -> Cube a -> a Source #

Reduces all the elements of a cube to one element based on a binary function.

>>> let m = cube 3 3 [1,2,3,11,12,13,21,22,23]
>>> reduce (+) m
108

get Source #

Arguments

:: Int

X index starting from zero

-> Int

Y index starting from zero

-> Int

Z index starting from zero

-> Cube a 
-> Maybe a 

Returns the element of a matrix at a certain position.

>>> let m = matrix 3 3 [1,2,3,11,12,13,21,22,23]
>>> at 2 1 m
13

take Source #

Arguments

:: Int

X index starting from zero

-> Int

Y index starting from zero

-> Int
index starting from zero
-> Cube a 
-> Cube a 

Returns the upper-left part of a matrix until a specific position.

>>> let m = matrix 4 4 [1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34]
>>> pretty " " $ take 2 2 m
 1  2
11 12

drop Source #

Arguments

:: Int

X index starting from zero

-> Int

Y index starting from zero

-> Int

Z index starting from zero

-> Cube a 
-> Cube a 

Returns the upper-left part of a matrix until a specific position.

>>> let m = matrix 4 4 [1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34]
>>> pretty " " $ drop 2 2 m
23 24
33 34