module Data.Array.Comfort.Check where

import qualified Data.Array.Comfort.Shape as Shape

import Text.Printf (printf)


{-# INLINE reshape #-}
reshape ::
   (Shape.C sh0, Shape.C sh1) =>
   String ->
   (array0 -> sh0) ->
   (sh1 -> array0 -> array1) ->
   sh1 -> array0 -> array1
reshape :: String
-> (array0 -> sh0)
-> (sh1 -> array0 -> array1)
-> sh1
-> array0
-> array1
reshape String
name array0 -> sh0
shape sh1 -> array0 -> array1
uncheckedReshape sh1
sh1 array0
arr =
   let n0 :: Int
n0 = sh0 -> Int
forall sh. C sh => sh -> Int
Shape.size (sh0 -> Int) -> sh0 -> Int
forall a b. (a -> b) -> a -> b
$ array0 -> sh0
shape array0
arr
       n1 :: Int
n1 = sh1 -> Int
forall sh. C sh => sh -> Int
Shape.size sh1
sh1
   in if Int
n0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n1
         then sh1 -> array0 -> array1
uncheckedReshape sh1
sh1 array0
arr
         else String -> array1
forall a. HasCallStack => String -> a
error (String -> array1) -> String -> array1
forall a b. (a -> b) -> a -> b
$
              String -> String -> Int -> Int -> String
forall r. PrintfType r => String -> r
printf
                 (String
"Array.Comfort.%s.reshape: " String -> String -> String
forall a. [a] -> [a] -> [a]
++
                  String
"different sizes of old (%d) and new (%d) shape")
                 String
name Int
n0 Int
n1