forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnp.tofile.cs
More file actions
28 lines (26 loc) · 1.04 KB
/
np.tofile.cs
File metadata and controls
28 lines (26 loc) · 1.04 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
using System.IO;
namespace NumSharp
{
public partial class NDArray
{
/// <summary>
/// Write array to a file as text or binary (default).<br></br>
/// Data is always written in ‘C’ order, independent of the order of a. <br></br>The data produced by this method can be recovered using the function fromfile().
/// </summary>
/// <param name="fid">An open file object, or a string containing a filename.</param>
/// <remarks>https://numpy.org/doc/stable/reference/generated/numpy.ndarray.tofile.html</remarks>
public void tofile(string fid)
{
//TODO! support for sliced data (if sliced, clone and then save)
unsafe
{
using (var fs = File.Open(fid, FileMode.OpenOrCreate))
using (var ums = new UnmanagedMemoryStream((byte*)this.Array.Address, this.Array.BytesLength))
{
fs.SetLength(0);
ums.CopyTo(fs);
}
}
}
}
}