Skip to content

Commit fcb223d

Browse files
committed
Matrices loading is optimized.
1 parent b400b84 commit fcb223d

1 file changed

Lines changed: 53 additions & 33 deletions

File tree

  • benchmarks/GraphBLAS-sharp.Benchmarks

benchmarks/GraphBLAS-sharp.Benchmarks/Utils.fs

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -93,46 +93,66 @@ module Utils =
9393
matrixFilename
9494
|]
9595

96+
let pack x y = (uint64 x <<< 32) ||| (uint64 y)
97+
let unpack x = (int ((x &&& 0xFFFFFFFF0000000UL) >>> 32)), (int (x &&& 0xFFFFFFFUL))
98+
9699
let makeCOO (mtx: MtxFormat) (valueProvider: ValueProvider<'a>) =
100+
printfn "Start make COO"
97101
mtx.Data
98-
|> List.map
99-
(fun line ->
100-
let value =
101-
match valueProvider with
102-
| FromUnit get -> get ()
103-
| FromString get -> get line.[2]
104-
105-
(int line.[0], int line.[1], value)
106-
)
107102
|> List.toArray
108-
|> Array.sortBy (fun (row, col, _) -> row, col)
109-
|> Array.unzip3
110-
|>
111-
fun (rows, cols, values) ->
112-
let c f x y = f y x
113-
let rows = rows |> Array.map (c (-) 1)
114-
let cols = cols |> Array.map (c (-) 1)
115-
printfn "kek"
116-
{
117-
Rows = rows
118-
Columns = cols
119-
Values = values
120-
RowCount = mtx.Shape.RowCount
121-
ColumnCount = mtx.Shape.ColumnCount
122-
}
103+
|> Array.Parallel.map
104+
(fun line ->
105+
let value =
106+
match valueProvider with
107+
| FromUnit get -> get ()
108+
| FromString get -> get line.[2]
109+
struct (pack (int line.[0]) (int line.[1]), value)
110+
)
111+
|> Array.sortBy (fun struct (p, _) -> p)
112+
|> fun data ->
113+
let rows = Array.zeroCreate data.Length
114+
let cols = Array.zeroCreate data.Length
115+
let values = Array.zeroCreate data.Length
116+
data
117+
|> Array.Parallel.iteri
118+
(fun i struct(p,v) ->
119+
let r,c = unpack p
120+
rows.[i] <- r
121+
cols.[i] <- c
122+
values.[i] <- v
123+
)
124+
let c f x y = f y x
125+
let rows = rows |> Array.map (c (-) 1)
126+
let cols = cols |> Array.map (c (-) 1)
127+
printfn "kek"
128+
{
129+
Rows = rows
130+
Columns = cols
131+
Values = values
132+
RowCount = mtx.Shape.RowCount
133+
ColumnCount = mtx.Shape.ColumnCount
134+
}
123135

124136
let transposeCOO (matrix: COOFormat<'a>) =
125-
(matrix.Rows, matrix.Columns, matrix.Values)
126-
|||> Array.zip3
127-
|> Array.sortBy (fun (row, col, value) -> col, row)
128-
|> Array.unzip3
137+
printfn "Start transpose COO"
138+
Array.map3 (fun c r v -> struct ((pack c r), v)) matrix.Columns matrix.Rows matrix.Values
139+
|> Array.sortBy (fun struct (p, value) -> p)
129140
|>
130-
fun (rows, cols, values) ->
131-
printfn "kek"
141+
fun data ->
142+
let rows = Array.zeroCreate data.Length
143+
let cols = Array.zeroCreate data.Length
144+
let values = Array.zeroCreate data.Length
145+
data
146+
|> Array.Parallel.iteri
147+
(fun i struct(p, v) ->
148+
let r,c = unpack p
149+
rows.[i] <- r
150+
cols.[i] <- c
151+
values.[i] <- v)
132152
{
133-
Rows = cols
134-
Columns = rows
153+
Rows = rows
154+
Columns = cols
135155
Values = values
136156
RowCount = matrix.ColumnCount
137157
ColumnCount = matrix.RowCount
138-
}
158+
}

0 commit comments

Comments
 (0)