File tree Expand file tree Collapse file tree 5 files changed +46
-3
lines changed Expand file tree Collapse file tree 5 files changed +46
-3
lines changed Original file line number Diff line number Diff line change 2
2
using TorchSharp ;
3
3
4
4
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
+
5
12
public static void Main ( string [ ] args )
6
13
{
7
14
var x = new FloatTensor ( 10 ) ;
15
+ var b = new FloatTensor ( 10 ) ;
16
+ b . Fill ( 30 ) ;
17
+ Dump ( b ) ;
8
18
x . Random ( new THRandom ( ) , 10 ) ;
19
+ FloatTensor . Add ( x , 100 , b ) ;
20
+ Dump ( x ) ;
21
+ Dump ( b ) ;
22
+ #if false
9
23
24
+ Dump ( x ) ;
25
+ var y = x . Add ( 100 ) ;
26
+ Dump ( y ) ;
27
+ #endif
10
28
}
11
29
}
Original file line number Diff line number Diff line change 18
18
<ErrorReport >prompt</ErrorReport >
19
19
<WarningLevel >4</WarningLevel >
20
20
<ExternalConsole >true</ExternalConsole >
21
+ <PlatformTarget >x64</PlatformTarget >
21
22
</PropertyGroup >
22
23
<PropertyGroup Condition =" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " >
23
24
<Optimize >true</Optimize >
34
35
<Compile Include =" Properties\AssemblyInfo.cs" />
35
36
</ItemGroup >
36
37
<ItemGroup >
37
- <ProjectReference Include =" ..\TorchSharp.csproj" >
38
+ <ProjectReference Include =" ..\TorchSharp\TorchSharp .csproj" >
38
39
<Project >{E47E6785-B43B-49E9-A360-DB23B5E21C35}</Project >
39
40
<Name >TorchSharp</Name >
40
41
</ProjectReference >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Runtime . InteropServices ;
3
3
using Microsoft . Win32 . SafeHandles ;
4
- using HType = Microsoft . Win32 . SafeHandles . SafeHandleZeroOrMinusOneIsInvalid ;
4
+ using HType = TorchSharp . TorchHandle ;
5
5
using System . Text ;
6
6
7
7
namespace TorchSharp {
Original file line number Diff line number Diff line change 6
6
using System;
7
7
using System.Runtime.InteropServices;
8
8
using Microsoft.Win32.SafeHandles;
9
- using HType=Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid ;
9
+ using HType=TorchSharp.TorchHandle ;
10
10
using System.Text;
11
11
12
12
namespace TorchSharp {
You can’t perform that action at this time.
0 commit comments