-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathFill.cs
More file actions
45 lines (43 loc) · 1.87 KB
/
Copy pathFill.cs
File metadata and controls
45 lines (43 loc) · 1.87 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
41
42
43
44
45
using Tensornet.Common;
using Tensornet.Native;
using Tensornet.Exceptions;
using Tensornet.Native.Param;
namespace Tensornet{
public static class FillExtension{
/// <summary>
/// Fill the tensor with the given value.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="src"></param>
/// <param name="value"> The value to be filled in the tensor. </param>
public static void Fill<T>(this Tensor<T> src, T value) where T : struct, IEquatable<T>, IConvertible
{
FillParam param = new FillParam() { value = Convert.ToDouble(value) };
FillInternal<T>(src, value);
}
private unsafe static void FillInternal<T>(Tensor<T> src, T value) where T : struct, IEquatable<T>, IConvertible{
FillParam param = new FillParam() { value = Convert.ToDouble(value) };
IntPtr status = NativeExecutor.Execute(NativeApi.Fill, src.TMemory, src.TLayout, new IntPtr(¶m), Tensor<T>.Provider);
NativeStatus.AssertOK(status);
}
public static Tensor<TResult> FillLike<TResult, TRefer>(Tensor<TRefer> tensor, TResult value)
where TResult : struct, IConvertible, IEquatable<TResult>
where TRefer : struct, IConvertible, IEquatable<TRefer>{
Tensor<TResult> res = new Tensor<TResult>(tensor.TLayout);
res.Fill(value);
return res;
}
}
public static partial class Tensor{
/// <summary>
/// Fill the tensor with the given value.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="src"></param>
/// <param name="value"> The value to be filled in the tensor. </param>
public static void Fill<T>(Tensor<T> src, T value) where T : struct, IEquatable<T>, IConvertible
{
src.Fill(value);
}
}
}