Generalize transpose to all arrays

This commit is contained in:
Kiana Sheibani 2022-08-31 16:01:21 -04:00
parent ea824a901b
commit 92fc8f00c9
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
2 changed files with 9 additions and 10 deletions

View file

@ -484,6 +484,15 @@ stack axis arrs = rewrite sym (lengthCorrect arrs) in
getAxisInd FZ (i :: is) = (i, is) getAxisInd FZ (i :: is) = (i, is)
getAxisInd {s=_::_} (FS ax) (i :: is) = mapSnd (i::) (getAxisInd ax is) getAxisInd {s=_::_} (FS ax) (i :: is) = mapSnd (i::) (getAxisInd ax is)
export
transpose : Array s a -> Array (reverse s) a
transpose arr with (viewShape arr)
_ | Shape s = fromFunctionNB (reverse s) (\is => arr !# reverse is)
export
(.T) : Array s a -> Array (reverse s) a
(.T) = transpose
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Implementations -- Implementations

View file

@ -141,16 +141,6 @@ hstack : {m : _} -> Vect n (Vector m a) -> Matrix m n a
hstack = stack 1 hstack = stack 1
export
transpose : Matrix m n a -> Matrix n m a
transpose mat with (viewShape mat)
_ | Shape [m,n] = fromFunctionNB [n,m] (\[i,j] => mat!#[j,i])
export
(.T) : Matrix m n a -> Matrix n m a
(.T) = transpose
||| Calculate the outer product of two vectors as a matrix. ||| Calculate the outer product of two vectors as a matrix.
export export
outer : Num a => Vector m a -> Vector n a -> Matrix m n a outer : Num a => Vector m a -> Vector n a -> Matrix m n a