forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspmatrix.cs
More file actions
40 lines (35 loc) · 1.03 KB
/
spmatrix.cs
File metadata and controls
40 lines (35 loc) · 1.03 KB
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
using NumSharp.Core;
using System;
using System.Collections.Generic;
using System.Text;
namespace NumSharp.Core.Sparse
{
public class spmatrix
{
public static matrix sum(_cs_matrix mx, int? axis = null, Type dtype = null)
{
var (m, n) = mx.shape.BiShape;
matrix ret = null;
// sum over columns
if (axis == 0)
{
var matrix = np.asmatrix(np.ones(new Shape(1, m), dtype));
ret = matrix * mx;
}
return ret;
}
public static void csc_matvec(int n_row, int n_col, int[] Ap, int[] Ai, double[] Ax, double[] Xx, NDArray Yx)
{
for (int j = 0; j < n_col; j++)
{
int col_start = Ap[j];
int col_end = Ap[j + 1];
for (int ii = col_start; ii < col_end; ii++)
{
int i = Ai[ii];
Yx.Data<double>()[i] += Ax[ii] * Xx[j];
}
}
}
}
}