forked from SciSharp/Tensor.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicFunctionGenerator.cs
More file actions
24 lines (23 loc) · 1017 Bytes
/
Copy pathBasicFunctionGenerator.cs
File metadata and controls
24 lines (23 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System.Text;
using System.Collections.Generic;
namespace CodeGenerator{
public class BasicFunctionGenerator{
public string Name{ get; set; }
public string Expr{ get; set; }
public List<string> Parameters{ get; set; }
private List<string> _types= new List<string>(new string[]{ "double", "float", "long", "int", "bool" });
private string _targetType = null;
public string GetCode(){
StringBuilder builder = new StringBuilder();
foreach(var typeInp in _types){
string typeRes = _targetType??typeInp;
builder.Append(@"
public static Tensor<" + typeRes + $"> {Name}(this Tensor<" + typeInp + @"> inp" + (Parameters is null ? "": ", ") +
(Parameters is null ? "": string.Join(',', Parameters)) + @"){
return OnElemOperation.Execute<" + $"{typeInp}, {typeRes}" + $">(inp, x => {Expr});" + @"
}");
}
return builder.ToString();
}
}
}