1+ using NumSharp ;
2+ using System ;
3+
4+ namespace NumSharp . Core . Interfaces
5+ {
6+ /// <summary>
7+ /// An abstract interface as design basis for the true Storage
8+ ///
9+ /// Responsible for :
10+ ///
11+ /// - store data type, elements, Shape
12+ /// - offers methods for accessing elements depending on shape
13+ /// - offers methods for casting elements
14+ /// - offers methods for change tensor order
15+ /// - GetData always return reference object to the true storage
16+ /// - GetData<T> and SetData<T> change dtype and cast storage
17+ /// - CloneData always create a clone of storage and return this as reference object
18+ /// - CloneData<T> clone storage and cast this clone
19+ ///
20+ /// </summary>
21+ public interface IStorage
22+ {
23+ /// <summary>
24+ /// Data Type of stored elements
25+ /// </summary>
26+ /// <value>numpys equal dtype</value>
27+ Type DType { get ; }
28+ /// <summary>
29+ /// storage shape for outside representation
30+ /// </summary>
31+ /// <value>numpys equal shape</value>
32+ IShape Shape { get ; }
33+ /// <summary>
34+ /// column wise or row wise order
35+ /// </summary>
36+ /// <value>0 row wise, 1 column wise</value>
37+ int TensorOrder { get ; }
38+ /// <summary>
39+ /// Allocate memory by dtype, shape, tensororder (default column wise)
40+ /// </summary>
41+ /// <param name="dtype">storage data type</param>
42+ /// <param name="shape">storage data shape</param>
43+ /// <param name="tensorOrder">row or column wise</param>
44+ void Allocate ( Type dtype , Shape shape , int tensorOrder = 1 ) ;
45+ /// <summary>
46+ /// Allocate memory by Array and tensororder and deduce shape and dtype (default column wise)
47+ /// </summary>
48+ /// <param name="values">elements to store</param>
49+ /// <param name="tensorOrder">row or column wise</param>
50+ void Allocate ( Array values , int tensorOrder = 1 ) ;
51+ /// <summary>
52+ /// Get Back Storage with Columnwise tensor Layout
53+ /// By this method the layout is changed if layout is not columnwise
54+ /// </summary>
55+ /// <returns>reference to storage (transformed or not)</returns>
56+ IStorage GetColumWiseStorage ( ) ;
57+ /// <summary>
58+ /// Get Back Storage with row wise tensor Layout
59+ /// By this method the layout is changed if layout is not row wise
60+ /// </summary>
61+ /// <returns>reference to storage (transformed or not)</returns>
62+ IStorage GetRowWiseStorage ( ) ;
63+ /// <summary>
64+ /// Get reference to internal data storage
65+ /// </summary>
66+ /// <returns>reference to internal storage as System.Array</returns>
67+ Array GetData ( ) ;
68+ /// <summary>
69+ /// Clone internal storage and get reference to it
70+ /// </summary>
71+ /// <returns>reference to cloned storage as System.Array</returns>
72+ Array CloneData ( ) ;
73+ /// <summary>
74+ /// Get reference to internal data storage and cast elements to new dtype
75+ /// </summary>
76+ /// <param name="dtype">new storage data type</param>
77+ /// <returns>reference to internal (casted) storage as System.Array </returns>
78+ Array GetData ( Type dtype ) ;
79+ /// <summary>
80+ /// Clone internal storage and cast elements to new dtype
81+ /// </summary>
82+ /// <param name="dtype">cloned storage data type</param>
83+ /// <returns>reference to cloned storage as System.Array</returns>
84+ Array CloneData ( Type dtype ) ;
85+ /// <summary>
86+ /// Get reference to internal data storage and cast elements to new dtype
87+ /// </summary>
88+ /// <typeparam name="T">new storage data type</typeparam>
89+ /// <returns>reference to internal (casted) storage as T[]</returns>
90+ T [ ] GetData < T > ( ) ;
91+ /// <summary>
92+ /// Get all elements from cloned storage as T[] and cast dtype
93+ /// </summary>
94+ /// <typeparam name="T">cloned storgae dtype</typeparam>
95+ /// <returns>reference to cloned storage as T[]</returns>
96+ T [ ] CloneData < T > ( ) ;
97+ /// <summary>
98+ /// Get single value from internal storage and do not cast dtype
99+ /// </summary>
100+ /// <param name="indexes">indexes</param>
101+ /// <returns>element from internal storage</returns>
102+ object GetData ( params int [ ] indexes ) ;
103+ /// <summary>
104+ /// Get single value from internal storage as type T and cast dtype to T
105+ /// </summary>
106+ /// <param name="indexes">indexes</param>
107+ /// <typeparam name="T">new storage data type</typeparam>
108+ /// <returns>element from internal storage</returns>
109+ T GetData < T > ( params int [ ] indexes ) ;
110+ /// <summary>
111+ /// Set an array to internal storage and keep dtype
112+ /// </summary>
113+ /// <param name="values"></param>
114+ void SetData ( Array values ) ;
115+ /// <summary>
116+ /// Set 1 single value to internal storage and keep dtype
117+ /// </summary>
118+ /// <param name="value"></param>
119+ /// <param name="indexes"></param>
120+ void SetData ( object value , params int [ ] indexes ) ;
121+ /// <summary>
122+ /// Set a 1D Array of type T to internal storage and cast dtype
123+ /// </summary>
124+ /// <param name="values"></param>
125+ /// <typeparam name="T"></typeparam>
126+ void SetData < T > ( T [ ] values ) ;
127+ /// <summary>
128+ /// Set a single value of type dtype to internal storage and cast storage
129+ /// </summary>
130+ /// <param name="value"></param>
131+ /// <param name="indexes"></param>
132+ /// <typeparam name="T"></typeparam>
133+ void SetData < T > ( T value , params int [ ] indexes ) ;
134+ /// <summary>
135+ /// Set an Array to internal storage, cast it to new dtype and change dtype
136+ /// </summary>
137+ /// <param name="values"></param>
138+ /// <param name="dtype"></param>
139+ void SetData ( Array values , Type dtype ) ;
140+ /// <summary>
141+ /// Change dtype of elements
142+ /// </summary>
143+ /// <param name="dtype">new storage data type</param>
144+ /// <returns>sucess or not</returns>
145+ bool ChangeDataType ( Type dtype ) ;
146+ /// <summary>
147+ /// Cange layout to 0 row wise or 1 colum wise
148+ /// </summary>
149+ /// <param name="order">0 or 1</param>
150+ /// <returns>success or not</returns>
151+ bool SwitchTensorOrder ( int order ) ;
152+ }
153+ }
0 commit comments