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
286fc44d
Commit
286fc44d
authored
Feb 10, 2025
by
Alfredo Di Napoli
Committed by
Alfredo Di Napoli
Feb 27, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug in unsafe division in both implementations of logDistributional2
parent
681eb942
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
4 deletions
+34
-4
Distributional.hs
src/Gargantext/Core/LinearAlgebra/Distributional.hs
+3
-2
Utils.hs
src/Gargantext/Core/Methods/Matrix/Accelerate/Utils.hs
+6
-2
LinearAlgebra.hs
test/Test/Core/LinearAlgebra.hs
+25
-0
No files found.
src/Gargantext/Core/LinearAlgebra/Distributional.hs
View file @
286fc44d
...
@@ -212,7 +212,8 @@ distributionalReferenceImplementation m' = result
...
@@ -212,7 +212,8 @@ distributionalReferenceImplementation m' = result
logDistributional2
::
(
A
.
Manifest
r
e
logDistributional2
::
(
A
.
Manifest
r
e
,
A
.
Unbox
e
,
A
.
Unbox
e
,
A
.
Source
r
Int
,
A
.
Source
r
Int
,
A
.
Shape
r
Ix2
,
Num
e
,
A
.
Shape
r
Ix2
,
Num
e
,
Ord
e
,
Ord
e
,
A
.
Source
r
e
,
A
.
Source
r
e
,
Fractional
e
,
Fractional
e
...
@@ -272,7 +273,7 @@ logDistributional' n m' = result
...
@@ -272,7 +273,7 @@ logDistributional' n m' = result
mi_divvy
::
Matrix
A
.
D
e
mi_divvy
::
Matrix
A
.
D
e
mi_divvy
=
A
.
zipWith
(
\
m_val
ss_val
->
mi_divvy
=
A
.
zipWith
(
\
m_val
ss_val
->
let
x
=
m_val
/
ss_val
let
x
=
m_val
`
safeDiv
`
ss_val
x'
=
x
*
to
x'
=
x
*
to
in
if
(
x'
<
1
)
then
0
else
log
x'
)
m
ss
in
if
(
x'
<
1
)
then
0
else
log
x'
)
m
ss
...
...
src/Gargantext/Core/Methods/Matrix/Accelerate/Utils.hs
View file @
286fc44d
...
@@ -53,13 +53,14 @@ import qualified Gargantext.Prelude as P
...
@@ -53,13 +53,14 @@ import qualified Gargantext.Prelude as P
(
./
)
::
(
Shape
ix
(
./
)
::
(
Shape
ix
,
Slice
ix
,
Slice
ix
,
Elt
a
,
Elt
a
,
Eq
a
,
P
.
Num
(
Exp
a
)
,
P
.
Num
(
Exp
a
)
,
P
.
Fractional
(
Exp
a
)
,
P
.
Fractional
(
Exp
a
)
)
)
=>
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
=>
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
->
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
->
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
->
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
->
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
(
./
)
=
zipWith
(
/
)
(
./
)
=
zipWith
safeDivCond
-- | Term by term division where divisions by 0 produce 0 rather than NaN.
-- | Term by term division where divisions by 0 produce 0 rather than NaN.
termDivNan
::
(
Elt
a
termDivNan
::
(
Elt
a
...
@@ -70,7 +71,10 @@ termDivNan :: ( Elt a
...
@@ -70,7 +71,10 @@ termDivNan :: ( Elt a
=>
Acc
(
Matrix
a
)
=>
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
termDivNan
=
zipWith
(
\
i
j
->
cond
((
==
)
j
0
)
0
((
/
)
i
j
))
termDivNan
=
zipWith
safeDivCond
safeDivCond
::
(
Eq
a
,
P
.
Num
(
Exp
a
),
P
.
Fractional
(
Exp
a
))
=>
Exp
a
->
Exp
a
->
Exp
a
safeDivCond
i
j
=
cond
((
==
)
j
0
)
0
((
/
)
i
j
)
(
.-
)
::
(
Shape
ix
(
.-
)
::
(
Shape
ix
,
Slice
ix
,
Slice
ix
...
...
test/Test/Core/LinearAlgebra.hs
View file @
286fc44d
...
@@ -96,7 +96,30 @@ testMatrix_02 = SquareMatrix $ fromList (Z :. 7 :. 7) $
...
@@ -96,7 +96,30 @@ testMatrix_02 = SquareMatrix $ fromList (Z :. 7 :. 7) $
7
,
-
12
,
12
,
-
2
,
36
,
10
,
34
,
7
,
-
12
,
12
,
-
2
,
36
,
10
,
34
,
13
,
-
37
,
-
16
,
2
,
7
,
-
13
,
21
]
13
,
-
37
,
-
16
,
2
,
7
,
-
13
,
21
]
testMatrix_03
::
SquareMatrix
Int
testMatrix_03
=
SquareMatrix
$
fromList
(
Z
:.
11
:.
11
)
$
[
1
,
-
1
,
1
,
0
,
1
,
-
1
,
0
,
1
,
1
,
0
,
0
,
1
,
1
,
1
,
1
,
1
,
0
,
1
,
-
1
,
1
,
0
,
0
,
-
1
,
1
,
0
,
-
1
,
0
,
-
1
,
0
,
1
,
0
,
-
1
,
0
,
1
,
1
,
1
,
-
1
,
-
1
,
0
,
1
,
-
1
,
0
,
0
,
-
1
,
-
1
,
1
,
-
1
,
-
1
,
0
,
1
,
1
,
1
,
-
1
,
-
1
,
-
1
,
1
,
1
,
0
,
-
1
,
-
1
,
-
1
,
1
,
0
,
1
,
-
1
,
-
1
,
-
1
,
1
,
0
,
-
1
,
1
,
-
1
,
0
,
1
,
-
1
,
-
1
,
-
1
,
1
,
1
,
-
1
,
1
,
1
,
0
,
1
,
-
1
,
1
,
-
1
,
1
,
-
1
,
-
1
,
0
,
1
,
1
,
0
,
1
,
1
,
-
1
,
1
,
0
,
1
,
1
,
0
,
-
1
,
1
,
-
1
,
1
,
0
,
1
,
0
,
-
1
,
1
,
1
,
-
1
,
0
,
-
1
,
-
1
,
1
,
0
,
1
,
0
,
-
1
]
testMatrix_04
::
SquareMatrix
Int
testMatrix_04
=
SquareMatrix
$
fromList
(
Z
:.
8
:.
8
)
$
[
3
,
-
1
,
0
,
1
,
-
1
,
1
,
1
,
-
3
,
-
2
,
-
2
,
2
,
1
,
1
,
-
2
,
1
,
-
1
,
-
2
,
-
3
,
-
1
,
1
,
1
,
-
3
,
-
2
,
-
1
,
1
,
-
2
,
2
,
0
,
1
,
0
,
2
,
0
,
-
1
,
-
3
,
-
1
,
3
,
-
3
,
0
,
-
1
,
2
,
0
,
0
,
-
3
,
3
,
-
1
,
-
2
,
-
1
,
1
,
-
2
,
1
,
-
1
,
2
,
1
,
-
1
,
-
2
,
0
,
-
2
,
2
,
1
,
1
,
1
,
0
,
2
,
-
3
]
--
--
-- Main test runner
-- Main test runner
--
--
...
@@ -124,6 +147,8 @@ tests = testGroup "LinearAlgebra" [
...
@@ -124,6 +147,8 @@ tests = testGroup "LinearAlgebra" [
,
testGroup
"logDistributional2"
[
,
testGroup
"logDistributional2"
[
testProperty
"2x2"
(
compareLogDistributional2
(
Proxy
@
Double
)
twoByTwo
)
testProperty
"2x2"
(
compareLogDistributional2
(
Proxy
@
Double
)
twoByTwo
)
,
testProperty
"7x7"
(
compareLogDistributional2
(
Proxy
@
Double
)
testMatrix_02
)
,
testProperty
"7x7"
(
compareLogDistributional2
(
Proxy
@
Double
)
testMatrix_02
)
,
testProperty
"8x8"
(
compareLogDistributional2
(
Proxy
@
Double
)
testMatrix_04
)
,
testProperty
"11x11"
(
compareLogDistributional2
(
Proxy
@
Double
)
testMatrix_03
)
,
testProperty
"14x14"
(
compareLogDistributional2
(
Proxy
@
Double
)
testMatrix_01
)
,
testProperty
"14x14"
(
compareLogDistributional2
(
Proxy
@
Double
)
testMatrix_01
)
,
testProperty
"roundtrips"
(
compareLogDistributional2
(
Proxy
@
Double
))
,
testProperty
"roundtrips"
(
compareLogDistributional2
(
Proxy
@
Double
))
]
]
...
...
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