Skip to content

Commit ad21968

Browse files
committed
Doc work
1 parent a435a2b commit ad21968

File tree

3 files changed

+319
-233
lines changed

3 files changed

+319
-233
lines changed

TensorFlowSharp/Tensor.cs

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,51 @@ public unsafe TFTensor (long value)
314314
}
315315

316316
// Convenience, should I add T[,] and T[,,] as more convenience ones?
317+
318+
/// <summary>
319+
/// Creates a 1 dimensional tensor from an array of sbytes.
320+
/// </summary>
321+
/// <param name="data">Data.</param>
317322
public TFTensor (sbyte [] data) : base (SetupTensor (TFDataType.Int8, data, size: 2)) { }
323+
/// <summary>
324+
/// Creates a 1 dimensional tensor from an array of bytes.
325+
/// </summary>
326+
/// <param name="data">Data.</param>
318327
public TFTensor (byte [] data) : base (SetupTensor (TFDataType.UInt8, data, size: 1)) { }
328+
/// <summary>
329+
/// Creates a 1 dimensional tensor from an array of shorts.
330+
/// </summary>
331+
/// <param name="data">Data.</param>
319332
public TFTensor (short [] data) : base (SetupTensor (TFDataType.Int16, data, size: 2)) { }
333+
/// <summary>
334+
/// Creates a 1 dimensional tensor from an array of ushorts
335+
/// </summary>
336+
/// <param name="data">Data.</param>
320337
public TFTensor (ushort [] data) : base (SetupTensor (TFDataType.UInt16, data, size: 2)) { }
338+
/// <summary>
339+
/// Creates a 1 dimensional tensor from an array of ints.
340+
/// </summary>
341+
/// <param name="data">Data.</param>
321342
public TFTensor (int [] data) : base (SetupTensor (TFDataType.Int32, data, size: 4)) { }
343+
/// <summary>
344+
/// Creates a 1 dimensional tensor from an array of floats.
345+
/// </summary>
346+
/// <param name="data">Data.</param>
322347
public TFTensor (float [] data) : base (SetupTensor (TFDataType.Float, data, size: 4)) { }
348+
/// <summary>
349+
/// Creates a 1 dimensional tensor from an array of doubles.
350+
/// </summary>
351+
/// <param name="data">Data.</param>
323352
public TFTensor (double [] data) : base (SetupTensor (TFDataType.Double, data, size: 8)) { }
353+
/// <summary>
354+
/// Creates a 1 dimensional tensor from an array of longs.
355+
/// </summary>
356+
/// <param name="data">Data.</param>
324357
public TFTensor (long [] data) : base (SetupTensor (TFDataType.Int64, data, size: 8)) { }
358+
/// <summary>
359+
/// Creates a 1 dimensional tensor from an array of complex numbers.
360+
/// </summary>
361+
/// <param name="data">Data.</param>
325362
public TFTensor (Complex [] data) : base (SetupTensor (TFDataType.Complex128, data, size: 16)) { }
326363

327364
/// <summary>
@@ -405,38 +442,78 @@ static IntPtr SetupMulti (TFDataType dt, long [] dims, Array data, long bytes)
405442
//
406443
// Factory methods to create tensors from a constant
407444
//
408-
// TODO: add more data types
409445

446+
/// <summary>
447+
/// Converts an integer into a 1-dimensional, 1-valued tensor.
448+
/// </summary>
449+
/// <returns>The tensor representing the integer value.</returns>
450+
/// <param name="value">Value to initialize the tensor with.</param>
410451
public static implicit operator TFTensor (int value)
411452
{
412453
return new TFTensor (value);
413454
}
414455

456+
/// <summary>
457+
/// Converts a long into a 1-dimensional, 1-valued tensor.
458+
/// </summary>
459+
/// <returns>The tensor representing the long value.</returns>
460+
/// <param name="value">Value to initialize the tensor with.</param>
415461
public static implicit operator TFTensor (long value)
416462
{
417463
return new TFTensor (value);
418464
}
419465

466+
/// <summary>
467+
/// Converts a double into a 1-dimensional, 1-valued tensor.
468+
/// </summary>
469+
/// <returns>The tensor representing the double value.</returns>
470+
/// <param name="value">Value to initialize the tensor with.</param>
420471
unsafe public static implicit operator TFTensor (double value)
421472
{
422473
return new TFTensor (value);
423474
}
424475

476+
/// <summary>
477+
/// Converts a float into a 1-dimensional, 1-valued tensor.
478+
/// </summary>
479+
/// <returns>The tensor representing the float value.</returns>
480+
/// <param name="value">Value to initialize the tensor with.</param>
425481
unsafe public static implicit operator TFTensor (float value)
426482
{
427483
return new TFTensor (value);
428484
}
429485

486+
/// <summary>
487+
/// Converts a Complex number into a 1-dimensional, 1-valued tensor.
488+
/// </summary>
489+
/// <returns>The tensor representing the complex value.</returns>
490+
/// <param name="value">Value to initialize the tensor with.</param>
430491
unsafe public static implicit operator TFTensor (Complex value)
431492
{
432493
return new TFTensor (value);
433494
}
434495

496+
/// <summary>
497+
/// Converts a byte into a 1-dimensional, 1-valued tensor.
498+
/// </summary>
499+
/// <returns>The tensor representing the byte value.</returns>
500+
/// <param name="value">Value to initialize the tensor with.</param>
435501
unsafe public static implicit operator TFTensor (byte value)
436502
{
437503
return new TFTensor (value);
438504
}
439505

506+
/// <summary>
507+
/// Converts a C# array into a tensor.
508+
/// </summary>
509+
/// <returns>The tensor containing the data.</returns>
510+
/// <param name="array">single dimension, or multi-dimensional array.</param>
511+
/// <remarks>
512+
/// This implicit conversion can convert single or multidimensional arrays of
513+
/// booleans, sbytes, byte, shorts, ushorts, ints, longs, doubles, floats and
514+
/// complex numbers into a tensor with the same dimensional shape as the provided
515+
/// array.
516+
/// </remarks>
440517
unsafe public static implicit operator TFTensor (Array array)
441518
{
442519
if (array == null)
@@ -504,6 +581,15 @@ unsafe public static implicit operator TFTensor (Array array)
504581

505582
// General purpose constructor, specifies data type and gets pointer to buffer
506583
// Is the default good, one where we let the user provide their own deallocator, or should we make a copy in that case?
584+
/// <summary>
585+
/// Low-level tensor constructor that creates a tensor from a buffer pointed to by an IntPtr.
586+
/// </summary>
587+
/// <param name="dataType">Specifies the data type held by the tensor, as well as how to interpret the provided data.</param>
588+
/// <param name="dims">Describes the tensor shape, an array that indicates .</param>
589+
/// <param name="data">Pointer to the raw data that will be used to initialize the tensor.</param>
590+
/// <param name="dataSize">The size of the data being passed in.</param>
591+
/// <param name="deallocator">Deallocator method, it is invoked when the tensor is destroyed to release the data pointed to by <paramref name="data"/>.</param>
592+
/// <param name="deallocatorData">An optional argument of data that is passed to the deallocator method when the tensor is destroyed, you can use this to pass context information.</param>
507593
public TFTensor (TFDataType dataType, long [] dims, IntPtr data, size_t dataSize, Deallocator deallocator, IntPtr deallocatorData) : base (IntPtr.Zero)
508594
{
509595
if (dims == null)
@@ -524,6 +610,16 @@ internal override void NativeDispose (IntPtr handle)
524610
[DllImport (NativeBinding.TensorFlowLibrary)]
525611
static extern unsafe TF_Tensor TF_AllocateTensor (TFDataType dataType, IntPtr zeroDim, int num_dims, size_t len);
526612

613+
/// <summary>
614+
/// Low-level: Creates an empty tensor of the specified type and shape, with the specified number of elements
615+
/// </summary>
616+
/// <param name="dataType">Data type.</param>
617+
/// <param name="dims">Tensor shape.</param>
618+
/// <param name="size">Size in bytes of the tensor, this will be the actual memory allocated.</param>
619+
/// <remarks>
620+
/// It is the responsibility of the caller to ensure that the size is correct given the data type size
621+
/// and the tensor dimension specified in dims.
622+
/// </remarks>
527623
public TFTensor (TFDataType dataType, long [] dims, int size) : base (IntPtr.Zero)
528624
{
529625
if (dims == null)
@@ -539,6 +635,10 @@ public TFTensor (TFDataType dataType, long [] dims, int size) : base (IntPtr.Zer
539635
[DllImport (NativeBinding.TensorFlowLibrary)]
540636
static extern unsafe TFDataType TF_TensorType (TF_Tensor tensor);
541637

638+
/// <summary>
639+
/// Returns the data type for the tensor.
640+
/// </summary>
641+
/// <value>The type of the tensor.</value>
542642
public TFDataType TensorType => TF_TensorType (handle);
543643

544644
// extern int TF_NumDims (const TF_Tensor *);

0 commit comments

Comments
 (0)