forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNdArray.Eye.cs
More file actions
38 lines (32 loc) · 1.12 KB
/
NdArray.Eye.cs
File metadata and controls
38 lines (32 loc) · 1.12 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace NumSharp.Core
{
public partial class NDArray
{
public NDArray eye(int dim, int diagonalIndex = 0)
{
int noOfDiagElement = dim - Math.Abs(diagonalIndex);
NDArray puffer = null;
if((ndim == 1) && (dim != 1))
{
puffer = new NDArray(this.dtype, new Shape(dim, dim));
}
else
{
puffer = new NDArray(this.dtype,this.shape);
}
puffer.Storage.SetData(Array.CreateInstance(dtype,puffer.size));
if (diagonalIndex >= 0)
for(int idx = 0; idx < noOfDiagElement;idx++ )
puffer.Storage.SetData(1,idx,idx+diagonalIndex);
else
for(int idx = puffer.Storage.Shape.Dimensions[0]-1; idx > puffer.Storage.Shape.Dimensions[0]-1 - noOfDiagElement;idx-- )
puffer.Storage.SetData(1,idx,idx+diagonalIndex);
return puffer;
}
}
}