-
Notifications
You must be signed in to change notification settings - Fork 0
/
SourceCodeGeneration.cs
66 lines (50 loc) · 1.65 KB
/
SourceCodeGeneration.cs
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
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace MkFn {
public partial class MkFn {
/*
添え字から配列の先頭からのオフセットの計算式を得ます。
*/
public static string OffsetFromIndexes(Reference rf) {
if (!IsNew(rf.VarRef.Domain)) {
// 変数の定義域がない場合
throw new Exception();
}
// 対象の変数参照をコピーします。
rf = rf.Clone();
// 変数の定義域をコピーします。
Apply domain = (rf.VarRef.Domain as Apply).Clone();
Term t = rf.Indexes[0];
for (int dim = 1; dim < rf.Indexes.Length; dim++) {
t = Add(Mul(domain.Args[dim], t), rf.Indexes[dim]);
}
string idx = t.Code();
if (rf.VarRef.Kind == FieldKind.CalculatedField) {
if (OutputLanguage == Language.CUDA) {
idx = "(" + idx + ") * _BatchSize + _batch_idx";
}
else {
idx = "(" + idx + ") * BatchSize + _batch_idx";
}
}
return idx;
}
/*
バッチ
配列のアクセス
検証
CalculatedField
単一
複数
ParameterField
単一
複数
レイヤー
単一
複数
*/
}
}