Skip to content

Commit dc65023

Browse files
committed
Update
1 parent 2ef6f71 commit dc65023

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

Tester/Program.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,28 @@
22
using TorchSharp;
33

44
class MainClass {
5+
static void Dump (FloatTensor x)
6+
{
7+
for (int i = 0; i < x.GetTensorDimension (0); i++)
8+
Console.Write ($"{x [i]}, ");
9+
Console.WriteLine ();
10+
}
11+
512
public static void Main (string [] args)
613
{
714
var x = new FloatTensor (10);
15+
var b = new FloatTensor (10);
16+
b.Fill (30);
17+
Dump (b);
818
x.Random (new THRandom (), 10);
19+
FloatTensor.Add (x, 100, b);
20+
Dump (x);
21+
Dump (b);
22+
#if false
923

24+
Dump (x);
25+
var y = x.Add (100);
26+
Dump (y);
27+
#endif
1028
}
1129
}

Tester/Tester.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<ErrorReport>prompt</ErrorReport>
1919
<WarningLevel>4</WarningLevel>
2020
<ExternalConsole>true</ExternalConsole>
21+
<PlatformTarget>x64</PlatformTarget>
2122
</PropertyGroup>
2223
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2324
<Optimize>true</Optimize>
@@ -34,7 +35,7 @@
3435
<Compile Include="Properties\AssemblyInfo.cs" />
3536
</ItemGroup>
3637
<ItemGroup>
37-
<ProjectReference Include="..\TorchSharp.csproj">
38+
<ProjectReference Include="..\TorchSharp\TorchSharp.csproj">
3839
<Project>{E47E6785-B43B-49E9-A360-DB23B5E21C35}</Project>
3940
<Name>TorchSharp</Name>
4041
</ProjectReference>

TorchSharp/Handle.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.Win32.SafeHandles;
2+
using System;
3+
4+
namespace TorchSharp {
5+
public sealed class TorchHandle : SafeHandleZeroOrMinusOneIsInvalid {
6+
public TorchHandle (IntPtr preexistingHandle, bool ownsHandle) : base (ownsHandle)
7+
{
8+
SetHandle (preexistingHandle);
9+
}
10+
11+
// This is just for marshalling
12+
internal TorchHandle () : base (true)
13+
{
14+
}
15+
16+
protected override bool ReleaseHandle ()
17+
{
18+
// ouch.
19+
// Will likely need to abandon this attempt.
20+
return true;
21+
}
22+
23+
}
24+
}

TorchSharp/TypeGeneration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Runtime.InteropServices;
33
using Microsoft.Win32.SafeHandles;
4-
using HType=Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid;
4+
using HType=TorchSharp.TorchHandle;
55
using System.Text;
66

77
namespace TorchSharp {

TorchSharp/TypeGeneration.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System;
77
using System.Runtime.InteropServices;
88
using Microsoft.Win32.SafeHandles;
9-
using HType=Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid;
9+
using HType=TorchSharp.TorchHandle;
1010
using System.Text;
1111

1212
namespace TorchSharp {

0 commit comments

Comments
 (0)