diff --git a/src/NumSharp.Core/Interfaces/IShape.cs b/src/NumSharp.Core/Interfaces/IShape.cs new file mode 100644 index 00000000..2ff7ce10 --- /dev/null +++ b/src/NumSharp.Core/Interfaces/IShape.cs @@ -0,0 +1,22 @@ +using NumSharp; +using System; +using System.Collections.Generic; + +namespace NumSharp.Core.Interfaces +{ + public interface IShape + { + int Size {get;} + int NDim {get;} + int TensorOrder {get;} + IReadOnlyList DimOffset {get;} + IReadOnlyList Shapes {get;} + int ReShape(params int[] dimensions); + int GetIndexInShape(params int[] select); + int[] GetDimIndexOutShape(int select); + int UniShape {get;} + (int, int) BiShape {get;} + (int, int, int) TriShape {get;} + bool ChangeTensorOrder(int order); + } +} \ No newline at end of file diff --git a/src/NumSharp.Core/Interfaces/IStorage.cs b/src/NumSharp.Core/Interfaces/IStorage.cs new file mode 100644 index 00000000..b3b20331 --- /dev/null +++ b/src/NumSharp.Core/Interfaces/IStorage.cs @@ -0,0 +1,153 @@ +using NumSharp; +using System; + +namespace NumSharp.Core.Interfaces +{ + /// + /// An abstract interface as design basis for the true Storage + /// + /// Responsible for : + /// + /// - store data type, elements, Shape + /// - offers methods for accessing elements depending on shape + /// - offers methods for casting elements + /// - offers methods for change tensor order + /// - GetData always return reference object to the true storage + /// - GetData and SetData change dtype and cast storage + /// - CloneData always create a clone of storage and return this as reference object + /// - CloneData clone storage and cast this clone + /// + /// + public interface IStorage + { + /// + /// Data Type of stored elements + /// + /// numpys equal dtype + Type DType {get;} + /// + /// storage shape for outside representation + /// + /// numpys equal shape + IShape Shape {get;} + /// + /// column wise or row wise order + /// + /// 0 row wise, 1 column wise + int TensorOrder {get;} + /// + /// Allocate memory by dtype, shape, tensororder (default column wise) + /// + /// storage data type + /// storage data shape + /// row or column wise + void Allocate(Type dtype, Shape shape, int tensorOrder = 1); + /// + /// Allocate memory by Array and tensororder and deduce shape and dtype (default column wise) + /// + /// elements to store + /// row or column wise + void Allocate(Array values, int tensorOrder = 1); + /// + /// Get Back Storage with Columnwise tensor Layout + /// By this method the layout is changed if layout is not columnwise + /// + /// reference to storage (transformed or not) + IStorage GetColumWiseStorage(); + /// + /// Get Back Storage with row wise tensor Layout + /// By this method the layout is changed if layout is not row wise + /// + /// reference to storage (transformed or not) + IStorage GetRowWiseStorage(); + /// + /// Get reference to internal data storage + /// + /// reference to internal storage as System.Array + Array GetData(); + /// + /// Clone internal storage and get reference to it + /// + /// reference to cloned storage as System.Array + Array CloneData(); + /// + /// Get reference to internal data storage and cast elements to new dtype + /// + /// new storage data type + /// reference to internal (casted) storage as System.Array + Array GetData(Type dtype); + /// + /// Clone internal storage and cast elements to new dtype + /// + /// cloned storage data type + /// reference to cloned storage as System.Array + Array CloneData(Type dtype); + /// + /// Get reference to internal data storage and cast elements to new dtype + /// + /// new storage data type + /// reference to internal (casted) storage as T[] + T[] GetData(); + /// + /// Get all elements from cloned storage as T[] and cast dtype + /// + /// cloned storgae dtype + /// reference to cloned storage as T[] + T[] CloneData(); + /// + /// Get single value from internal storage and do not cast dtype + /// + /// indexes + /// element from internal storage + object GetData(params int[] indexes); + /// + /// Get single value from internal storage as type T and cast dtype to T + /// + /// indexes + /// new storage data type + /// element from internal storage + T GetData(params int[] indexes); + /// + /// Set an array to internal storage and keep dtype + /// + /// + void SetData(Array values); + /// + /// Set 1 single value to internal storage and keep dtype + /// + /// + /// + void SetData(object value, params int[] indexes); + /// + /// Set a 1D Array of type T to internal storage and cast dtype + /// + /// + /// + void SetData(T[] values); + /// + /// Set a single value of type dtype to internal storage and cast storage + /// + /// + /// + /// + void SetData(T value, params int[] indexes); + /// + /// Set an Array to internal storage, cast it to new dtype and change dtype + /// + /// + /// + void SetData(Array values, Type dtype); + /// + /// Change dtype of elements + /// + /// new storage data type + /// sucess or not + bool ChangeDataType(Type dtype); + /// + /// Cange layout to 0 row wise or 1 colum wise + /// + /// 0 or 1 + /// success or not + bool SwitchTensorOrder(int order); + } +} \ No newline at end of file