예제 #1
0
        public static Tensor <T> Empty <T>(params int[] shape)
            where T : struct
        {
            var type = typeof(T).Name;

            switch (type)
            {
            case TensorTypes.Float:
                var fData   = new TensorData <float>(shape);
                var fTensor = new FloatTensor(fData);
                return((Tensor <T>)(object) fTensor);

            case TensorTypes.Double:
                var dData   = new TensorData <double>(shape);
                var dTensor = new DoubleTensor(dData);
                return((Tensor <T>)(object) dTensor);

            case TensorTypes.Int:
                var iData   = new TensorData <int>(shape);
                var iTensor = new IntTensor(iData);
                return((Tensor <T>)(object) iTensor);

            case TensorTypes.Long:
                var lData   = new TensorData <long>(shape);
                var lTensor = new LongTensor(lData);
                return((Tensor <T>)(object) lTensor);

            default:
                break;
            }
            throw new NotImplementedException($"type {type} not implemented!");
        }
예제 #2
0
        public static Tensor <T> Values <T>(Array array)
            where T : struct
        {
            var shape = new TensorShape(TensorShape.GetShapeFromArray(array));

            var type = typeof(T).Name;

            switch (type)
            {
            case TensorTypes.Float:
                var fData = new TensorData <float>(shape);
                var fSpan = fData.RawValues;
                for (int i = 0; i < fSpan.Length; i++)
                {
                    fSpan[i] = (float)array.GetValue(shape.OffsetToIndex(i));
                }
                var fTensor = new FloatTensor(fData);
                return((Tensor <T>)(object) fTensor);

            case TensorTypes.Double:
                var dData = new TensorData <double>(shape);
                var dSpan = dData.RawValues;
                for (int i = 0; i < dSpan.Length; i++)
                {
                    dSpan[i] = (double)array.GetValue(shape.OffsetToIndex(i));
                }
                var dTensor = new DoubleTensor(dData);
                return((Tensor <T>)(object) dTensor);

            case TensorTypes.Int:
                var iData = new TensorData <int>(shape);
                var iSpan = iData.RawValues;
                for (int i = 0; i < iSpan.Length; i++)
                {
                    var index = shape.OffsetToIndex(i);
                    iSpan[i] = (int)array.GetValue(index);
                }
                var iTensor = new IntTensor(iData);
                return((Tensor <T>)(object) iTensor);

            case TensorTypes.Long:
                var lData = new TensorData <long>(shape);
                var lSpan = lData.RawValues;
                for (int i = 0; i < lSpan.Length; i++)
                {
                    lSpan[i] = (long)array.GetValue(shape.OffsetToIndex(i));
                }
                var lTensor = new LongTensor(lData);
                return((Tensor <T>)(object) lTensor);

            default:
                break;
            }
            throw new NotImplementedException($"type {type} not implemented!");
        }
예제 #3
0
        public static Tensor <int> Fill(int fillValue, params int[] shape)
        {
            var data = new TensorData <int>(fillValue, shape);

            return(Create(data));
        }
예제 #4
0
        public static Tensor <int> Create(int[] values)
        {
            var data = new TensorData <int>(values);

            return(Create(data));
        }
예제 #5
0
 public static Tensor <float> Create(TensorData <float> data)
 {
     return(new FloatTensor(data));
 }
예제 #6
0
        public static Tensor <float> Empty(params int[] shape)
        {
            var data = new TensorData <float>(shape);

            return(Create(data));
        }
예제 #7
0
 public Tensor(TensorData <T> data)
 {
     Values   = data;
     DataType = typeof(T);
 }
예제 #8
0
        public static Tensor <double> Fill(double fillValue, params int[] shape)
        {
            var data = new TensorData <double>(fillValue, shape);

            return(Create(data));
        }
예제 #9
0
        public static Tensor <double> Create(double[] values)
        {
            var data = new TensorData <double>(values);

            return(Create(data));
        }
예제 #10
0
 public IntTensor(TensorData <int> data) : base(data)
 {
 }
예제 #11
0
 public static Tensor <long> Create(TensorData <long> data)
 {
     return(new LongTensor(data));
 }
예제 #12
0
        public static Tensor <long> Create(long[] values, params int[] shape)
        {
            var data = new TensorData <long>(values, shape);

            return(Create(data));
        }
예제 #13
0
        public static Tensor <long> Create(long[] values)
        {
            var data = new TensorData <long>(values);

            return(Create(data));
        }
예제 #14
0
 public static Tensor <int> Create(TensorData <int> data)
 {
     return(new IntTensor(data));
 }
예제 #15
0
 public DoubleTensor(TensorData <double> data) : base(data)
 {
 }
예제 #16
0
 public LongTensor(TensorData <long> data) : base(data)
 {
 }
예제 #17
0
        public static Tensor <float> Create(float[] values)
        {
            var data = new TensorData <float>(values);

            return(Create(data));
        }
예제 #18
0
        public static Tensor <double> Create(double[] values, params int[] shape)
        {
            var data = new TensorData <double>(values, shape);

            return(Create(data));
        }
예제 #19
0
        public static Tensor <float> Create(float[] values, params int[] shape)
        {
            var data = new TensorData <float>(values, shape);

            return(Create(data));
        }
예제 #20
0
 public static Tensor <double> Create(TensorData <double> data)
 {
     return(new DoubleTensor(data));
 }
예제 #21
0
 public FloatTensor(TensorData <float> data) : base(data)
 {
 }