Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- decodeArray :: forall ix a m. MonadThrow m => (Index ix, AxesIndex ix, Prim a, GetPix a) => DataArray -> m (Array D ix a)
- encodeArray :: forall r ix a. (Source r a, Stream r Ix1 a, Size r, PutArray ix, Index ix, AxesIndex ix, PutPix a, Prim a) => Array r ix a -> DataArray
- decodeArrayData :: forall ix a m. (AxesIndex ix, Prim a, GetPix a, Index ix, MonadThrow m) => BitPix -> Axes Column -> ByteString -> m (Array D ix a)
- encodeArrayData :: (Source r a, Stream r Ix1 a, PutArray ix, Index ix, PutPix a, Prim a) => Array r ix a -> ByteString
- totalPix :: Axes Column -> Int
- class AxesIndex ix where
- getAxesVector :: Get a -> Axes Column -> Get (Vector DS a)
- runGetThrow :: forall a m. MonadThrow m => Get a -> ByteString -> m a
- sizeAxes :: (AxesIndex ix, Index ix) => Sz ix -> Axes Column
- class GetPix a where
- class PutPix a where
- bitPixFormat :: Proxy a -> BitPix
- putPix :: a -> Put
- class PutArray ix where
- parseVector :: forall a. GetPix a => Comp -> BitPix -> ByteString -> Vector D a
- fromVector :: forall ix a m. (AxesIndex ix, Index ix, Prim a, MonadThrow m) => Axes Column -> Vector D a -> m (Array D ix a)
- data family Array r ix e
- type Ix1 = Int
- data Ix2
- type Ix3 = IxN 3
- type Ix4 = IxN 4
- type Ix5 = IxN 5
- size :: Size r => Array r ix e -> Sz ix
- (!>) :: forall r ix e. (HasCallStack, Index ix, Index (Lower ix), Source r e) => Array r ix e -> Int -> Array r (Lower ix) e
- (!?>) :: forall r ix e m. (MonadThrow m, Index ix, Index (Lower ix), Source r e) => Array r ix e -> Int -> m (Array r (Lower ix) e)
- (<!) :: forall r ix e. (HasCallStack, Index ix, Source r e) => Array r ix e -> Int -> Array D (Lower ix) e
- (<!?) :: forall r ix e m. (MonadThrow m, Index ix, Source r e) => Array r ix e -> Int -> m (Array D (Lower ix) e)
- (<!>) :: forall r ix e. (HasCallStack, Index ix, Index (Lower ix), Source r e) => Array r ix e -> (Dim, Int) -> Array D (Lower ix) e
- newtype Dim = Dim {}
Encoding Images
decodeArray :: forall ix a m. MonadThrow m => (Index ix, AxesIndex ix, Prim a, GetPix a) => DataArray -> m (Array D ix a) Source #
Decode a DataArray
of arbitrary dimensions ix
and type a
. Inspect the DataArray's (.bitpix) and (.axes) if these are unknown.
>>>
decodeArray @Ix2 @Float hdu.dataArray
Array D Seq (Sz (2 :. 3)) [ [ 1.0, 2.0, 3.0 ] , [ 4.0, 5.0, 6.0 ] ]
This creates a delayed (D) array, which will postpone evaluation of cells until needed
encodeArray :: forall r ix a. (Source r a, Stream r Ix1 a, Size r, PutArray ix, Index ix, AxesIndex ix, PutPix a, Prim a) => Array r ix a -> DataArray Source #
Encoding as ByteStrings
decodeArrayData :: forall ix a m. (AxesIndex ix, Prim a, GetPix a, Index ix, MonadThrow m) => BitPix -> Axes Column -> ByteString -> m (Array D ix a) Source #
Decode data into an Array of arbitrary dimensions ix
specifying BitPixFormat
and Axes
>>>
decodeArray @Ix2 @Float BPFloat [3, 2] input
Array P Seq (Sz (2 :. 3)) [ [ 1.0, 2.0, 3.0 ] , [ 4.0, 5.0, 6.0 ] ]
encodeArrayData :: (Source r a, Stream r Ix1 a, PutArray ix, Index ix, PutPix a, Prim a) => Array r ix a -> ByteString Source #
Encode an Array as a Lazy ByteString based on the type of the element a
>>>
myArray = decodeArray @Ix2 @Float BPFloat [3, 2] input
>>>
output = encodeArray myArray
Handling Axes
getAxesVector :: Get a -> Axes Column -> Get (Vector DS a) Source #
Decode Axes as a delayed 1d vector
runGetThrow :: forall a m. MonadThrow m => Get a -> ByteString -> m a Source #
Binary Encoding
How to encode an element type. Note that there is no instance for Int
, since the size is system dependent. Use Int64 or Int32 instead
parseVector :: forall a. GetPix a => Comp -> BitPix -> ByteString -> Vector D a Source #
fromVector :: forall ix a m. (AxesIndex ix, Index ix, Prim a, MonadThrow m) => Axes Column -> Vector D a -> m (Array D ix a) Source #
Exports from Data.Massiv.Array
The array family. Representations r
describe how data is arranged or computed. All
arrays have a common property that each index ix
always maps to the same unique
element e
, even if that element does not yet exist in memory and the array has to be
computed in order to get the value of that element. Data is always arranged in a nested
row-major fashion. Rank of an array is specified by
.Dimensions
ix
Since: massiv-0.1.0
Instances
Index ix => Foldable (Array DI ix) | |
Defined in Data.Massiv.Array.Delayed.Interleaved fold :: Monoid m => Array DI ix m -> m # foldMap :: Monoid m => (a -> m) -> Array DI ix a -> m # foldMap' :: Monoid m => (a -> m) -> Array DI ix a -> m # foldr :: (a -> b -> b) -> b -> Array DI ix a -> b # foldr' :: (a -> b -> b) -> b -> Array DI ix a -> b # foldl :: (b -> a -> b) -> b -> Array DI ix a -> b # foldl' :: (b -> a -> b) -> b -> Array DI ix a -> b # foldr1 :: (a -> a -> a) -> Array DI ix a -> a # foldl1 :: (a -> a -> a) -> Array DI ix a -> a # toList :: Array DI ix a -> [a] # null :: Array DI ix a -> Bool # length :: Array DI ix a -> Int # elem :: Eq a => a -> Array DI ix a -> Bool # maximum :: Ord a => Array DI ix a -> a # minimum :: Ord a => Array DI ix a -> a # | |
Index ix => Foldable (Array D ix) | Row-major sequential folding over a Delayed array. |
Defined in Data.Massiv.Array.Delayed.Pull fold :: Monoid m => Array D ix m -> m # foldMap :: Monoid m => (a -> m) -> Array D ix a -> m # foldMap' :: Monoid m => (a -> m) -> Array D ix a -> m # foldr :: (a -> b -> b) -> b -> Array D ix a -> b # foldr' :: (a -> b -> b) -> b -> Array D ix a -> b # foldl :: (b -> a -> b) -> b -> Array D ix a -> b # foldl' :: (b -> a -> b) -> b -> Array D ix a -> b # foldr1 :: (a -> a -> a) -> Array D ix a -> a # foldl1 :: (a -> a -> a) -> Array D ix a -> a # toList :: Array D ix a -> [a] # null :: Array D ix a -> Bool # length :: Array D ix a -> Int # elem :: Eq a => a -> Array D ix a -> Bool # maximum :: Ord a => Array D ix a -> a # minimum :: Ord a => Array D ix a -> a # | |
Foldable (Array DS Ix1) | |
Defined in Data.Massiv.Array.Delayed.Stream fold :: Monoid m => Array DS Ix1 m -> m # foldMap :: Monoid m => (a -> m) -> Array DS Ix1 a -> m # foldMap' :: Monoid m => (a -> m) -> Array DS Ix1 a -> m # foldr :: (a -> b -> b) -> b -> Array DS Ix1 a -> b # foldr' :: (a -> b -> b) -> b -> Array DS Ix1 a -> b # foldl :: (b -> a -> b) -> b -> Array DS Ix1 a -> b # foldl' :: (b -> a -> b) -> b -> Array DS Ix1 a -> b # foldr1 :: (a -> a -> a) -> Array DS Ix1 a -> a # foldl1 :: (a -> a -> a) -> Array DS Ix1 a -> a # toList :: Array DS Ix1 a -> [a] # null :: Array DS Ix1 a -> Bool # length :: Array DS Ix1 a -> Int # elem :: Eq a => a -> Array DS Ix1 a -> Bool # maximum :: Ord a => Array DS Ix1 a -> a # minimum :: Ord a => Array DS Ix1 a -> a # | |
Index ix => Foldable (Array B ix) | Row-major sequential folding over a Boxed array. |
Defined in Data.Massiv.Array.Manifest.Boxed fold :: Monoid m => Array B ix m -> m # foldMap :: Monoid m => (a -> m) -> Array B ix a -> m # foldMap' :: Monoid m => (a -> m) -> Array B ix a -> m # foldr :: (a -> b -> b) -> b -> Array B ix a -> b # foldr' :: (a -> b -> b) -> b -> Array B ix a -> b # foldl :: (b -> a -> b) -> b -> Array B ix a -> b # foldl' :: (b -> a -> b) -> b -> Array B ix a -> b # foldr1 :: (a -> a -> a) -> Array B ix a -> a # foldl1 :: (a -> a -> a) -> Array B ix a -> a # toList :: Array B ix a -> [a] # null :: Array B ix a -> Bool # length :: Array B ix a -> Int # elem :: Eq a => a -> Array B ix a -> Bool # maximum :: Ord a => Array B ix a -> a # minimum :: Ord a => Array B ix a -> a # | |
Index ix => Foldable (Array BL ix) | Row-major sequential folding over a Boxed array. |
Defined in Data.Massiv.Array.Manifest.Boxed fold :: Monoid m => Array BL ix m -> m # foldMap :: Monoid m => (a -> m) -> Array BL ix a -> m # foldMap' :: Monoid m => (a -> m) -> Array BL ix a -> m # foldr :: (a -> b -> b) -> b -> Array BL ix a -> b # foldr' :: (a -> b -> b) -> b -> Array BL ix a -> b # foldl :: (b -> a -> b) -> b -> Array BL ix a -> b # foldl' :: (b -> a -> b) -> b -> Array BL ix a -> b # foldr1 :: (a -> a -> a) -> Array BL ix a -> a # foldl1 :: (a -> a -> a) -> Array BL ix a -> a # toList :: Array BL ix a -> [a] # null :: Array BL ix a -> Bool # length :: Array BL ix a -> Int # elem :: Eq a => a -> Array BL ix a -> Bool # maximum :: Ord a => Array BL ix a -> a # minimum :: Ord a => Array BL ix a -> a # | |
Index ix => Traversable (Array B ix) | |
Defined in Data.Massiv.Array.Manifest.Boxed | |
Index ix => Traversable (Array BL ix) | |
Defined in Data.Massiv.Array.Manifest.Boxed | |
Index ix => Applicative (Array DI ix) | |
Defined in Data.Massiv.Array.Delayed.Interleaved | |
Index ix => Applicative (Array D ix) | |
Defined in Data.Massiv.Array.Delayed.Pull | |
Applicative (Array DS Ix1) | |
Defined in Data.Massiv.Array.Delayed.Stream | |
Functor (Array DI ix) | |
Functor (Array D ix) | |
Index ix => Functor (Array DL ix) | |
Functor (Array DS Ix1) | |
Functor (Array DW ix) | |
Index ix => Functor (Array B ix) | |
Index ix => Functor (Array BL ix) | |
Monad (Array DS Ix1) | |
Monoid (Array DL Ix1 e) | |
Monoid (Array DS Ix1 e) | |
Semigroup (Array DL Ix1 e) | |
Semigroup (Array DS Ix1 e) | |
IsList (Array DS Ix1 e) | |
(IsList (Array L ix e), Ragged L ix e) => IsList (Array B ix e) | |
(IsList (Array L ix e), Ragged L ix e) => IsList (Array BL ix e) | |
(NFData e, IsList (Array L ix e), Ragged L ix e) => IsList (Array BN ix e) | |
(Prim e, IsList (Array L ix e), Ragged L ix e) => IsList (Array P ix e) | |
(Storable e, IsList (Array L ix e), Ragged L ix e) => IsList (Array S ix e) | |
(Unbox e, IsList (Array L ix e), Ragged L ix e) => IsList (Array U ix e) | |
Coercible (Elt ix e) (ListItem ix e) => IsList (Array L ix e) | |
(Ragged L ix e, Show e) => Show (Array DI ix e) | |
(Ragged L ix e, Show e) => Show (Array D ix e) | |
(Ragged L ix e, Load DW ix e, Show e) => Show (Array DW ix e) | |
(Ragged L ix e, Show e) => Show (Array B ix e) | |
(Ragged L ix e, Show e) => Show (Array BL ix e) | |
(Ragged L ix e, Show e, NFData e) => Show (Array BN ix e) | |
(Ragged L ix e, Show e, Prim e) => Show (Array P ix e) | |
(Ragged L ix e, Show e, Storable e) => Show (Array S ix e) | |
(Ragged L ix e, Show e, Unbox e) => Show (Array U ix e) | |
(Ragged L ix e, Show e) => Show (Array L ix e) | |
(Index ix, NFData e) => NFData (Array B ix e) | |
Defined in Data.Massiv.Array.Manifest.Boxed | |
(Index ix, NFData e) => NFData (Array BL ix e) | |
Defined in Data.Massiv.Array.Manifest.Boxed | |
NFData (Array BN ix e) | O(1) - |
Defined in Data.Massiv.Array.Manifest.Boxed | |
Index ix => NFData (Array P ix e) | |
Defined in Data.Massiv.Array.Manifest.Primitive | |
NFData ix => NFData (Array S ix e) | |
Defined in Data.Massiv.Array.Manifest.Storable | |
NFData ix => NFData (Array U ix e) | |
Defined in Data.Massiv.Array.Manifest.Unboxed | |
(Index ix, Eq e) => Eq (Array DI ix e) | |
(Eq e, Index ix) => Eq (Array D ix e) | |
(Index ix, Eq e) => Eq (Array B ix e) | |
(Index ix, Eq e) => Eq (Array BL ix e) | |
(Index ix, NFData e, Eq e) => Eq (Array BN ix e) | |
(Prim e, Eq e, Index ix) => Eq (Array P ix e) | |
(Storable e, Eq e, Index ix) => Eq (Array S ix e) | |
(Unbox e, Eq e, Index ix) => Eq (Array U ix e) | |
(Index ix, Ord e) => Ord (Array DI ix e) | |
Defined in Data.Massiv.Array.Delayed.Interleaved compare :: Array DI ix e -> Array DI ix e -> Ordering # (<) :: Array DI ix e -> Array DI ix e -> Bool # (<=) :: Array DI ix e -> Array DI ix e -> Bool # (>) :: Array DI ix e -> Array DI ix e -> Bool # (>=) :: Array DI ix e -> Array DI ix e -> Bool # | |
(Ord e, Index ix) => Ord (Array D ix e) | |
Defined in Data.Massiv.Array.Delayed.Pull | |
(Index ix, Ord e) => Ord (Array B ix e) | |
Defined in Data.Massiv.Array.Manifest.Boxed | |
(Index ix, Ord e) => Ord (Array BL ix e) | |
Defined in Data.Massiv.Array.Manifest.Boxed compare :: Array BL ix e -> Array BL ix e -> Ordering # (<) :: Array BL ix e -> Array BL ix e -> Bool # (<=) :: Array BL ix e -> Array BL ix e -> Bool # (>) :: Array BL ix e -> Array BL ix e -> Bool # (>=) :: Array BL ix e -> Array BL ix e -> Bool # | |
(Index ix, NFData e, Ord e) => Ord (Array BN ix e) | |
Defined in Data.Massiv.Array.Manifest.Boxed compare :: Array BN ix e -> Array BN ix e -> Ordering # (<) :: Array BN ix e -> Array BN ix e -> Bool # (<=) :: Array BN ix e -> Array BN ix e -> Bool # (>) :: Array BN ix e -> Array BN ix e -> Bool # (>=) :: Array BN ix e -> Array BN ix e -> Bool # | |
(Prim e, Ord e, Index ix) => Ord (Array P ix e) | |
Defined in Data.Massiv.Array.Manifest.Primitive | |
(Storable e, Ord e, Index ix) => Ord (Array S ix e) | |
Defined in Data.Massiv.Array.Manifest.Storable | |
(Unbox e, Ord e, Index ix) => Ord (Array U ix e) | |
Defined in Data.Massiv.Array.Manifest.Unboxed | |
newtype Array DI ix e | |
data Array D ix e | |
Defined in Data.Massiv.Array.Delayed.Pull | |
data Array DL ix e | |
data Array DW ix e | |
newtype Array B ix e | |
data Array BL ix e | |
newtype Array BN ix e | |
data Array P ix e | |
data Array S ix e | |
Defined in Data.Massiv.Array.Manifest.Storable | |
data Array U ix e | |
data Array L ix e | |
newtype Array DS Ix1 e | |
type Item (Array DS Ix1 e) | |
Defined in Data.Massiv.Array.Delayed.Stream | |
type Item (Array B ix e) | |
type Item (Array BL ix e) | |
type Item (Array BN ix e) | |
type Item (Array P ix e) | |
type Item (Array S ix e) | |
type Item (Array U ix e) | |
type Item (Array L ix e) | |
Defined in Data.Massiv.Core.List |
2-dimensional index. This is also a base index for higher dimensions.
Since: massiv-0.1.0
Instances
3-dimensional type synonym. Useful as a alternative to enabling DataKinds
and using type
level Nats.
Since: massiv-0.1.0
size :: Size r => Array r ix e -> Sz ix #
O(1) - Get the exact size of an immutabe array. Most of the time will
produce the size in constant time, except for DS
representation, which could result in evaluation of the whole stream. See
maxLinearSize
and slength
for more info.
Since: massiv-0.1.0
(!>) :: forall r ix e. (HasCallStack, Index ix, Index (Lower ix), Source r e) => Array r ix e -> Int -> Array r (Lower ix) e infixl 4 #
O(1) - Slices the array from the outside. For 2-dimensional array this will be equivalent of taking a row. Throws an error when index is out of bounds.
Examples
You could say that slicing from outside is synonymous to slicing from the end or slicing at the highermost dimension. For example with rank-3 arrays outer slice would be equivalent to getting a page:
>>>
import Data.Massiv.Array
>>>
arr = makeArrayR U Seq (Sz (3 :> 2 :. 4)) fromIx3
>>>
arr
Array U Seq (Sz (3 :> 2 :. 4)) [ [ [ (0,0,0), (0,0,1), (0,0,2), (0,0,3) ] , [ (0,1,0), (0,1,1), (0,1,2), (0,1,3) ] ] , [ [ (1,0,0), (1,0,1), (1,0,2), (1,0,3) ] , [ (1,1,0), (1,1,1), (1,1,2), (1,1,3) ] ] , [ [ (2,0,0), (2,0,1), (2,0,2), (2,0,3) ] , [ (2,1,0), (2,1,1), (2,1,2), (2,1,3) ] ] ]>>>
arr !> 2
Array U Seq (Sz (2 :. 4)) [ [ (2,0,0), (2,0,1), (2,0,2), (2,0,3) ] , [ (2,1,0), (2,1,1), (2,1,2), (2,1,3) ] ]
There is nothing wrong with chaining, mixing and matching slicing operators:
>>>
arr !> 2 !> 0 ! 3
(2,0,3)>>>
evaluateM (arr !> 2 <! 3) 0
(2,0,3)>>>
(arr !> 2 !> 0 ! 3) == (arr ! 2 :> 0 :. 3)
True
Since: massiv-0.1.0
(!?>) :: forall r ix e m. (MonadThrow m, Index ix, Index (Lower ix), Source r e) => Array r ix e -> Int -> m (Array r (Lower ix) e) infixl 4 #
(<!) :: forall r ix e. (HasCallStack, Index ix, Source r e) => Array r ix e -> Int -> Array D (Lower ix) e infixl 4 #
O(1) - Similarly to (!>
) slice an array from an opposite direction.
Since: massiv-0.1.0
(<!?) :: forall r ix e m. (MonadThrow m, Index ix, Source r e) => Array r ix e -> Int -> m (Array D (Lower ix) e) infixl 4 #
O(1) - Safe slice from the inside
Since: massiv-0.1.0
(<!>) :: forall r ix e. (HasCallStack, Index ix, Index (Lower ix), Source r e) => Array r ix e -> (Dim, Int) -> Array D (Lower ix) e infixl 4 #
O(1) - Slices the array in any available dimension. Throws an error when index is out of bounds or dimensions is invalid.
Since: massiv-0.1.0
A way to select Array dimension at a value level.
Since: massiv-0.1.0
Instances
Enum Dim | |
Num Dim | |
Integral Dim | |
Real Dim | |
Defined in Data.Massiv.Core.Index.Internal toRational :: Dim -> Rational # | |
Show Dim | |
NFData Dim | |
Defined in Data.Massiv.Core.Index.Internal | |
Eq Dim | |
Ord Dim | |
Random Dim | |
Uniform Dim | |
Defined in Data.Massiv.Core.Index.Internal uniformM :: StatefulGen g m => g -> m Dim # | |
UniformRange Dim | |
Defined in Data.Massiv.Core.Index.Internal |