1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Scalar dispatch trait for Inspector-Executor Sparse BLAS.
use core::ffi::c_int;
use num_complex::{Complex32, Complex64};
use onemkl_sys::{
self as sys, matrix_descr, sparse_index_base_t, sparse_layout_t, sparse_matrix_t,
sparse_operation_t, sparse_status_t,
};
use crate::scalar::Scalar;
/// Scalar types supported by the IE sparse BLAS.
///
/// Implemented for [`f32`], [`f64`], [`Complex32`], and [`Complex64`].
/// Methods are `unsafe` thunks that forward to the corresponding
/// `mkl_sparse_*` C symbol.
#[allow(missing_docs)]
pub trait SparseScalar: Scalar {
/// Raw `sparse_create_csr` call.
///
/// # Safety
///
/// `a` must be valid for a write of one `sparse_matrix_t`.
/// **Pointer retention:** MKL does NOT copy the index and value arrays; the handle stores these pointers. Every array passed here must therefore stay allocated, at a stable address, with unchanged index contents, and must not be mutably aliased by Rust references while MKL may read them, until `mkl_sparse_destroy` has been called on the created handle.
/// `indexing` must match how the index arrays are actually based (zero or one).
/// `rows_start` and `rows_end` must each hold `rows` entries (`rows_end[i]` is the exclusive end of row `i`); `col_indx` and `values` must each hold `rows_end[rows-1] - indexing` entries, with every column index in `[0, cols)` after removing the base.
/// The MKL library must be linked and usable. The returned status is MKL's; on a non-success status `*a` must not be used.
#[allow(clippy::too_many_arguments)]
unsafe fn sparse_create_csr(
a: *mut sparse_matrix_t,
indexing: sparse_index_base_t::Type,
rows: c_int,
cols: c_int,
rows_start: *mut c_int,
rows_end: *mut c_int,
col_indx: *mut c_int,
values: *mut Self,
) -> sparse_status_t::Type;
/// Raw `sparse_create_coo` call.
///
/// # Safety
///
/// `a` must be valid for a write of one `sparse_matrix_t`.
/// **Pointer retention:** MKL does NOT copy the index and value arrays; the handle stores these pointers. Every array passed here must therefore stay allocated, at a stable address, with unchanged index contents, and must not be mutably aliased by Rust references while MKL may read them, until `mkl_sparse_destroy` has been called on the created handle.
/// `indexing` must match how the index arrays are actually based (zero or one).
/// `row_indx`, `col_indx` and `values` must each hold `nnz` entries, with every row index in `[0, rows)` and column index in `[0, cols)` after removing the base.
/// The MKL library must be linked and usable. The returned status is MKL's; on a non-success status `*a` must not be used.
#[allow(clippy::too_many_arguments)]
unsafe fn sparse_create_coo(
a: *mut sparse_matrix_t,
indexing: sparse_index_base_t::Type,
rows: c_int,
cols: c_int,
nnz: c_int,
row_indx: *mut c_int,
col_indx: *mut c_int,
values: *mut Self,
) -> sparse_status_t::Type;
/// Raw `sparse_create_csc` call.
///
/// # Safety
///
/// `a` must be valid for a write of one `sparse_matrix_t`.
/// **Pointer retention:** MKL does NOT copy the index and value arrays; the handle stores these pointers. Every array passed here must therefore stay allocated, at a stable address, with unchanged index contents, and must not be mutably aliased by Rust references while MKL may read them, until `mkl_sparse_destroy` has been called on the created handle.
/// `indexing` must match how the index arrays are actually based (zero or one).
/// `cols_start` and `cols_end` must each hold `cols` entries; `row_indx` and `values` must each hold `cols_end[cols-1] - indexing` entries, with every row index in `[0, rows)` after removing the base.
/// The MKL library must be linked and usable. The returned status is MKL's; on a non-success status `*a` must not be used.
#[allow(clippy::too_many_arguments)]
unsafe fn sparse_create_csc(
a: *mut sparse_matrix_t,
indexing: sparse_index_base_t::Type,
rows: c_int,
cols: c_int,
cols_start: *mut c_int,
cols_end: *mut c_int,
row_indx: *mut c_int,
values: *mut Self,
) -> sparse_status_t::Type;
/// Raw `sparse_create_bsr` call.
///
/// # Safety
///
/// `a` must be valid for a write of one `sparse_matrix_t`.
/// **Pointer retention:** MKL does NOT copy the index and value arrays; the handle stores these pointers. Every array passed here must therefore stay allocated, at a stable address, with unchanged index contents, and must not be mutably aliased by Rust references while MKL may read them, until `mkl_sparse_destroy` has been called on the created handle.
/// `indexing` must match how the index arrays are actually based (zero or one).
/// `rows` and `cols` count blocks, not scalar rows/columns; `block_size` is the square block edge and `block_layout` the in-block storage order. `rows_start` and `rows_end` must each hold `rows` entries; `col_indx` must hold one entry per stored block and `values` `block_size * block_size` entries per stored block.
/// The MKL library must be linked and usable. The returned status is MKL's; on a non-success status `*a` must not be used.
#[allow(clippy::too_many_arguments)]
unsafe fn sparse_create_bsr(
a: *mut sparse_matrix_t,
indexing: sparse_index_base_t::Type,
block_layout: onemkl_sys::sparse_layout_t::Type,
rows: c_int,
cols: c_int,
block_size: c_int,
rows_start: *mut c_int,
rows_end: *mut c_int,
col_indx: *mut c_int,
values: *mut Self,
) -> sparse_status_t::Type;
/// Raw `sparse_mv` call.
///
/// # Safety
///
/// `a` must be a live handle created by one of the `sparse_create_*` calls (or produced by MKL) and not yet destroyed; `descr` must describe its structure (type, fill mode, diagonal).
/// `x` must be valid for reads of `cols(op(A))` elements and `y` for reads (when `beta != 0`) and writes of `rows(op(A))` elements, where `op(A)` is `A` for the non-transpose operation and `A^T`/`A^H` otherwise. `x` and `y` must not overlap.
/// The MKL library must be linked and usable. The returned status is MKL's; on a non-success status `*a` must not be used.
unsafe fn sparse_mv(
op: sparse_operation_t::Type,
alpha: Self,
a: sparse_matrix_t,
descr: matrix_descr,
x: *const Self,
beta: Self,
y: *mut Self,
) -> sparse_status_t::Type;
/// Raw `sparse_mm` call.
///
/// # Safety
///
/// `a` must be a live handle created by one of the `sparse_create_*` calls and not yet destroyed; `descr` must describe its structure.
/// `x` is a dense matrix of `cols(op(A))` rows by `columns` columns and `y` one of `rows(op(A))` rows by `columns` columns, both stored per `layout` (row-major: leading dimension is the row stride and must be `>= columns`; column-major: it is the column stride and must be `>=` the row count). `x` must be valid for reads of the whole strided extent, `y` for reads (when `beta != 0`) and writes. `x` and `y` must not overlap.
/// The MKL library must be linked and usable. The returned status is MKL's; on a non-success status `*a` must not be used.
#[allow(clippy::too_many_arguments)]
unsafe fn sparse_mm(
op: sparse_operation_t::Type,
alpha: Self,
a: sparse_matrix_t,
descr: matrix_descr,
layout: sparse_layout_t::Type,
x: *const Self,
columns: c_int,
ldx: c_int,
beta: Self,
y: *mut Self,
ldy: c_int,
) -> sparse_status_t::Type;
/// Raw `sparse_trsv` call.
///
/// # Safety
///
/// `a` must be a live, square handle created by one of the `sparse_create_*` calls and not yet destroyed; `descr` must describe it as triangular (with fill mode and diagonal kind) and the diagonal must be non-singular as MKL requires.
/// `x` must be valid for reads and `y` for writes of `n` elements, where `n` is the order of `A`; `x` and `y` must not partially overlap (do not assume in-place solve is supported).
/// The MKL library must be linked and usable. The returned status is MKL's; on a non-success status `*a` must not be used.
unsafe fn sparse_trsv(
op: sparse_operation_t::Type,
alpha: Self,
a: sparse_matrix_t,
descr: matrix_descr,
x: *const Self,
y: *mut Self,
) -> sparse_status_t::Type;
/// Raw `sparse_add` call.
///
/// # Safety
///
/// `a` and `b` must be live handles of identical dimensions, created by `sparse_create_*` or by MKL, and not yet destroyed. `c` must be valid for a write of one `sparse_matrix_t`.
/// On success `*c` is a new handle owned by the caller, who must release it with `mkl_sparse_destroy`; it may reference data owned by `a` and `b`, so neither source nor their backing arrays may be freed first.
/// The MKL library must be linked and usable. The returned status is MKL's; on a non-success status `*a` must not be used.
unsafe fn sparse_add(
op: sparse_operation_t::Type,
a: sparse_matrix_t,
alpha: Self,
b: sparse_matrix_t,
c: *mut sparse_matrix_t,
) -> sparse_status_t::Type;
/// Raw `sparse_dotmv` call.
///
/// # Safety
///
/// `a` must be a live, square handle created by `sparse_create_*` and not yet destroyed; `descr` must describe it.
/// `x` must be valid for reads of `cols(op(A))` elements and `y` for reads (when `beta != 0`) and writes of `rows(op(A))` elements; `d` must be valid for a write of exactly one `Self` (the dot product `x . y`). `x`, `y` and `d` must not overlap.
/// The MKL library must be linked and usable. The returned status is MKL's; on a non-success status `*a` must not be used.
#[allow(clippy::too_many_arguments)]
unsafe fn sparse_dotmv(
op: sparse_operation_t::Type,
alpha: Self,
a: sparse_matrix_t,
descr: matrix_descr,
x: *const Self,
beta: Self,
y: *mut Self,
d: *mut Self,
) -> sparse_status_t::Type;
/// Raw `sparse_symgs` call.
///
/// # Safety
///
/// `a` must be a live, square, symmetric-described handle (`descr` fill mode and diagonal set) created by `sparse_create_*` and not yet destroyed.
/// `b` must be valid for reads and `x` for reads and writes of `n` elements, where `n` is the order of `A`; `x` carries the initial guess in and the updated iterate out. `b` and `x` must not overlap.
/// The MKL library must be linked and usable. The returned status is MKL's; on a non-success status `*a` must not be used.
unsafe fn sparse_symgs(
op: sparse_operation_t::Type,
a: sparse_matrix_t,
descr: matrix_descr,
alpha: Self,
b: *const Self,
x: *mut Self,
) -> sparse_status_t::Type;
/// Raw `sparse_symgs_mv` call.
///
/// # Safety
///
/// `a` must be a live, square, symmetric-described handle created by `sparse_create_*` and not yet destroyed.
/// `b` must be valid for reads, and `x` and `y` for writes (`x` also read as the initial guess), of `n` elements, where `n` is the order of `A`; `y` receives `A * x`. `b`, `x` and `y` must not overlap.
/// The MKL library must be linked and usable. The returned status is MKL's; on a non-success status `*a` must not be used.
#[allow(clippy::too_many_arguments)]
unsafe fn sparse_symgs_mv(
op: sparse_operation_t::Type,
a: sparse_matrix_t,
descr: matrix_descr,
alpha: Self,
b: *const Self,
x: *mut Self,
y: *mut Self,
) -> sparse_status_t::Type;
/// Raw `sparse_spmmd` call.
///
/// # Safety
///
/// `a` and `b` must be live handles whose dimensions make `op(A) * B` defined, created by `sparse_create_*` and not yet destroyed.
/// `c` must be valid for writes of the dense `rows(op(A)) x cols(B)` result stored per `layout`: row-major needs `ldc >= cols(B)` and `rows(op(A)) * ldc` elements; column-major needs `ldc >= rows(op(A))` and `cols(B) * ldc` elements. `c` must not overlap any storage owned by `a` or `b`.
/// The MKL library must be linked and usable. The returned status is MKL's; on a non-success status `*a` must not be used.
#[allow(clippy::too_many_arguments)]
unsafe fn sparse_spmmd(
op: sparse_operation_t::Type,
a: sparse_matrix_t,
b: sparse_matrix_t,
layout: onemkl_sys::sparse_layout_t::Type,
c: *mut Self,
ldc: c_int,
) -> sparse_status_t::Type;
}
macro_rules! impl_sparse_real {
($ty:ty,
create_csr=$create:ident, create_coo=$create_coo:ident,
create_csc=$create_csc:ident, create_bsr=$create_bsr:ident,
mv=$mv:ident, mm=$mm:ident, trsv=$trsv:ident,
add=$add:ident, spmmd=$spmmd:ident,
dotmv=$dotmv:ident, symgs=$symgs:ident, symgs_mv=$symgs_mv:ident,
) => {
impl SparseScalar for $ty {
unsafe fn sparse_create_csr(
a: *mut sparse_matrix_t,
indexing: sparse_index_base_t::Type,
rows: c_int,
cols: c_int,
rows_start: *mut c_int,
rows_end: *mut c_int,
col_indx: *mut c_int,
values: *mut Self,
) -> sparse_status_t::Type {
unsafe {
sys::$create(
a, indexing, rows, cols, rows_start, rows_end, col_indx, values,
)
}
}
unsafe fn sparse_create_coo(
a: *mut sparse_matrix_t,
indexing: sparse_index_base_t::Type,
rows: c_int,
cols: c_int,
nnz: c_int,
row_indx: *mut c_int,
col_indx: *mut c_int,
values: *mut Self,
) -> sparse_status_t::Type {
unsafe {
sys::$create_coo(a, indexing, rows, cols, nnz, row_indx, col_indx, values)
}
}
unsafe fn sparse_create_csc(
a: *mut sparse_matrix_t,
indexing: sparse_index_base_t::Type,
rows: c_int,
cols: c_int,
cols_start: *mut c_int,
cols_end: *mut c_int,
row_indx: *mut c_int,
values: *mut Self,
) -> sparse_status_t::Type {
unsafe {
sys::$create_csc(
a, indexing, rows, cols, cols_start, cols_end, row_indx, values,
)
}
}
unsafe fn sparse_create_bsr(
a: *mut sparse_matrix_t,
indexing: sparse_index_base_t::Type,
block_layout: onemkl_sys::sparse_layout_t::Type,
rows: c_int,
cols: c_int,
block_size: c_int,
rows_start: *mut c_int,
rows_end: *mut c_int,
col_indx: *mut c_int,
values: *mut Self,
) -> sparse_status_t::Type {
unsafe {
sys::$create_bsr(
a,
indexing,
block_layout,
rows,
cols,
block_size,
rows_start,
rows_end,
col_indx,
values,
)
}
}
unsafe fn sparse_mv(
op: sparse_operation_t::Type,
alpha: Self,
a: sparse_matrix_t,
descr: matrix_descr,
x: *const Self,
beta: Self,
y: *mut Self,
) -> sparse_status_t::Type {
unsafe { sys::$mv(op, alpha, a, descr, x, beta, y) }
}
unsafe fn sparse_mm(
op: sparse_operation_t::Type,
alpha: Self,
a: sparse_matrix_t,
descr: matrix_descr,
layout: sparse_layout_t::Type,
x: *const Self,
columns: c_int,
ldx: c_int,
beta: Self,
y: *mut Self,
ldy: c_int,
) -> sparse_status_t::Type {
unsafe { sys::$mm(op, alpha, a, descr, layout, x, columns, ldx, beta, y, ldy) }
}
unsafe fn sparse_trsv(
op: sparse_operation_t::Type,
alpha: Self,
a: sparse_matrix_t,
descr: matrix_descr,
x: *const Self,
y: *mut Self,
) -> sparse_status_t::Type {
unsafe { sys::$trsv(op, alpha, a, descr, x, y) }
}
unsafe fn sparse_add(
op: sparse_operation_t::Type,
a: sparse_matrix_t,
alpha: Self,
b: sparse_matrix_t,
c: *mut sparse_matrix_t,
) -> sparse_status_t::Type {
unsafe { sys::$add(op, a, alpha, b, c) }
}
unsafe fn sparse_spmmd(
op: sparse_operation_t::Type,
a: sparse_matrix_t,
b: sparse_matrix_t,
layout: onemkl_sys::sparse_layout_t::Type,
c: *mut Self,
ldc: c_int,
) -> sparse_status_t::Type {
unsafe { sys::$spmmd(op, a, b, layout, c, ldc) }
}
unsafe fn sparse_dotmv(
op: sparse_operation_t::Type,
alpha: Self,
a: sparse_matrix_t,
descr: matrix_descr,
x: *const Self,
beta: Self,
y: *mut Self,
d: *mut Self,
) -> sparse_status_t::Type {
unsafe { sys::$dotmv(op, alpha, a, descr, x, beta, y, d) }
}
unsafe fn sparse_symgs(
op: sparse_operation_t::Type,
a: sparse_matrix_t,
descr: matrix_descr,
alpha: Self,
b: *const Self,
x: *mut Self,
) -> sparse_status_t::Type {
unsafe { sys::$symgs(op, a, descr, alpha, b, x) }
}
unsafe fn sparse_symgs_mv(
op: sparse_operation_t::Type,
a: sparse_matrix_t,
descr: matrix_descr,
alpha: Self,
b: *const Self,
x: *mut Self,
y: *mut Self,
) -> sparse_status_t::Type {
unsafe { sys::$symgs_mv(op, a, descr, alpha, b, x, y) }
}
}
};
}
impl_sparse_real!(
f32,
create_csr = mkl_sparse_s_create_csr,
create_coo = mkl_sparse_s_create_coo,
create_csc = mkl_sparse_s_create_csc,
create_bsr = mkl_sparse_s_create_bsr,
mv = mkl_sparse_s_mv,
mm = mkl_sparse_s_mm,
trsv = mkl_sparse_s_trsv,
add = mkl_sparse_s_add,
spmmd = mkl_sparse_s_spmmd,
dotmv = mkl_sparse_s_dotmv,
symgs = mkl_sparse_s_symgs,
symgs_mv = mkl_sparse_s_symgs_mv,
);
impl_sparse_real!(
f64,
create_csr = mkl_sparse_d_create_csr,
create_coo = mkl_sparse_d_create_coo,
create_csc = mkl_sparse_d_create_csc,
create_bsr = mkl_sparse_d_create_bsr,
mv = mkl_sparse_d_mv,
mm = mkl_sparse_d_mm,
trsv = mkl_sparse_d_trsv,
add = mkl_sparse_d_add,
spmmd = mkl_sparse_d_spmmd,
dotmv = mkl_sparse_d_dotmv,
symgs = mkl_sparse_d_symgs,
symgs_mv = mkl_sparse_d_symgs_mv,
);
macro_rules! impl_sparse_complex {
($ty:ty,
create_csr=$create:ident, create_coo=$create_coo:ident,
create_csc=$create_csc:ident, create_bsr=$create_bsr:ident,
mv=$mv:ident, mm=$mm:ident, trsv=$trsv:ident,
add=$add:ident, spmmd=$spmmd:ident,
dotmv=$dotmv:ident, symgs=$symgs:ident, symgs_mv=$symgs_mv:ident,
) => {
impl SparseScalar for $ty {
unsafe fn sparse_create_csr(
a: *mut sparse_matrix_t,
indexing: sparse_index_base_t::Type,
rows: c_int,
cols: c_int,
rows_start: *mut c_int,
rows_end: *mut c_int,
col_indx: *mut c_int,
values: *mut Self,
) -> sparse_status_t::Type {
unsafe {
sys::$create(
a,
indexing,
rows,
cols,
rows_start,
rows_end,
col_indx,
values.cast(),
)
}
}
unsafe fn sparse_create_coo(
a: *mut sparse_matrix_t,
indexing: sparse_index_base_t::Type,
rows: c_int,
cols: c_int,
nnz: c_int,
row_indx: *mut c_int,
col_indx: *mut c_int,
values: *mut Self,
) -> sparse_status_t::Type {
unsafe {
sys::$create_coo(
a,
indexing,
rows,
cols,
nnz,
row_indx,
col_indx,
values.cast(),
)
}
}
unsafe fn sparse_create_csc(
a: *mut sparse_matrix_t,
indexing: sparse_index_base_t::Type,
rows: c_int,
cols: c_int,
cols_start: *mut c_int,
cols_end: *mut c_int,
row_indx: *mut c_int,
values: *mut Self,
) -> sparse_status_t::Type {
unsafe {
sys::$create_csc(
a,
indexing,
rows,
cols,
cols_start,
cols_end,
row_indx,
values.cast(),
)
}
}
unsafe fn sparse_create_bsr(
a: *mut sparse_matrix_t,
indexing: sparse_index_base_t::Type,
block_layout: onemkl_sys::sparse_layout_t::Type,
rows: c_int,
cols: c_int,
block_size: c_int,
rows_start: *mut c_int,
rows_end: *mut c_int,
col_indx: *mut c_int,
values: *mut Self,
) -> sparse_status_t::Type {
unsafe {
sys::$create_bsr(
a,
indexing,
block_layout,
rows,
cols,
block_size,
rows_start,
rows_end,
col_indx,
values.cast(),
)
}
}
unsafe fn sparse_mv(
op: sparse_operation_t::Type,
alpha: Self,
a: sparse_matrix_t,
descr: matrix_descr,
x: *const Self,
beta: Self,
y: *mut Self,
) -> sparse_status_t::Type {
unsafe {
sys::$mv(
op,
core::mem::transmute_copy(&alpha),
a,
descr,
x.cast(),
core::mem::transmute_copy(&beta),
y.cast(),
)
}
}
unsafe fn sparse_mm(
op: sparse_operation_t::Type,
alpha: Self,
a: sparse_matrix_t,
descr: matrix_descr,
layout: sparse_layout_t::Type,
x: *const Self,
columns: c_int,
ldx: c_int,
beta: Self,
y: *mut Self,
ldy: c_int,
) -> sparse_status_t::Type {
unsafe {
sys::$mm(
op,
core::mem::transmute_copy(&alpha),
a,
descr,
layout,
x.cast(),
columns,
ldx,
core::mem::transmute_copy(&beta),
y.cast(),
ldy,
)
}
}
unsafe fn sparse_trsv(
op: sparse_operation_t::Type,
alpha: Self,
a: sparse_matrix_t,
descr: matrix_descr,
x: *const Self,
y: *mut Self,
) -> sparse_status_t::Type {
unsafe {
sys::$trsv(
op,
core::mem::transmute_copy(&alpha),
a,
descr,
x.cast(),
y.cast(),
)
}
}
unsafe fn sparse_add(
op: sparse_operation_t::Type,
a: sparse_matrix_t,
alpha: Self,
b: sparse_matrix_t,
c: *mut sparse_matrix_t,
) -> sparse_status_t::Type {
unsafe { sys::$add(op, a, core::mem::transmute_copy(&alpha), b, c) }
}
unsafe fn sparse_spmmd(
op: sparse_operation_t::Type,
a: sparse_matrix_t,
b: sparse_matrix_t,
layout: onemkl_sys::sparse_layout_t::Type,
c: *mut Self,
ldc: c_int,
) -> sparse_status_t::Type {
unsafe { sys::$spmmd(op, a, b, layout, c.cast(), ldc) }
}
unsafe fn sparse_dotmv(
op: sparse_operation_t::Type,
alpha: Self,
a: sparse_matrix_t,
descr: matrix_descr,
x: *const Self,
beta: Self,
y: *mut Self,
d: *mut Self,
) -> sparse_status_t::Type {
unsafe {
sys::$dotmv(
op,
core::mem::transmute_copy(&alpha),
a,
descr,
x.cast(),
core::mem::transmute_copy(&beta),
y.cast(),
d.cast(),
)
}
}
unsafe fn sparse_symgs(
op: sparse_operation_t::Type,
a: sparse_matrix_t,
descr: matrix_descr,
alpha: Self,
b: *const Self,
x: *mut Self,
) -> sparse_status_t::Type {
unsafe {
sys::$symgs(
op,
a,
descr,
core::mem::transmute_copy(&alpha),
b.cast(),
x.cast(),
)
}
}
unsafe fn sparse_symgs_mv(
op: sparse_operation_t::Type,
a: sparse_matrix_t,
descr: matrix_descr,
alpha: Self,
b: *const Self,
x: *mut Self,
y: *mut Self,
) -> sparse_status_t::Type {
unsafe {
sys::$symgs_mv(
op,
a,
descr,
core::mem::transmute_copy(&alpha),
b.cast(),
x.cast(),
y.cast(),
)
}
}
}
};
}
impl_sparse_complex!(
Complex32,
create_csr = mkl_sparse_c_create_csr,
create_coo = mkl_sparse_c_create_coo,
create_csc = mkl_sparse_c_create_csc,
create_bsr = mkl_sparse_c_create_bsr,
mv = mkl_sparse_c_mv,
mm = mkl_sparse_c_mm,
trsv = mkl_sparse_c_trsv,
add = mkl_sparse_c_add,
spmmd = mkl_sparse_c_spmmd,
dotmv = mkl_sparse_c_dotmv,
symgs = mkl_sparse_c_symgs,
symgs_mv = mkl_sparse_c_symgs_mv,
);
impl_sparse_complex!(
Complex64,
create_csr = mkl_sparse_z_create_csr,
create_coo = mkl_sparse_z_create_coo,
create_csc = mkl_sparse_z_create_csc,
create_bsr = mkl_sparse_z_create_bsr,
mv = mkl_sparse_z_mv,
mm = mkl_sparse_z_mm,
trsv = mkl_sparse_z_trsv,
add = mkl_sparse_z_add,
spmmd = mkl_sparse_z_spmmd,
dotmv = mkl_sparse_z_dotmv,
symgs = mkl_sparse_z_symgs,
symgs_mv = mkl_sparse_z_symgs_mv,
);