File tree Expand file tree Collapse file tree
src/TensorFlowNET.Core/Variables Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /*****************************************************************************
2+ Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved.
3+
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+
8+ http://www.apache.org/licenses/LICENSE-2.0
9+
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+ ******************************************************************************/
16+
17+ using System ;
18+ using Tensorflow . Util ;
19+
20+ namespace Tensorflow . Variables
21+ {
22+ public sealed class SafeResourceVariableHandle : SafeTensorflowHandle
23+ {
24+ private SafeResourceVariableHandle ( )
25+ {
26+ }
27+
28+ public SafeResourceVariableHandle ( IntPtr handle )
29+ : base ( handle )
30+ {
31+ }
32+
33+ protected override bool ReleaseHandle ( )
34+ {
35+ c_api . TFE_DeleteResourceVariable ( handle ) ;
36+ SetHandle ( IntPtr . Zero ) ;
37+ return true ;
38+ }
39+ }
40+ }
Original file line number Diff line number Diff line change 11using System ;
2- using System . Collections . Generic ;
32using System . Runtime . InteropServices ;
4- using System . Text ;
3+ using Tensorflow . Variables ;
54
65namespace Tensorflow
76{
87 public partial class c_api
98 {
109 [ DllImport ( TensorFlowLibName ) ]
11- public static extern IntPtr TFE_NewResourceVariable ( ) ;
10+ public static extern SafeResourceVariableHandle TFE_NewResourceVariable ( ) ;
1211
1312 [ DllImport ( TensorFlowLibName ) ]
1413 public static extern void TFE_DeleteResourceVariable ( IntPtr variable ) ;
1514
1615 [ DllImport ( TensorFlowLibName ) ]
17- public static extern void TFE_SetResourceVariableHandle ( IntPtr variable , IntPtr tensor ) ;
16+ public static extern void TFE_SetResourceVariableHandle ( SafeResourceVariableHandle variable , IntPtr tensor ) ;
1817
1918 [ DllImport ( TensorFlowLibName ) ]
20- public static extern void TFE_SetResourceVariableName ( IntPtr variable , string name ) ;
19+ public static extern void TFE_SetResourceVariableName ( SafeResourceVariableHandle variable , string name ) ;
2120 }
2221}
You can’t perform that action at this time.
0 commit comments