2 Module : Gargantext.Graph.Distances.Utils
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 These functions are used for Vector.Matrix only.
14 {-# LANGUAGE BangPatterns #-}
15 {-# LANGUAGE NoImplicitPrelude #-}
16 {-# LANGUAGE FlexibleContexts #-}
17 {-# LANGUAGE Strict #-}
19 module Gargantext.Viz.Graph.Utils
22 import Data.Matrix hiding (identity)
24 import Data.Vector (Vector)
25 import qualified Data.Vector as V
27 import qualified Data.List as L
28 import Gargantext.Prelude
30 ------------------------------------------------------------------------
31 -- | Some utils to build the matrix from cooccurrence results
33 -- | For tests only, to be removed
34 -- m1 :: Matrix Double
35 -- m1 = fromList 300 300 [1..]
36 ------------------------------------------------------------------------
37 ------------------------------------------------------------------------
39 ------------------------------------------------------------------------
43 -- Data.Vector.Additions
44 dropAt :: Int -> Vector a -> Vector a
45 dropAt n v = debut <> (V.tail fin)
50 total :: Num a => Matrix a -> a
51 total m = V.sum $ V.map (\c -> V.sum (getCol c m)) (V.enumFromTo 1 (nOf Col m))
53 nOf :: Axis -> Matrix a -> Int
57 axis :: Axis -> AxisId -> Matrix a -> Vector a
62 toListsWithIndex :: Matrix a -> [((Int, Int), a)]
63 toListsWithIndex m = concat' $ zip [1..] $ map (\c -> zip [1..] c) $ toLists m
65 concat' :: [(Int, [(Int, a)])] -> [((Int, Int), a)]
66 concat' xs = L.concat $ map (\(x, ys) -> map (\(y, a) -> ((x,y), a)) ys ) xs