forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtf.math.cs
More file actions
59 lines (51 loc) · 1.68 KB
/
tf.math.cs
File metadata and controls
59 lines (51 loc) · 1.68 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Text;
namespace Tensorflow
{
public static partial class tf
{
public static Tensor add(Tensor a, Tensor b)
{
return gen_math_ops.add(a, b);
}
public static Tensor sub(Tensor a, Tensor b)
{
return gen_math_ops.sub(a, b);
}
public static Tensor multiply(Tensor x, Tensor y)
{
return gen_math_ops.mul(x, y);
}
public static Tensor pow(Tensor x, double y)
{
return gen_math_ops.pow(x, y);
}
/// <summary>
/// Computes the sum of elements across dimensions of a tensor.
/// </summary>
/// <param name="input"></param>
/// <param name="axis"></param>
/// <returns></returns>
public static Tensor reduce_sum(Tensor input, int[] axis = null)
{
Tensor rank;
string name;
using (var namescop = new ops.name_scope<Tensor>("", "Rank", new List<Tensor> { input }))
{
name = namescop;
rank = gen_array_ops.rank(input, namescop);
}
using (var namescope = new ops.name_scope<Tensor>("range", "Range", new List<Tensor> { 0D, input, 1D }))
{
name = namescope;
var start = ops.convert_to_tensor(0D);
var limit = ops.convert_to_tensor(input);
var delta = ops.convert_to_tensor(1D);
var t = gen_math_ops.range(start, limit, delta, name);
}
var s = gen_math_ops.sum(input, rank);
return s;
}
}
}