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!"); }
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!"); }
public static Tensor <int> Fill(int fillValue, params int[] shape) { var data = new TensorData <int>(fillValue, shape); return(Create(data)); }
public static Tensor <int> Create(int[] values) { var data = new TensorData <int>(values); return(Create(data)); }
public static Tensor <float> Create(TensorData <float> data) { return(new FloatTensor(data)); }
public static Tensor <float> Empty(params int[] shape) { var data = new TensorData <float>(shape); return(Create(data)); }
public Tensor(TensorData <T> data) { Values = data; DataType = typeof(T); }
public static Tensor <double> Fill(double fillValue, params int[] shape) { var data = new TensorData <double>(fillValue, shape); return(Create(data)); }
public static Tensor <double> Create(double[] values) { var data = new TensorData <double>(values); return(Create(data)); }
public IntTensor(TensorData <int> data) : base(data) { }
public static Tensor <long> Create(TensorData <long> data) { return(new LongTensor(data)); }
public static Tensor <long> Create(long[] values, params int[] shape) { var data = new TensorData <long>(values, shape); return(Create(data)); }
public static Tensor <long> Create(long[] values) { var data = new TensorData <long>(values); return(Create(data)); }
public static Tensor <int> Create(TensorData <int> data) { return(new IntTensor(data)); }
public DoubleTensor(TensorData <double> data) : base(data) { }
public LongTensor(TensorData <long> data) : base(data) { }
public static Tensor <float> Create(float[] values) { var data = new TensorData <float>(values); return(Create(data)); }
public static Tensor <double> Create(double[] values, params int[] shape) { var data = new TensorData <double>(values, shape); return(Create(data)); }
public static Tensor <float> Create(float[] values, params int[] shape) { var data = new TensorData <float>(values, shape); return(Create(data)); }
public static Tensor <double> Create(TensorData <double> data) { return(new DoubleTensor(data)); }
public FloatTensor(TensorData <float> data) : base(data) { }