Beispiel #1
0
        // @TODO: choose approach to handle case when tensors after Flatten/Reshape are written into OR taken ownership of
        // 1) owns data, copy on PrepareCacheForAccess() and PinForWrite()
        // 2) always copy data in Flatten()/Reshape(), remove from Tensor interface
        // 2) always copy data in Flatten()/Reshape(), implement ICloneable for GPU ITensorData

        /// <summary>
        /// Create a flattened copy of the current Tensor ie of shape [B,1,1,H*W*CH]
        /// </summary>
        public Tensor Flatten()
        {
            var newShape = shape.Flatten();

            Tensor copy;

            if (m_TensorAllocator != null)
            {
                copy = m_TensorAllocator.Alloc(newShape, m_TensorOnDevice);
            }
            else
            {
                copy = new Tensor(newShape, m_TensorOnDevice);
            }

            copy.name           = $"flatten of {name}";
            copy.m_Cache        = m_Cache;
            copy.m_CacheIsDirty = m_CacheIsDirty;
            return(copy);
        }
Beispiel #2
0
        /// <summary>
        /// Create a flattened copy of the current Tensor ie of shape [B,1,1,H*W*CH]
        /// </summary>
        public Tensor Flatten()
        {
            var newShape = shape.Flatten();

            return(ShallowCopy(newShape, $"flatten of {name}"));
        }