From 001aa1b70010353d972e43dbb45e54e1161ecdc7 Mon Sep 17 00:00:00 2001 From: Meinrad Recheis Date: Fri, 12 Jul 2019 15:15:24 +0200 Subject: [PATCH] Tensor: Create a Tensor from Array without copying --- src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs b/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs index b90c4e69..f6d49192 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.Creation.cs @@ -1,8 +1,6 @@ /***************************************************************************** Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved. - Portions of this file have been adapted from TensorFlowSharp, authored by Miguel de Icaza (miguel@microsoft.com) - Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -358,8 +356,8 @@ namespace Tensorflow protected IntPtr CreateTensorWithoutCopying(TF_DataType dt, long[] shape, Array data, int element_size) { return CreateTensorWithoutCopying(dt, shape, data, 0, data.Length, element_size); - } - + } + /// /// Creates a new tensor from a subsection of the given array without copying memory. The array is pinned down and the pointer passed on. /// @@ -378,7 +376,7 @@ namespace Tensorflow protected IntPtr CreateTensorWithoutCopying(TF_DataType dt, long[] shape, Array data, int start, int count, int element_size) { if (start < 0 || start > data.Length - count) - throw new ArgumentException("start + count > Array size"); + throw new ArgumentException($"Array length {data.Length} does not match the given shape {new Shape(shape.Cast().ToArray())}"); // get a handle to the pinned array which we will pass on to the tensor computation engine to use var dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned);