Exemple #1
0
        /// <summary>
        /// Allocate a new tensor. The caller must set the Tensor values by writing them to the DataPointer
        /// with length ByteSize.
        /// </summary>
        /// <param name="dataType">The type of data</param>
        /// <param name="dims">The size for each of the dimension of the tensor</param>
        public Tensor(DataType dataType, int[] dims)
        {
            int size = dims.Length > 0 ? 1 : 0;

            for (int i = 0; i < dims.Length; i++)
            {
                size *= dims[i];
            }

            size *= TfInvoke.DataTypeSize(dataType);

            GCHandle dimHandle = GCHandle.Alloc(dims, GCHandleType.Pinned);

            _ptr = TfInvoke.tfeAllocateTensor(dataType, dimHandle.AddrOfPinnedObject(), dims.Length, size);
            dimHandle.Free();
        }