コード例 #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)
 {
 }