Copyright | (c) Artem Chirkin |
---|---|

License | BSD3 |

Maintainer | chirkin@arch.ethz.ch |

Safe Haskell | None |

Language | Haskell2010 |

Provides a data type Idx that enumerates through multiple dimensions. Lower indices go first, i.e. assumed enumeration is i = i1 + i2*n1 + i3*n1*n2 + ... + ik*n1*n2*...*n(k-1). This is also to encourage column-first matrix enumeration and array layout.

## Synopsis

- newtype Idx n = Idx {}
- type Idxs (xs :: [k]) = TypedList Idx xs
- idxFromWord :: forall d. KnownDim d => Word -> Maybe (Idx d)
- unsafeIdxFromWord :: forall d. KnownDim d => Word -> Idx d
- idxToWord :: Idx d -> Word
- listIdxs :: Idxs xs -> [Word]
- idxsFromWords :: forall ds. Dimensions ds => [Word] -> Maybe (Idx ds)
- module Numeric.Dimensions.Dims

# Data types

This type is used to index a single dimension;
the range of indices is from `1`

to `n`

.

Note, this type has a weird `Enum`

instance:

`>>>`

6`fromEnum (Idx 7)`

The logic behind this is that the `Enum`

class is used to transform
indices to offsets. That is, element of an array at index `k :: Idx n`

is the element taken by an offset `k - 1 :: Int`.

## Instances

Generic1 (Idx :: k -> *) Source # | |

Dimensions ds => Bounded (Idxs ds) Source # | |

KnownDim n => Bounded (Idx n) Source # | |

Dimensions ds => Enum (Idxs ds) Source # | |

KnownDim n => Enum (Idx n) Source # | |

Defined in Numeric.Dimensions.Idxs | |

Eq (Idxs xs) Source # | |

Eq (Idx n) Source # | |

KnownDim n => Integral (Idx n) Source # | |

(Typeable n, Typeable k) => Data (Idx n) Source # | |

Defined in Numeric.Dimensions.Idxs gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Idx n -> c (Idx n) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Idx n) # dataTypeOf :: Idx n -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Idx n)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Idx n)) # gmapT :: (forall b. Data b => b -> b) -> Idx n -> Idx n # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Idx n -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Idx n -> r # gmapQ :: (forall d. Data d => d -> u) -> Idx n -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Idx n -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Idx n -> m (Idx n) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Idx n -> m (Idx n) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Idx n -> m (Idx n) # | |

KnownDim n => Num (Idxs (n ': ([] :: [k]))) Source # | With this instance we can slightly reduce indexing expressions, e.g. x ! (1 :* 2 :* 4) == x ! (1 :* 2 :* 4 :* U) |

Defined in Numeric.Dimensions.Idxs (+) :: Idxs (n ': []) -> Idxs (n ': []) -> Idxs (n ': []) # (-) :: Idxs (n ': []) -> Idxs (n ': []) -> Idxs (n ': []) # (*) :: Idxs (n ': []) -> Idxs (n ': []) -> Idxs (n ': []) # negate :: Idxs (n ': []) -> Idxs (n ': []) # abs :: Idxs (n ': []) -> Idxs (n ': []) # signum :: Idxs (n ': []) -> Idxs (n ': []) # fromInteger :: Integer -> Idxs (n ': []) # | |

KnownDim n => Num (Idx n) Source # | |

Ord (Idxs xs) Source # | Compare indices by their importance in lexicorgaphic order
from the last dimension to the first dimension
(the last dimension is the most significant one) Literally, compare a b = compare (reverse $ listIdxs a) (reverse $ listIdxs b) This is the same sort == sortOn fromEnum |

Ord (Idx n) Source # | |

Read (Idx n) Source # | |

KnownDim n => Real (Idx n) Source # | |

Defined in Numeric.Dimensions.Idxs toRational :: Idx n -> Rational # | |

Show (Idxs xs) Source # | |

Show (Idx n) Source # | |

Generic (Idx n) Source # | |

Storable (Idx n) Source # | |

type Rep1 (Idx :: k -> *) Source # | |

Defined in Numeric.Dimensions.Idxs | |

type Rep (Idx n) Source # | |

Defined in Numeric.Dimensions.Idxs |

type Idxs (xs :: [k]) = TypedList Idx xs Source #

Type-level dimensional indexing with arbitrary Word values inside.
Most of the operations on it require `Dimensions`

constraint,
because the `Idxs`

itself does not store info about dimension bounds.

Note, this type has a special `Enum`

instance:
`fromEnum`

gives an offset of the index in a flat 1D array;
this is in line with a weird `Enum`

instance of `Idx`

type.

idxsFromWords :: forall ds. Dimensions ds => [Word] -> Maybe (Idx ds) Source #

# Re-export dimensions types

module Numeric.Dimensions.Dims