@@ -3,22 +3,46 @@ use crate::{DType, Device, Shape};
33
44#[ derive( Debug ) ]
55pub enum StorageError {
6- BinaryOperationDeviceMismatch { lhs : Device , rhs : Device , op : & ' static str } ,
7- BinaryOperationDTypeMismatch { lhs : DType , rhs : DType , op : & ' static str } ,
8- BinaryOperationShapeMismatch { lhs : Shape , rhs : Shape , op : & ' static str } ,
6+ BinaryOperationDeviceMismatch {
7+ lhs : Device ,
8+ rhs : Device ,
9+ op : & ' static str ,
10+ } ,
11+ BinaryOperationDTypeMismatch {
12+ lhs : DType ,
13+ rhs : DType ,
14+ op : & ' static str ,
15+ } ,
16+ BinaryOperationShapeMismatch {
17+ lhs : Shape ,
18+ rhs : Shape ,
19+ op : & ' static str ,
20+ } ,
921}
1022
1123impl std:: fmt:: Display for StorageError {
1224 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1325 match self {
1426 StorageError :: BinaryOperationDeviceMismatch { lhs, rhs, op } => {
15- write ! ( f, "unexpected device in {}, lhs: {:?}, rhs: {:?}" , op, lhs, rhs)
27+ write ! (
28+ f,
29+ "unexpected device in {}, lhs: {:?}, rhs: {:?}" ,
30+ op, lhs, rhs
31+ )
1632 }
1733 StorageError :: BinaryOperationDTypeMismatch { lhs, rhs, op } => {
18- write ! ( f, "unexpected dtype in {}, lhs: {:?}, rhs: {:?}" , op, lhs, rhs)
34+ write ! (
35+ f,
36+ "unexpected dtype in {}, lhs: {:?}, rhs: {:?}" ,
37+ op, lhs, rhs
38+ )
1939 }
2040 StorageError :: BinaryOperationShapeMismatch { lhs, rhs, op } => {
21- write ! ( f, "unexpected shape in {}, lhs: {:?}, rhs: {:?}" , op, lhs, rhs)
41+ write ! (
42+ f,
43+ "unexpected shape in {}, lhs: {:?}, rhs: {:?}" ,
44+ op, lhs, rhs
45+ )
2246 }
2347 }
2448 }
@@ -139,7 +163,11 @@ impl Storage {
139163 }
140164 }
141165
142- pub ( crate ) fn matches_device ( & self , rhs : & Self , op : & ' static str ) -> std:: result:: Result < ( ) , StorageError > {
166+ pub ( crate ) fn matches_device (
167+ & self ,
168+ rhs : & Self ,
169+ op : & ' static str ,
170+ ) -> std:: result:: Result < ( ) , StorageError > {
143171 let lhs = self . device ( ) ;
144172 let rhs = rhs. device ( ) ;
145173
@@ -150,7 +178,11 @@ impl Storage {
150178 }
151179 }
152180
153- pub ( crate ) fn matches_dtype ( & self , rhs : & Self , op : & ' static str ) -> std:: result:: Result < ( ) , StorageError > {
181+ pub ( crate ) fn matches_dtype (
182+ & self ,
183+ rhs : & Self ,
184+ op : & ' static str ,
185+ ) -> std:: result:: Result < ( ) , StorageError > {
154186 let lhs = self . dtype ( ) ;
155187 let rhs = rhs. dtype ( ) ;
156188
@@ -161,7 +193,11 @@ impl Storage {
161193 }
162194 }
163195
164- fn unary_operation < T : UnaryOperation > ( & self , shape : & Shape , stride : & [ usize ] ) -> std:: result:: Result < Self , StorageError > {
196+ fn unary_operation < T : UnaryOperation > (
197+ & self ,
198+ shape : & Shape ,
199+ stride : & [ usize ] ,
200+ ) -> std:: result:: Result < Self , StorageError > {
165201 match self {
166202 Storage :: CPU ( storage) => {
167203 let storage = storage. unary_impl :: < T > ( shape, stride) ?;
@@ -245,19 +281,35 @@ impl Storage {
245281 }
246282 }
247283
248- pub ( crate ) fn sqr ( & self , shape : & Shape , stride : & [ usize ] ) -> std:: result:: Result < Self , StorageError > {
284+ pub ( crate ) fn sqr (
285+ & self ,
286+ shape : & Shape ,
287+ stride : & [ usize ] ,
288+ ) -> std:: result:: Result < Self , StorageError > {
249289 self . unary_operation :: < Sqr > ( shape, stride)
250290 }
251291
252- pub ( crate ) fn sqrt ( & self , shape : & Shape , stride : & [ usize ] ) -> std:: result:: Result < Self , StorageError > {
292+ pub ( crate ) fn sqrt (
293+ & self ,
294+ shape : & Shape ,
295+ stride : & [ usize ] ,
296+ ) -> std:: result:: Result < Self , StorageError > {
253297 self . unary_operation :: < Sqrt > ( shape, stride)
254298 }
255299
256- pub ( crate ) fn neg ( & self , shape : & Shape , stride : & [ usize ] ) -> std:: result:: Result < Self , StorageError > {
300+ pub ( crate ) fn neg (
301+ & self ,
302+ shape : & Shape ,
303+ stride : & [ usize ] ,
304+ ) -> std:: result:: Result < Self , StorageError > {
257305 self . unary_operation :: < Neg > ( shape, stride)
258306 }
259307
260- pub ( crate ) fn transpose ( & self , shape : & Shape , stride : & [ usize ] ) -> std:: result:: Result < Self , StorageError > {
308+ pub ( crate ) fn transpose (
309+ & self ,
310+ shape : & Shape ,
311+ stride : & [ usize ] ,
312+ ) -> std:: result:: Result < Self , StorageError > {
261313 match self {
262314 Storage :: CPU ( storage) => {
263315 let storage = storage. transpose ( shape, stride) ?;
0 commit comments