... | @@ -19,13 +19,16 @@ When encoding multidimensional arrays using segment descriptors or by storing th |
... | @@ -19,13 +19,16 @@ When encoding multidimensional arrays using segment descriptors or by storing th |
|
|
|
|
|
The remainder of this document is a first design draft for SAC style language support of multidimensional arrays in the context of DPH. The implementation is not completed yet, and there are several open questions.
|
|
The remainder of this document is a first design draft for SAC style language support of multidimensional arrays in the context of DPH. The implementation is not completed yet, and there are several open questions.
|
|
|
|
|
|
|
|
**SLPJ: perhaps early give some SAC examples and the corresponding
|
|
|
|
code for us.**
|
|
|
|
|
|
## The regular array type
|
|
## The regular array type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Regular parallel arrays are similar to arrays in SAC, with one major
|
|
Regular parallel arrays are similar to arrays in SAC, with one major
|
|
difference: array operations in DPH are fully typed, and consequently, what
|
|
difference: array operations in DPH are fully typed, and consequently, what
|
|
is called 'shape invariant programming' in SAC works differently in DPH. In particular, the dimensionality of an array (not its size, however) are encoded in its type.
|
|
is called 'shape invariant programming' in SAC works differently in DPH. In particular, the dimensionality of an array (not its size, however) are encoded in its type. **SLPJ: unlike SAC, where functions can be polymorphic even in the dimensionality of the array?**
|
|
|
|
|
|
|
|
|
|
An multidimensional array is parametrised with its dimensionality and its
|
|
An multidimensional array is parametrised with its dimensionality and its
|
... | @@ -45,6 +48,8 @@ tuples - arrays of which correspond to scalar values. So, for example |
... | @@ -45,6 +48,8 @@ tuples - arrays of which correspond to scalar values. So, for example |
|
Array (3,2) Double -- two dimensional array (matrix) of three rows, two columns
|
|
Array (3,2) Double -- two dimensional array (matrix) of three rows, two columns
|
|
```
|
|
```
|
|
|
|
|
|
|
|
**SLPJ: urk. Is `(2,3)` a type?! Or did you mean `Array (Int,Int) Double`?**
|
|
|
|
|
|
|
|
|
|
Internally, shapes are represented as nested pairs
|
|
Internally, shapes are represented as nested pairs
|
|
|
|
|
... | @@ -58,27 +63,27 @@ type instance Shape (Int, Int) = (((),Int), Int) |
... | @@ -58,27 +63,27 @@ type instance Shape (Int, Int) = (((),Int), Int) |
|
|
|
|
|
Elements types are restricted to the element type of flat parallel
|
|
Elements types are restricted to the element type of flat parallel
|
|
arrays, that it, primitive types like integers, boolean and floating
|
|
arrays, that it, primitive types like integers, boolean and floating
|
|
point numbers, and tuples.
|
|
point numbers, and tuples. **SLPJ: so what is in class `Elt`?**
|
|
|
|
|
|
## Operations
|
|
## Operations
|
|
|
|
|
|
### Creating Arrays
|
|
### Creating Arrays
|
|
|
|
|
|
|
|
|
|
A new arrays can be created from flat parallel arrays
|
|
A new array can be created from a flat parallel array
|
|
|
|
|
|
```wiki
|
|
```wiki
|
|
fromNArray:: U.Elt r => U.Array r -> Array DIM1 r
|
|
fromNArray:: U.Elt r => U.Array r -> Array DIM1 r
|
|
```
|
|
```
|
|
|
|
|
|
|
|
**SLPJ: what is U? What is U.Array?**
|
|
and from scalar values:
|
|
and from scalar values:
|
|
|
|
|
|
```wiki
|
|
```wiki
|
|
fromScalar:: U.Elt r => r -> Array DIM0 r
|
|
fromScalar:: U.Elt r => r -> Array DIM0 r
|
|
```
|
|
```
|
|
|
|
|
|
|
|
**SLPJ: whoa! What are `DIM1`, `DIM0`? Presumably you mean 1-dimensional etc. But indexed by what? Always `Int`? Maybe that's ok; but say so.**
|
|
and bpermuteR, which creates a new array of new shape, using values of the argument array.
|
|
and bpermuteR, which creates a new array of new shape, using values of the argument array.
|
|
|
|
|
|
```wiki
|
|
```wiki
|
... | @@ -86,7 +91,7 @@ bpermuteR:: Array dim e -> Shape dim' -> (Shape dim' -> Shape dim) -> Array dim' |
... | @@ -86,7 +91,7 @@ bpermuteR:: Array dim e -> Shape dim' -> (Shape dim' -> Shape dim) -> Array dim' |
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
For example, transposition of a two dimensional array can be defined in terms of mkArray as follows:
|
|
For example, transposition of a two dimensional array can be defined in terms of mkArray as follows **SLPJ: in terms of `bpermuteR` perhaps?**:
|
|
|
|
|
|
```wiki
|
|
```wiki
|
|
transpose:: Array DIM2 a -> Array DIM2 a
|
|
transpose:: Array DIM2 a -> Array DIM2 a
|
... | @@ -94,7 +99,7 @@ transpose arr = bpermuteR arr (n,m) (\(i,j) -> (j,i)) |
... | @@ -94,7 +99,7 @@ transpose arr = bpermuteR arr (n,m) (\(i,j) -> (j,i)) |
|
where (n,m) = shape arr
|
|
where (n,m) = shape arr
|
|
```
|
|
```
|
|
|
|
|
|
|
|
**SLPJ: presumably `shape :: Array dim a -> Shape dim`? Or perhaps rather `shape :: Array dim a -> dim`?**. **SLPJ: did you mean `bpermuteR arr (m,n)`?**
|
|
Or cutting a 3 x 3 tile starting at indices (0,0) out of a two dimensional matrix:
|
|
Or cutting a 3 x 3 tile starting at indices (0,0) out of a two dimensional matrix:
|
|
|
|
|
|
```wiki
|
|
```wiki
|
... | @@ -102,6 +107,8 @@ tile:: Array DIM2 a -> Array DIM2 a |
... | @@ -102,6 +107,8 @@ tile:: Array DIM2 a -> Array DIM2 a |
|
tile arr = bpermuteR arr (3,3) id
|
|
tile arr = bpermuteR arr (3,3) id
|
|
```
|
|
```
|
|
|
|
|
|
|
|
**SLPJ: Does the `Shape` stuff need to be exposed at this level. Could we not work just in terms of the `(Int,Int)` indices the programmer expects, and hide the shapery?**
|
|
|
|
|
|
### Manipulating array values
|
|
### Manipulating array values
|
|
|
|
|
|
|
|
|
... | @@ -124,8 +131,7 @@ scan :: Elt a => ((a, a) -> a) -- combination function |
... | @@ -124,8 +131,7 @@ scan :: Elt a => ((a, a) -> a) -- combination function |
|
-> (Array dim a, Array (dim, Int) a)
|
|
-> (Array dim a, Array (dim, Int) a)
|
|
```
|
|
```
|
|
|
|
|
|
|
|
**SLPJ: didn't understand scan**. Manipulating the shape of arrays:
|
|
Manipulating the shape of arrays:
|
|
|
|
|
|
|
|
```wiki
|
|
```wiki
|
|
-- size of both shapes have to be the same, otherwise runtime error
|
|
-- size of both shapes have to be the same, otherwise runtime error
|
... | @@ -135,6 +141,8 @@ reshape ::(Ix (Shape dim), Ix (Shape dim')) => |
... | @@ -135,6 +141,8 @@ reshape ::(Ix (Shape dim), Ix (Shape dim')) => |
|
-> Array dim a
|
|
-> Array dim a
|
|
```
|
|
```
|
|
|
|
|
|
|
|
**SLPJ: why doesn't `reshape` need the size of the result array, as `bpermuteR` did.**
|
|
|
|
|
|
### Changing the dimensionality of an array
|
|
### Changing the dimensionality of an array
|
|
|
|
|
|
#### The index type
|
|
#### The index type
|
... | | ... | |