From de187b9b7e9cbdb79429c505f1e0f9954593c76c Mon Sep 17 00:00:00 2001 From: Mikolaj Konarski Date: Tue, 16 Dec 2025 20:43:38 +0100 Subject: De-triplicate ix?ToLinear --- src/Data/Array/Nested/Ranked/Shape.hs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/Data/Array/Nested/Ranked') diff --git a/src/Data/Array/Nested/Ranked/Shape.hs b/src/Data/Array/Nested/Ranked/Shape.hs index 0ac980e..74f4c5c 100644 --- a/src/Data/Array/Nested/Ranked/Shape.hs +++ b/src/Data/Array/Nested/Ranked/Shape.hs @@ -290,14 +290,10 @@ ixrPermutePrefix = coerce (listrPermutePrefix @i) -- index into the buffer. {-# INLINEABLE ixrToLinear #-} ixrToLinear :: Num i => IShR m -> IxR m i -> i -ixrToLinear = \sh i -> go sh i 0 - where - -- Additional argument: index, in the @m - m1@ dimensional array so far, - -- of the @m - m1 + n@ dimensional tensor pointed to by the current - -- @m - m1@ dimensional index prefix. - go :: Num i => IShR m1 -> IxR m1 i -> i -> i - go ZSR ZIR a = a - go (n :$: sh) (i :.: ix) a = go sh ix (fromIntegral n * a + i) +ixrToLinear (ShR sh) ix = ixxToLinear sh (ixxFromIxR ix) + +ixxFromIxR :: IxR n i -> IxX (Replicate n Nothing) i +ixxFromIxR = unsafeCoerce {-# INLINEABLE ixrFromLinear #-} ixrFromLinear :: forall i m. Num i => IShR m -> Int -> IxR m i -- cgit v1.2.3-70-g09d2