Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
160
Issues
160
List
Board
Labels
Milestones
Merge Requests
14
Merge Requests
14
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
60de75f7
Commit
60de75f7
authored
Feb 03, 2025
by
Alfredo Di Napoli
Committed by
Alfredo Di Napoli
Feb 27, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extra performance tuning for distributional
parent
52edb95c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
18 deletions
+52
-18
Main.hs
bench/Main.hs
+4
-0
LinearAlgebra.hs
src/Gargantext/Core/LinearAlgebra.hs
+21
-10
Distributional.hs
...xt/Core/Methods/Similarities/Accelerate/Distributional.hs
+27
-8
No files found.
bench/Main.hs
View file @
60de75f7
...
@@ -121,5 +121,9 @@ main = do
...
@@ -121,5 +121,9 @@ main = do
,
bench
"Accelerate (LLVM)"
$
nf
Accelerate
.
distributional
accInput
,
bench
"Accelerate (LLVM)"
$
nf
Accelerate
.
distributional
accInput
,
bench
"Massiv "
$
nf
(
LA
.
distributional
@
_
@
Double
)
massivInput
,
bench
"Massiv "
$
nf
(
LA
.
distributional
@
_
@
Double
)
massivInput
]
]
,
bgroup
"logDistributional2"
[
bench
"Accelerate (Naive)"
$
nf
(
Accelerate
.
logDistributional2With
@
Double
Naive
.
run
)
accInput
,
bench
"Accelerate (LLVM)"
$
nf
Accelerate
.
logDistributional2
accInput
]
]
]
]
]
src/Gargantext/Core/LinearAlgebra.hs
View file @
60de75f7
...
@@ -165,10 +165,10 @@ distributional m' = result
...
@@ -165,10 +165,10 @@ distributional m' = result
-- Then we create a matrix that contains the same elements of 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.
-- for the rows and columns, to make it square again.
d_1
::
Matrix
A
.
U
e
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
d_1
=
A
.
makeArrayR
A
.
U
A
.
Seq
(
A
.
Sz2
n
diag_m_size
)
$
\
(
_
A
.:.
i
)
->
diag_m
A
.!
i
d_2
::
Matrix
A
.
U
e
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
d_2
=
A
.
makeArrayR
A
.
U
A
.
Seq
(
A
.
Sz2
n
diag_m_size
)
$
\
(
i
A
.:.
_
)
->
diag_m
A
.!
i
mi
::
Matrix
A
.
U
e
mi
::
Matrix
A
.
U
e
mi
=
(
.*
)
(
termDivNan
@
A
.
U
m
d_1
)
(
termDivNan
@
A
.
U
m
d_2
)
mi
=
(
.*
)
(
termDivNan
@
A
.
U
m
d_1
)
(
termDivNan
@
A
.
U
m
d_2
)
...
@@ -193,13 +193,13 @@ distributional m' = result
...
@@ -193,13 +193,13 @@ distributional m' = result
-- and r_(i,j,k) = 1 otherwise (i.e. k /= i AND k /= j).
-- and r_(i,j,k) = 1 otherwise (i.e. k /= i AND k /= j).
-- generate (constant (Z :. n :. n :. n)) (lift1 (\( i A.:. j A.:. k) -> cond ((&&) ((/=) k i) ((/=) k j)) 1 0))
-- generate (constant (Z :. n :. n :. n)) (lift1 (\( i A.:. j A.:. k) -> cond ((&&) ((/=) k i) ((/=) k j)) 1 0))
ii
::
Array
A
.
U
Ix3
e
ii
::
Array
A
.
U
Ix3
e
ii
=
A
.
makeArrayR
A
.
U
A
.
Par
(
A
.
Sz3
n
n
n
)
$
\
(
i
A
.:>
j
A
.:.
k
)
->
if
k
/=
i
&&
k
/=
j
then
1
else
0
ii
=
A
.
makeArrayR
A
.
U
A
.
Seq
(
A
.
Sz3
n
n
n
)
$
\
(
i
A
.:>
j
A
.:.
k
)
->
if
k
/=
i
&&
k
/=
j
then
1
else
0
z_1
::
Matrix
A
.
U
e
z_1
::
Matrix
A
.
D
e
z_1
=
sumRows
((
.*
)
w'
ii
)
z_1
=
sumRows
D
(
w'
`
mulD
`
ii
)
z_2
::
Matrix
A
.
U
e
z_2
::
Matrix
A
.
D
e
z_2
=
sumRows
((
.*
)
w_1
ii
)
z_2
=
sumRows
D
(
w_1
`
mulD
`
ii
)
result
=
termDivNan
z_1
z_2
result
=
termDivNan
z_1
z_2
...
@@ -218,8 +218,13 @@ sumRows :: ( A.Load r A.Ix2 e
...
@@ -218,8 +218,13 @@ sumRows :: ( A.Load r A.Ix2 e
,
Num
e
,
Num
e
)
=>
Array
r
A
.
Ix3
e
)
=>
Array
r
A
.
Ix3
e
->
Array
r
A
.
Ix2
e
->
Array
r
A
.
Ix2
e
sumRows
matrix
=
sumRows
=
A
.
compute
.
sumRowsD
A
.
computeP
$
A
.
map
getSum
$
A
.
foldlWithin'
1
(
\
(
Sum
s
)
n
->
Sum
$
s
+
n
)
mempty
matrix
sumRowsD
::
(
A
.
Source
r
e
,
Num
e
)
=>
Array
r
A
.
Ix3
e
->
Array
D
A
.
Ix2
e
sumRowsD
matrix
=
A
.
map
getSum
$
A
.
foldlWithin'
1
(
\
(
Sum
s
)
n
->
Sum
$
s
+
n
)
mempty
matrix
sumRowsReferenceImplementation
::
(
A
.
Load
r
A
.
Ix2
e
sumRowsReferenceImplementation
::
(
A
.
Load
r
A
.
Ix2
e
,
A
.
Source
r
e
,
A
.
Source
r
e
...
@@ -239,7 +244,13 @@ sumRowsReferenceImplementation matrix =
...
@@ -239,7 +244,13 @@ sumRowsReferenceImplementation matrix =
=>
Array
r1
ix
a
=>
Array
r1
ix
a
->
Array
r2
ix
a
->
Array
r2
ix
a
->
Array
r3
ix
a
->
Array
r3
ix
a
(
.*
)
m1
m2
=
A
.
computeP
$
A
.
zipWith
(
*
)
m1
m2
(
.*
)
m1
=
A
.
compute
.
mulD
m1
mulD
::
(
A
.
Source
r1
a
,
A
.
Source
r2
a
,
A
.
Index
ix
,
Num
a
)
=>
Array
r1
ix
a
->
Array
r2
ix
a
->
Array
D
ix
a
mulD
m1
m2
=
A
.
zipWith
(
*
)
m1
m2
-- | Get the dimensions of a /square/ matrix.
-- | Get the dimensions of a /square/ matrix.
dim
::
A
.
Size
r
=>
Matrix
r
a
->
Int
dim
::
A
.
Size
r
=>
Matrix
r
a
->
Int
...
...
src/Gargantext/Core/Methods/Similarities/Accelerate/Distributional.hs
View file @
60de75f7
...
@@ -94,6 +94,7 @@ module Gargantext.Core.Methods.Similarities.Accelerate.Distributional
...
@@ -94,6 +94,7 @@ module Gargantext.Core.Methods.Similarities.Accelerate.Distributional
-- internals for testing
-- internals for testing
,
distributionalWith
,
distributionalWith
,
logDistributional2With
)
)
where
where
...
@@ -104,9 +105,6 @@ import Data.Array.Accelerate as A
...
@@ -104,9 +105,6 @@ import Data.Array.Accelerate as A
import
Data.Array.Accelerate.LLVM.Native
qualified
as
LLVM
-- TODO: try runQ?
import
Data.Array.Accelerate.LLVM.Native
qualified
as
LLVM
-- TODO: try runQ?
import
Gargantext.Core.Methods.Matrix.Accelerate.Utils
import
Gargantext.Core.Methods.Matrix.Accelerate.Utils
import
Debug.Trace
(
trace
)
import
Prelude
(
show
,
mappend
{- , String, (<>), fromIntegral, flip -}
)
import
qualified
Prelude
import
qualified
Prelude
-- | `distributional m` returns the distributional distance between terms each
-- | `distributional m` returns the distributional distance between terms each
...
@@ -183,15 +181,36 @@ distributionalWith interpret m' = interpret $ result
...
@@ -183,15 +181,36 @@ distributionalWith interpret m' = interpret $ result
result
=
termDivNan
z_1
z_2
result
=
termDivNan
z_1
z_2
logDistributional2
::
Matrix
Int
->
Matrix
Double
logDistributional2
::
Matrix
Int
->
Matrix
Double
logDistributional2
m
=
trace
(
"logDistributional2, dim="
`
mappend
`
show
n
)
.
LLVM
.
run
logDistributional2
m
=
logDistributional2With
LLVM
.
run
m
logDistributional2With
::
(
Elt
e
,
Prelude
.
Num
(
Exp
e
)
,
Ord
e
,
Prelude
.
Num
e
,
FromIntegral
Int
e
,
Prelude
.
Fractional
(
Exp
e
)
,
Prelude
.
Floating
(
Exp
e
)
)
=>
(
forall
a
.
Arrays
a
=>
Acc
a
->
a
)
->
Matrix
Int
->
Matrix
e
logDistributional2With
interpreter
m
=
interpreter
$
diagNull
n
$
diagNull
n
$
matMaxMini
$
matMaxMini
$
logDistributional'
n
m
$
logDistributional'
n
m
where
where
n
=
dim
m
n
=
dim
m
logDistributional'
::
Int
->
Matrix
Int
->
Acc
(
Matrix
Double
)
logDistributional'
::
(
Elt
e
logDistributional'
n
m'
=
trace
(
"logDistributional'"
)
result
,
Prelude
.
Num
(
Exp
e
)
,
FromIntegral
Int
e
,
Eq
e
,
Ord
e
,
Prelude
.
Fractional
(
Exp
e
)
,
Prelude
.
Floating
(
Exp
e
)
)
=>
Int
->
Matrix
Int
->
Acc
(
Matrix
e
)
logDistributional'
n
m'
=
result
where
where
-- From Matrix Int to Matrix Double, i.e :
-- From Matrix Int to Matrix Double, i.e :
-- m :: Matrix Int -> Matrix Double
-- m :: Matrix Int -> Matrix Double
...
@@ -249,10 +268,10 @@ logDistributional' n m' = trace ("logDistributional'") result
...
@@ -249,10 +268,10 @@ logDistributional' n m' = trace ("logDistributional'") result
-- k_diff_i_and_j = lift1 (\(Z :. i :. j :. k) -> ((&&) ((/=) k i) ((/=) k j)))
-- k_diff_i_and_j = lift1 (\(Z :. i :. j :. k) -> ((&&) ((/=) k i) ((/=) k j)))
-- Matrix nxn.
-- Matrix nxn.
sumMin
=
trace
"sumMin"
$
sumMin_go
n
mi
-- sum (condOrDefault k_diff_i_and_j 0 w')
sumMin
=
sumMin_go
n
mi
-- sum (condOrDefault k_diff_i_and_j 0 w')
-- Matrix nxn. All columns are the same.
-- Matrix nxn. All columns are the same.
sumM
=
trace
"sumM"
$
sumM_go
n
mi
-- trace "sumM" $ sum (condOrDefault k_diff_i_and_j 0 w_1)
sumM
=
sumM_go
n
mi
-- trace "sumM" $ sum (condOrDefault k_diff_i_and_j 0 w_1)
result
=
termDivNan
sumMin
sumM
result
=
termDivNan
sumMin
sumM
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment