Copyright | (c) Artur M. Brodzki 2018 |
---|---|
License | BSD3 |
Maintainer | artur@brodzki.org |
Stability | experimental |
Portability | Windows/POSIX |
Safe Haskell | None |
Language | Haskell2010 |
Multilinear.Generic.MultiCore
Description
Synopsis
- data Tensor a where
- Scalar :: {..} -> Tensor a
- SimpleFinite :: {..} -> Tensor a
- FiniteTensor :: {..} -> Tensor a
- (!) :: Unbox a => Tensor a -> Int -> Tensor a
- isScalar :: Unbox a => Tensor a -> Bool
- isSimple :: Unbox a => Tensor a -> Bool
- isFiniteTensor :: Unbox a => Tensor a -> Bool
- tensorIndex :: Unbox a => Tensor a -> TIndex
- _standardize :: Unbox a => Tensor a -> Tensor a
- _mergeScalars :: Unbox a => Tensor a -> Tensor a
- _map :: (Unbox a, Unbox b, NFData b) => (a -> b) -> Tensor a -> Tensor b
- _contractedIndices :: Tensor Double -> Tensor Double -> Set String
- _elemByElem :: (Num a, Unbox a, NFData a) => Tensor a -> Tensor a -> (a -> a -> a) -> (Tensor a -> Tensor a -> Tensor a) -> Tensor a
- zipT :: (Num a, NFData a, Unbox a) => (a -> a -> a) -> Tensor a -> Tensor a -> Tensor a
- (.+) :: (Unbox a, Num a, NFData a) => Tensor a -> a -> Tensor a
- (.-) :: (Unbox a, Num a, NFData a) => Tensor a -> a -> Tensor a
- (.*) :: (Unbox a, Num a, NFData a) => Tensor a -> a -> Tensor a
- (+.) :: (Unbox a, Num a, NFData a) => a -> Tensor a -> Tensor a
- (-.) :: (Unbox a, Num a, NFData a) => a -> Tensor a -> Tensor a
- (*.) :: (Unbox a, Num a, NFData a) => a -> Tensor a -> Tensor a
- map :: (Unbox a, Unbox b, NFData b) => (a -> b) -> Tensor a -> Tensor b
- filter :: Unbox a => (String -> Int -> Bool) -> Tensor a -> Tensor a
- filterIndex :: Unbox a => String -> (Int -> Bool) -> Tensor a -> Tensor a
- zipWith :: (Unbox a, Unbox b, Unbox c, NFData c) => (a -> b -> c) -> Tensor a -> Tensor b -> Tensor c
Generic tensor datatype and its instances
Tensor defined recursively as scalar or list of other tensors
c
is type of a container, i
is type of index size and a
is type of tensor elements
Constructors
Scalar | Scalar |
SimpleFinite | Simple, one-dimensional finite tensor |
Fields
| |
FiniteTensor | Finite array of other tensors |
Fields
|
Instances
Auxiliary functions
Recursive indexing on list tensor. If index is greater than index size, performs modulo indexing
t ! i = t[i]
_standardize :: Unbox a => Tensor a -> Tensor a Source #
Move contravariant indices to lower recursion level
_mergeScalars :: Unbox a => Tensor a -> Tensor a Source #
Merge FiniteTensor of Scalars to SimpleFinite tensor for performance improvement
_map :: (Unbox a, Unbox b, NFData b) => (a -> b) -> Tensor a -> Tensor b Source #
Generic map function, which does not require a,b types to be Num
Arguments
:: Tensor Double | first tensor to contract |
-> Tensor Double | second tensor to contract |
-> Set String |
Contracted indices have to be consumed in result tensor.
Arguments
:: (Num a, Unbox a, NFData a) | |
=> Tensor a | First argument of operator |
-> Tensor a | Second argument of operator |
-> (a -> a -> a) | Operator on tensor elements if indices are different |
-> (Tensor a -> Tensor a -> Tensor a) | Tensor operator called if indices are the same |
-> Tensor a | Result tensor |
Apply a tensor operator elem by elem and merge scalars to simple tensor at the and
Arguments
:: (Num a, NFData a, Unbox a) | |
=> (a -> a -> a) | The zipping combinator |
-> Tensor a | First tensor to zip |
-> Tensor a | Second tensor to zip |
-> Tensor a | Result tensor Two simple tensors case |
Zipping two tensors with a combinator, assuming they have the same indices.
Additional functions
map :: (Unbox a, Unbox b, NFData b) => (a -> b) -> Tensor a -> Tensor b Source #
Simple mapping
map f t
returns tensor t2
in which t2[i1,i2,...] = f t[i1,i2,...]
Filtering tensor. Filtering multi-dimensional arrray may be dangerous, as we always assume, that on each recursion level, all tensors have the same size (length). To disable invalid filters, filtering is done over indices, not tensor elements. Filter function takes and index name and index value and if it returns True, this index value remains in result tensor. This allows to remove whole columns or rows of eg. a matrix: filter (i n -> i = "a" || i > 10) filters all rows of "a" index (because if i = "a", filter returns True) and for "a" index filter elements with index value <= 10 But this disallow to remove particular matrix element. If for some index all elements are removed, the index itself is removed from tensor.