Copyright | (c) George Ungureanu KTH/EECS/ESY 2019-2020 |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | ugeorge@kth.se |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
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
- type Cube a = Vector (Vector (Vector a))
- pretty :: Show a => String -> Cube a -> IO ()
- isNull :: Cube a -> Bool
- size :: Cube a -> (Int, Int, Int)
- wellFormed :: Cube a -> Cube a
- cube :: Int -> Int -> Int -> [a] -> Cube a
- fromCube :: Cube a -> [a]
- unit :: a -> Cube a
- fanout :: a -> Cube a
- indexes :: Cube (Int, Int, Int)
- transpose :: Cube a -> Cube a
- transpose' :: Cube a -> Cube a
- farm11 :: (a -> b) -> Cube a -> Cube b
- farm21 :: (a -> b -> c) -> Cube a -> Cube b -> Cube c
- farm31 :: (a -> b -> c -> d) -> Cube a -> Cube b -> Cube c -> Cube d
- reduce :: (a -> a -> a) -> Cube a -> a
- get :: Int -> Int -> Int -> Cube a -> Maybe a
- take :: Int -> Int -> Int -> Cube a -> Cube a
- drop :: Int -> Int -> Int -> Cube a -> Cube a
Documentation
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 --------
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.
:: a | |
-> Cube a | size = |
Creates a unit (i.e. singleton) cube, which is a cube with only 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)
Transposes a cube from (Z,Y,X)
to (Y,X,Z)
.
Transposes a cube from (Z,Y,X)
to (Z,Y,X)
.
Maps a function on every value of a cube.
OBS: this function does not check if the output cube is well-formed.
:: (a -> b -> c) | |
-> Cube a | size = |
-> Cube b | size = |
-> Cube c | size = |
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.
:: (a -> b -> c -> d) | |
-> Cube a | size = |
-> Cube b | size = |
-> Cube c | size = |
-> Cube d | size = |
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
:: 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
:: 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