Skip to content

Commit b105668

Browse files
committed
1.6 APIs
1 parent a68a42a commit b105668

File tree

9 files changed

+124
-11
lines changed

9 files changed

+124
-11
lines changed

TensorFlowSharp/Tensorflow.cs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public class TFStatus : TFDisposable
243243
/// <summary>
244244
/// Initializes a new instance of the <see cref="T:TensorFlow.TFStatus"/> class.
245245
/// </summary>
246-
public TFStatus () : base (TF_NewStatus ())
246+
public TFStatus () : base (TF_NewStatus ())
247247
{
248248
}
249249

@@ -1191,6 +1191,49 @@ public void Versions (TFBuffer outputVersionDef, TFStatus status = null)
11911191
}
11921192
cstatus.CheckMaybeRaise (status);
11931193
}
1194+
1195+
[DllImport (NativeBinding.TensorFlowLibrary)]
1196+
unsafe extern static int TF_GraphNumFunctions (TF_Graph graph);
1197+
1198+
/// <summary>
1199+
/// Returns the number of TF_Functions registered in this graph.
1200+
/// </summary>
1201+
/// <value>The number functions.</value>
1202+
public int NumFunctions => TF_GraphNumFunctions (Handle);
1203+
1204+
[DllImport (NativeBinding.TensorFlowLibrary)]
1205+
static extern int TF_GraphGetFunctions (TF_Graph graph, IntPtr funcs, int max_func, TF_Status status);
1206+
1207+
/// <summary>
1208+
/// Returns an the functions that have been defined in the graph.
1209+
/// </summary>
1210+
/// <value>The functions.</value>
1211+
public TFFunction [] Functions {
1212+
get {
1213+
if (handle == null)
1214+
ObjectDisposedException ();
1215+
var n = NumFunctions;
1216+
unsafe {
1217+
TFFunction [] ret = null;
1218+
var size = sizeof (IntPtr);
1219+
var buffer = Marshal.AllocHGlobal (n * size);
1220+
using (var status = new TFStatus ()) {
1221+
int num = TF_GraphGetFunctions (handle, buffer, n, status.handle);
1222+
if (num > 0 && status.Ok) {
1223+
ret = new TFFunction [num];
1224+
var ofs = 0;
1225+
for (int i = 0; i < num; i++) {
1226+
var tfhandle = Marshal.ReadIntPtr (buffer, ofs);
1227+
ret [i] = new TFFunction (tfhandle);
1228+
ofs += size;
1229+
}
1230+
}
1231+
}
1232+
Marshal.FreeHGlobal (buffer);
1233+
return ret;
1234+
}
1235+
}
1236+
}
11941237
}
11951238

11961239
//
@@ -1794,6 +1837,28 @@ public TFOperation FinishOperation (TFStatus status = null)
17941837

17951838
return new TFOperation (graph, h);
17961839
}
1840+
1841+
[DllImport (NativeBinding.TensorFlowLibrary)]
1842+
static extern unsafe void TF_SetAttrFuncName (TF_OperationDescription desc,
1843+
string attr_name, string value, IntPtr len);
1844+
1845+
/// <summary>
1846+
/// Sets an attribute on the function to the specified value.
1847+
/// </summary>
1848+
/// <param name="attrName">The attribute name.</param>
1849+
/// <param name="value">The value for the attribute.</param>
1850+
public void SetAttribute (string attrName, string value)
1851+
{
1852+
if (handle == IntPtr.Zero)
1853+
ObjectDisposedException ();
1854+
if (attrName == null)
1855+
throw new ArgumentNullException (nameof (attrName));
1856+
if (value == null)
1857+
throw new ArgumentNullException (nameof (value));
1858+
1859+
TF_SetAttrFuncName (handle, attrName, value, (IntPtr) value.Length);
1860+
}
1861+
17971862
}
17981863

17991864
/// <summary>

docfx/api/TensorFlow/TensorFlow.TFShape.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ items:
2626
assemblies:
2727
- TensorFlowSharp
2828
namespace: TensorFlow
29-
summary: Represents the shape of a tensor
29+
summary: Represents the shape of a tensor, it describes how many dimensions the tensor has in a given axis
3030
remarks: >-
3131
<p>
3232
The shapes can be created by calling the constructor with the number of dimensions

docfx/api/TensorFlow/TensorFlow.TFTensor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ items:
6464
- TensorFlowSharp
6565
namespace: TensorFlow
6666
summary: TFTensor holds a multi-dimensional array of elements of a single data type.
67-
remarks: "<p>\n You can create tensors with the various constructors in this class, or using\n the implicit conversions from various data types into a TFTensor.\n </p>\n <p>\n The implicit conversions for basic types produce tensors of one dimesion with\n a single element, while the implicit conversion from an array, expects a multi-dimensional\n array that is converted into a tensor of the right dimensions.\n </p>\n <p>\n The special \"String\" tensor data type that you will find in TensorFlow documentation\n really represents a byte array. You can create string tensors by using the <xref href=\"TensorFlow.TFTensor.CreateString\"></xref> \n method that takes a byte array buffer as input.\n </p>"
67+
remarks: "<p>\n You can create tensors with the various constructors in this class, or using\n the implicit conversions from various data types into a TFTensor, including\n the creation of tensors from simple constants (returning a tensor that reprensets\n a scalar, that is, it is a 0D tensor), arrays (returning a tensor of a single\n dimension, 1D) or arbitrary multidimensional arrays.\n </p>\n <p>\n Given a tensor, you can retrieve the number of dimensions in it via the\n NumDims property, or you can retrieve the shape of a tensor, that is how many\n elements on each dimension the tensor has, by fetching the Shape property.\n </p>\n <p>\n The implicit conversions for basic types produce tensors of one dimesion with\n a single element, while the implicit conversion from an array, expects a multi-dimensional\n array that is converted into a tensor of the right dimensions.\n </p>\n <p>\n The special \"String\" tensor data type that you will find in TensorFlow documentation\n really represents a byte array. You can create string tensors by using the <xref href=\"TensorFlow.TFTensor.CreateString\"></xref> \n method that takes a byte array buffer as input.\n </p>\n <example>\n <pre><code>\n TFTensor scalar = 1; // Creates a 0D tensor, for the integer value 1\n int d = scalar.NumDims; // d will be equal to zero, as it is a 0D tensor\n long [] shape = scalar.Shape // returns an empty array, as it is a 0D tensor\n \n TFTensor list = new [] {1,2,3} // Creates a 1D tensor, or vector, for the values 1, 2, 3\n d = list.NumDims; // d will be one\n shape = list.Shape; // shape will be an array with a single value 3, representing that the dimension 0 has 3 elements\n \n // Creates a 3D tensor, \n TFTensor cube = new [,,] { {{1,2,3},{4,5,6}}}\n d = cube.NumDims // d will be 3\n shape = list.Shape // shape will be [1,2,3] which is the shape of the above 3D array\n </code></pre>\n </example>"
6868
syntax:
6969
content: 'public class TFTensor : TensorFlow.TFDisposable'
7070
inheritance:

docs/api/TensorFlow.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ <h4><a class="xref" href="TensorFlow/TensorFlow.TFSessionOptions.html">TFSession
144144
<section><p>The session options object holds configuration options that you want to use during your session, like the TensorFlow target or the configuration.</p>
145145
</section>
146146
<h4><a class="xref" href="TensorFlow/TensorFlow.TFShape.html">TFShape</a></h4>
147-
<section><p>Represents the shape of a tensor</p>
147+
<section><p>Represents the shape of a tensor, it describes how many dimensions the tensor has in a given axis</p>
148148
</section>
149149
<h4><a class="xref" href="TensorFlow/TensorFlow.TFStatus.html">TFStatus</a></h4>
150150
<section><p>Used to track the result of TensorFlow operations.</p>

docs/api/TensorFlow/TensorFlow.TFShape.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
<h1 id="TensorFlow_TFShape" data-uid="TensorFlow.TFShape">Class TFShape
7474
</h1>
75-
<div class="markdown level0 summary"><p>Represents the shape of a tensor</p>
75+
<div class="markdown level0 summary"><p>Represents the shape of a tensor, it describes how many dimensions the tensor has in a given axis</p>
7676
</div>
7777
<div class="markdown level0 conceptual"></div>
7878
<div class="inheritance">

docs/api/TensorFlow/TensorFlow.TFTensor.html

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,18 @@ <h5 id="TensorFlow_TFTensor_syntax">Syntax</h5>
100100
<pre><code class="lang-csharp hljs">public class TFTensor : TensorFlow.TFDisposable</code></pre>
101101
</div>
102102
<h5 id="TensorFlow_TFTensor_remarks"><strong>Remarks</strong></h5>
103-
<div class="markdown level0 remarks"><p>
103+
<div class="markdown level0 remarks"><p><p>
104104
You can create tensors with the various constructors in this class, or using
105-
the implicit conversions from various data types into a TFTensor.
105+
the implicit conversions from various data types into a TFTensor, including
106+
the creation of tensors from simple constants (returning a tensor that reprensets
107+
a scalar, that is, it is a 0D tensor), arrays (returning a tensor of a single
108+
dimension, 1D) or arbitrary multidimensional arrays.
106109
</p>
110+
<p>
111+
Given a tensor, you can retrieve the number of dimensions in it via the
112+
NumDims property, or you can retrieve the shape of a tensor, that is how many
113+
elements on each dimension the tensor has, by fetching the Shape property.
114+
</p>
107115
<p>
108116
The implicit conversions for basic types produce tensors of one dimesion with
109117
a single element, while the implicit conversion from an array, expects a multi-dimensional
@@ -113,7 +121,23 @@ <h5 id="TensorFlow_TFTensor_remarks"><strong>Remarks</strong></h5>
113121
The special &quot;String&quot; tensor data type that you will find in TensorFlow documentation
114122
really represents a byte array. You can create string tensors by using the <span class="xref">TensorFlow.TFTensor.CreateString</span>
115123
method that takes a byte array buffer as input.
116-
</p></div>
124+
</p>
125+
<example>
126+
<pre><code>
127+
TFTensor scalar = 1; // Creates a 0D tensor, for the integer value 1
128+
int d = scalar.NumDims; // d will be equal to zero, as it is a 0D tensor
129+
long [] shape = scalar.Shape // returns an empty array, as it is a 0D tensor<p>
130+
<pre><code> TFTensor list = new [] {1,2,3} // Creates a 1D tensor, or vector, for the values 1, 2, 3
131+
d = list.NumDims; // d will be one
132+
shape = list.Shape; // shape will be an array with a single value 3, representing that the dimension 0 has 3 elements
133+
134+
// Creates a 3D tensor,
135+
TFTensor cube = new [,,] { {{1,2,3},{4,5,6}}}
136+
d = cube.NumDims // d will be 3
137+
shape = list.Shape // shape will be [1,2,3] which is the shape of the above 3D array
138+
&lt;/code&gt;&lt;/pre&gt;
139+
&lt;/example&gt;
140+
</code></pre></code></pre></example></div>
117141
<h3 id="constructors">Constructors
118142
</h3>
119143

docs/manifest.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

ecmadocs/en/TensorFlow/TFShape.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Interfaces />
1212
<Docs>
1313
<summary>
14-
Represents the shape of a tensor
14+
Represents the shape of a tensor, it describes how many dimensions the tensor has in a given axis
1515
</summary>
1616
<remarks>
1717
<para>

ecmadocs/en/TensorFlow/TFTensor.xml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@
1616
<remarks>
1717
<para>
1818
You can create tensors with the various constructors in this class, or using
19-
the implicit conversions from various data types into a TFTensor.
19+
the implicit conversions from various data types into a TFTensor, including
20+
the creation of tensors from simple constants (returning a tensor that reprensets
21+
a scalar, that is, it is a 0D tensor), arrays (returning a tensor of a single
22+
dimension, 1D) or arbitrary multidimensional arrays.
2023
</para>
24+
<para>
25+
Given a tensor, you can retrieve the number of dimensions in it via the
26+
NumDims property, or you can retrieve the shape of a tensor, that is how many
27+
elements on each dimension the tensor has, by fetching the Shape property.
28+
</para>
2129
<para>
2230
The implicit conversions for basic types produce tensors of one dimesion with
2331
a single element, while the implicit conversion from an array, expects a multi-dimensional
@@ -28,6 +36,22 @@
2836
really represents a byte array. You can create string tensors by using the <see cref="M:TensorFlow.TFTensor.CreateString" />
2937
method that takes a byte array buffer as input.
3038
</para>
39+
<example>
40+
<code>
41+
TFTensor scalar = 1; // Creates a 0D tensor, for the integer value 1
42+
int d = scalar.NumDims; // d will be equal to zero, as it is a 0D tensor
43+
long [] shape = scalar.Shape // returns an empty array, as it is a 0D tensor
44+
45+
TFTensor list = new [] {1,2,3} // Creates a 1D tensor, or vector, for the values 1, 2, 3
46+
d = list.NumDims; // d will be one
47+
shape = list.Shape; // shape will be an array with a single value 3, representing that the dimension 0 has 3 elements
48+
49+
// Creates a 3D tensor,
50+
TFTensor cube = new [,,] { {{1,2,3},{4,5,6}}}
51+
d = cube.NumDims // d will be 3
52+
shape = list.Shape // shape will be [1,2,3] which is the shape of the above 3D array
53+
</code>
54+
</example>
3155
</remarks>
3256
</Docs>
3357
<Members>

0 commit comments

Comments
 (0)