| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Tile.Affine
Description
An AffineRankSpace maps logical coordinates to integer ranks via
an offset and per-dimension strides. The type is general: any
combination of offset, sizes, and strides is representable.
Functions divide into two classes:
- Unconditional
rankOfandrankOfMaybecomputeoffset + sum (zipWith (*) coord strides)for any strides.- Row-major invariant required
pointOfandpointOfMayberecover coordinates by mixed-radix division and requirestrides[k] = product(sizes[k+1..])at every level.rowMajorestablishes this invariant;selectandfixDimpreserve it.
Synopsis
- data AffineRankSpace = AffineRankSpace {}
- type Point = [Int]
- rowMajor :: Shape -> AffineRankSpace
- rankOf :: AffineRankSpace -> Point -> Int
- rankOfMaybe :: AffineRankSpace -> Point -> Maybe Int
- pointOf :: AffineRankSpace -> Int -> Point
- pointOfMaybe :: AffineRankSpace -> Int -> Maybe Point
- spaceExtent :: AffineRankSpace -> Int
- points :: Shape -> [Point]
- ranks :: AffineRankSpace -> [Int]
- select :: AffineRankSpace -> Int -> Int -> Int -> Int -> Maybe AffineRankSpace
- fixDim :: AffineRankSpace -> Int -> Int -> Maybe AffineRankSpace
Affine rank spaces
data AffineRankSpace Source #
An affine map from logical coordinates to ranks.
For a coordinate coord, the rank is:
offset + sum (zipWith (*) coord strides)
Constructors
| AffineRankSpace | |
Instances
| Eq AffineRankSpace Source # | |
Defined in Tile.Affine Methods (==) :: AffineRankSpace -> AffineRankSpace -> Bool # (/=) :: AffineRankSpace -> AffineRankSpace -> Bool # | |
| Show AffineRankSpace Source # | |
Defined in Tile.Affine Methods showsPrec :: Int -> AffineRankSpace -> ShowS # show :: AffineRankSpace -> String # showList :: [AffineRankSpace] -> ShowS # | |
rowMajor :: Shape -> AffineRankSpace Source #
Construct the row-major affine rank space for a shape.
Strides satisfy strides[k] = product(sizes[k+1..]), which is the
row-major invariant required by pointOf and pointOfMaybe.
select and fixDim preserve this invariant.
Coordinate/rank conversion
rankOf :: AffineRankSpace -> Point -> Int Source #
Convert a coordinate to a rank.
Unconditional: works for any AffineRankSpace. Throws an error if
the coordinate has the wrong dimension or is out of bounds. Use
rankOfMaybe for a total variant.
rankOfMaybe :: AffineRankSpace -> Point -> Maybe Int Source #
Convert a coordinate to a rank, returning Nothing for invalid
coordinates.
Unconditional: works for any AffineRankSpace.
pointOf :: AffineRankSpace -> Int -> Point Source #
Convert a rank to a coordinate.
Precondition: strides must satisfy the row-major invariant
(strides[k] = sizes[k+1] * strides[k+1]). All spaces produced by
rowMajor, select, and fixDim satisfy this. A hand-constructed
AffineRankSpace with arbitrary strides may produce wrong
coordinates without error.
Throws an error if the rank is outside the affine rank space. Use
pointOfMaybe for a total variant.
pointOfMaybe :: AffineRankSpace -> Int -> Maybe Point Source #
Queries
spaceExtent :: AffineRankSpace -> Int Source #
Number of logical points in an affine rank space.
points :: Shape -> [Point] Source #
Enumerate all logical coordinates for a shape.
Coordinates are scanned in row-major order: the last dimension varies
fastest. This is the coordinate grid used by ranks.
ranks :: AffineRankSpace -> [Int] Source #
Enumerate all ranks in logical coordinate order.
Unconditional: works for any AffineRankSpace. Ranks are ordered
by the row-major scan of the coordinate grid via points.
Slicing
select :: AffineRankSpace -> Int -> Int -> Int -> Int -> Maybe AffineRankSpace Source #
fixDim :: AffineRankSpace -> Int -> Int -> Maybe AffineRankSpace Source #
Select one index along a dimension.
The fixed dimension remains present with extent 1. Preserves the
row-major stride invariant via select.