public static TensorIndices3 IndexOfMax <T>(this SpanTensor3 <T> tensor, IComparer <T> comparer = null)
            where T : unmanaged, IEquatable <T>
        {
            var span = tensor._Buffer;

            if (span.Length == 0)
            {
                return(TensorIndices3.Invalid);
            }

            if (comparer == null)
            {
                comparer = Comparer <T> .Default;
            }

            T   max = span[0];
            var idx = 0;

            for (int i = 1; i < span.Length; ++i)
            {
                var item = span[i];
                if (comparer.Compare(max, item) > 0)
                {
                    max = item; idx = i;
                }
            }

            return(tensor._Dimensions.GetDecomposedIndex(idx));
        }
        public static TensorIndices3 IndexOf <T>(this SpanTensor3 <T> tensor, T value)
            where T : unmanaged, IEquatable <T>
        {
            var idx = tensor._Buffer.IndexOf(value);

            if (idx < 0)
            {
                return(TensorSize3.Invalid);
            }
            return(tensor._Dimensions.GetDecomposedIndex(idx));
        }
        public static TensorIndices3 IndexOf <T>(this SpanTensor3 <T> tensor, Predicate <T> predicate)
            where T : unmanaged, IEquatable <T>
        {
            var span = tensor._Buffer;

            for (int i = 0; i < span.Length; ++i)
            {
                if (predicate(span[i]))
                {
                    return(tensor._Dimensions.GetDecomposedIndex(i));
                }
            }

            return(TensorIndices3.Invalid);
        }
Пример #4
0
        public static MemoryBitmap <Vector3> CreateBGRBitmap(SpanTensor3 <Single> tensor, Func <Single[], Vector3> pixelFunc)
        {
            var midPixel = new Single[tensor.Dimensions[2]];

            var memory = new MemoryBitmap <Vector3>(tensor.Dimensions[1], tensor.Dimensions[0], Pixel.BGR96F.Format);

            for (int y = 0; y < tensor.Dimensions[0]; ++y)
            {
                var row = tensor[y];

                for (int x = 0; x < row.Dimensions[0]; ++x)
                {
                    row[x].CopyTo(midPixel);
                    var dstPixel = pixelFunc(midPixel);
                    memory.SetPixel(x, y, dstPixel);
                }
            }

            return(memory);
        }
 public static void ApplySoftMax(this SpanTensor3 <float> tensor)
 {
     SpanTensor.ApplySoftMax(tensor.Span);
 }