Commit e5a4d5aa authored by Alfredo Di Napoli's avatar Alfredo Di Napoli Committed by Alfredo Di Napoli

Make tests pass given the use of makeArrayR for d_1 and d_2

parent 5ee7761f
......@@ -137,7 +137,15 @@ diag matrix =
--
-- /IMPORTANT/: As this function computes the diagonal matrix in order to carry on the computation
-- the input has to be a square matrix, or this function will fail at runtime.
distributional :: forall r e. (A.Manifest r e, A.Unbox e, A.Source r Int, A.Size r, Ord e, Fractional e, Num e)
distributional :: forall r e.
( A.Manifest r e
, A.Unbox e
, A.Source r Int
, A.Size r
, Ord e
, Fractional e
, Num e
)
=> Matrix r Int
-> Matrix r e
distributional m' = result
......@@ -146,34 +154,37 @@ distributional m' = result
m = A.computeP $ A.map fromIntegral m'
n = dim m'
-- Computes the diagonal matrix of the input ..
diag_m :: Vector A.U e
diag_m = A.computeP $ diag m
-- .. and its size.
diag_m_size :: Int
(A.Sz1 diag_m_size) = A.size diag_m
-- replicate (constant (Z :. n :. All)) diag_m
d_1 :: Matrix D e
d_1 = A.backpermute' (A.Sz2 n diag_m_size) (\(_ A.:. i) -> i) diag_m
-- Then we create a matrix that contains the same elements of diag_m
-- for the rows and columns, to make it square again.
d_1 :: Matrix A.U e
d_1 = A.makeArrayR A.U A.Par (A.Sz2 n diag_m_size) $ \(_ A.:. i) -> diag_m A.! i
-- replicate (constant (Z :. All :. n)) diag_m
d_2 :: Matrix D e
d_2 = A.backpermute' (A.Sz2 diag_m_size n) (\(i A.:. _) -> i) diag_m
d_2 :: Matrix A.U e
d_2 = A.makeArrayR A.U A.Par (A.Sz2 n diag_m_size) $ \(i A.:. _) -> diag_m A.! i
mi :: Matrix A.U e
mi = (.*) (termDivNan @A.U m d_1) (termDivNan @A.U m d_2)
mi_r, mi_c :: Int
(A.Sz2 mi_r mi_c) = A.size mi
-- The matrix permutations is taken care of below by directly replicating
-- the matrix mi, making the matrix w unneccessary and saving one step.
-- replicate (constant (Z :. All :. n :. All)) mi
w_1 :: Array D Ix3 e
w_1 = let (A.Sz2 r c) = A.size mi
in A.backpermute' (A.Sz3 r n c) (\(x A.:> _y A.:. z) -> x A.:. z) mi
w_1 = A.backpermute' (A.Sz3 mi_r n mi_c) (\(x A.:> _y A.:. z) -> x A.:. z) mi
-- replicate (constant (Z :. n :. All :. All)) mi
w_2 :: Array D Ix3 e
w_2 = let (A.Sz2 r c) = A.size mi
in A.backpermute' (A.Sz3 n r c) (\(_x A.:> y A.:. z) -> y A.:. z) mi
w_2 = A.backpermute' (A.Sz3 n mi_r mi_c) (\(_x A.:> y A.:. z) -> y A.:. z) mi
w' :: Array D Ix3 e
w' = A.zipWith min w_1 w_2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment