forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnp.copyto.cs
More file actions
37 lines (33 loc) · 1.23 KB
/
np.copyto.cs
File metadata and controls
37 lines (33 loc) · 1.23 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
using System;
using NumSharp.Backends;
using NumSharp.Backends.Unmanaged;
namespace NumSharp
{
public static partial class np
{
/// <summary>
/// Copies values from one array to another, broadcasting as necessary.
/// </summary>
/// <param name="dst">The array into which values are copied.</param>
/// <param name="src">The array from which values are copied.</param>
/// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.copyto.html</remarks>
public static void copyto(NDArray dst, NDArray src) //todo! add where argument
{
if (dst == null)
throw new ArgumentNullException(nameof(dst));
if (src == null)
throw new ArgumentNullException(nameof(src));
//try to perform memory copy
if (dst.Shape.IsContiguous && src.Shape.IsContiguous && dst.dtype == src.dtype && src.size == dst.size)
{
unsafe
{
src.CopyTo(dst.Address);
return;
}
}
//perform manual copy with automatic casting
MultiIterator.Assign(dst.Storage, src.Storage);
}
}
}