Skip to content

Commit 08f0364

Browse files
author
dotchris90
committed
Style : element wise operations by T4 template
1 parent b69fcd1 commit 08f0364

File tree

6 files changed

+1023
-466
lines changed

6 files changed

+1023
-466
lines changed

GenerateCode.ps1

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,75 @@ else
1010
Write-Host "T4 tool is already installed."
1111
}
1212

13-
Write-Host ("location of T4 tool is : " + (Get-Command t4).Path)
13+
Write-Host ("location of T4 tool is : " + (Get-Command t4).Path);
14+
Write-Host "----------------------------------------------------"
15+
Write-Host "----------------------------------------------------"
16+
Write-Host ("Test T4 before using it.");
17+
18+
# set variables
19+
$projectFolders = @{};
20+
$projectFolders['projectRoot'] = $PSScriptRoot;
21+
$projectFolders['tmp'] = $projectFolders['projectRoot'] + '/tmp_' + [System.Guid]::NewGuid();
22+
$projectFolders['tt.elementwise'] = $projectFolders['projectRoot'] + "/src/NumSharp.Core/Operations/NdArray.ElementsWise.tt";
23+
24+
Write-Host ("new tmp folder at " + $projectFolders["tmp"])
25+
26+
$projectFolders['tmp.tt'] = $projectFolders['tmp'] + '/test.tt';
27+
$projectFolders['tmp.html'] = $projectFolders['tmp'] + '/date.html';
28+
29+
New-Item -ItemType Directory -Path $projectFolders['tmp'];
30+
31+
'<html><body>' > $projectFolders['tmp.tt'];
32+
'The date and time now is: <#= DateTime.Now #>' >> $projectFolders['tmp.tt'];
33+
'</body></html>' >> $projectFolders['tmp.tt'];
34+
35+
Write-Host "";
36+
Write-Host ("folder " + $projectFolders["tmp"] + " was created.");
37+
Write-Host "";
38+
39+
t4 -o $projectFolders['tmp.html'] $projectFolders['tmp.tt']
40+
41+
if (Test-Path -Path ($projectFolders['tmp.html']))
42+
{
43+
Write-Host "html doc exist - was generated from tt."
44+
Write-Host "Everything should be fine..."
45+
}
46+
47+
Write-Host ""
48+
Write-Host "Tidy up now."
49+
Write-Host ""
50+
51+
Remove-Item -Recurse -Path $projectFolders["tmp"]
52+
53+
Write-Host "Start true Code-Generation.";
54+
Write-Host "";
55+
Write-Host "Generate element wise operations + , - , * , /";
56+
Write-Host "";
57+
58+
$supportDataType = New-Object 'System.Collections.Generic.List[System.String]';
59+
60+
$supportDataType.Add('System.Int32');
61+
$supportDataType.Add('System.Int64');
62+
$supportDataType.Add('System.Single');
63+
$supportDataType.Add('System.Double');
64+
$supportDataType.Add('System.Numerics.Complex');
65+
$supportDataType.Add('System.Numerics.Quaternion');
66+
67+
68+
$operationTypeString = [System.String]::Join(';',$supportDataType);
69+
70+
$command = "t4 -o - -p:operationName='+' -p:operationTypesString='" + $operationTypeString + "' " + $projectFolders['tt.elementwise'] + " > " + $projectFolders['projectRoot'] + "\src\NumSharp.Core\Operations\Elementwise\NdArray.Addition.cs";
71+
Write-Host ("execute - " + $command);
72+
Invoke-Expression $command;
73+
74+
$command = "t4 -o - -p:operationName='*' -p:operationTypesString='" + $operationTypeString + "' " + $projectFolders['tt.elementwise'] + " > " + $projectFolders['projectRoot'] + "\src\NumSharp.Core\Operations\Elementwise\NdArray.Multiplication.cs";
75+
Write-Host ("execute - " + $command);
76+
Invoke-Expression $command;
77+
78+
$command = "t4 -o - -p:operationName='/' -p:operationTypesString='" + $operationTypeString + "' " + $projectFolders['tt.elementwise'] + " > " + $projectFolders['projectRoot'] + "\src\NumSharp.Core\Operations\Elementwise\NdArray.Division.cs";
79+
Write-Host ("execute - " + $command);
80+
Invoke-Expression $command;
81+
82+
$command = "t4 -o - -p:operationName='-' -p:operationTypesString='" + $operationTypeString + "' " + $projectFolders['tt.elementwise'] + " > " + $projectFolders['projectRoot'] + "\src\NumSharp.Core\Operations\Elementwise\NdArray.Substraction.cs";
83+
Write-Host ("execute - " + $command);
84+
Invoke-Expression $command;

0 commit comments

Comments
 (0)