@@ -63,6 +63,71 @@ impl OrtexTensor {
6363 }
6464 }
6565
66+ pub fn reshape ( & self , shape : Vec < usize > ) -> rustler:: NifResult < Self > {
67+ match self {
68+ OrtexTensor :: s8( y) => {
69+ Ok ( OrtexTensor :: s8 ( y. clone ( ) . into_shape ( shape) . map_err (
70+ |e| rustler:: Error :: Term ( Box :: new ( e. to_string ( ) ) ) ,
71+ ) ?) )
72+ }
73+ OrtexTensor :: s16( y) => {
74+ Ok ( OrtexTensor :: s16 ( y. clone ( ) . into_shape ( shape) . map_err (
75+ |e| rustler:: Error :: Term ( Box :: new ( e. to_string ( ) ) ) ,
76+ ) ?) )
77+ }
78+ OrtexTensor :: s32( y) => {
79+ Ok ( OrtexTensor :: s32 ( y. clone ( ) . into_shape ( shape) . map_err (
80+ |e| rustler:: Error :: Term ( Box :: new ( e. to_string ( ) ) ) ,
81+ ) ?) )
82+ }
83+ OrtexTensor :: s64( y) => {
84+ Ok ( OrtexTensor :: s64 ( y. clone ( ) . into_shape ( shape) . map_err (
85+ |e| rustler:: Error :: Term ( Box :: new ( e. to_string ( ) ) ) ,
86+ ) ?) )
87+ }
88+ OrtexTensor :: u8( y) => {
89+ Ok ( OrtexTensor :: u8 ( y. clone ( ) . into_shape ( shape) . map_err (
90+ |e| rustler:: Error :: Term ( Box :: new ( e. to_string ( ) ) ) ,
91+ ) ?) )
92+ }
93+ OrtexTensor :: u16( y) => {
94+ Ok ( OrtexTensor :: u16 ( y. clone ( ) . into_shape ( shape) . map_err (
95+ |e| rustler:: Error :: Term ( Box :: new ( e. to_string ( ) ) ) ,
96+ ) ?) )
97+ }
98+ OrtexTensor :: u32( y) => {
99+ Ok ( OrtexTensor :: u32 ( y. clone ( ) . into_shape ( shape) . map_err (
100+ |e| rustler:: Error :: Term ( Box :: new ( e. to_string ( ) ) ) ,
101+ ) ?) )
102+ }
103+ OrtexTensor :: u64( y) => {
104+ Ok ( OrtexTensor :: u64 ( y. clone ( ) . into_shape ( shape) . map_err (
105+ |e| rustler:: Error :: Term ( Box :: new ( e. to_string ( ) ) ) ,
106+ ) ?) )
107+ }
108+ OrtexTensor :: f16( y) => {
109+ Ok ( OrtexTensor :: f16 ( y. clone ( ) . into_shape ( shape) . map_err (
110+ |e| rustler:: Error :: Term ( Box :: new ( e. to_string ( ) ) ) ,
111+ ) ?) )
112+ }
113+ OrtexTensor :: bf16( y) => {
114+ Ok ( OrtexTensor :: bf16 ( y. clone ( ) . into_shape ( shape) . map_err (
115+ |e| rustler:: Error :: Term ( Box :: new ( e. to_string ( ) ) ) ,
116+ ) ?) )
117+ }
118+ OrtexTensor :: f32( y) => {
119+ Ok ( OrtexTensor :: f32 ( y. clone ( ) . into_shape ( shape) . map_err (
120+ |e| rustler:: Error :: Term ( Box :: new ( e. to_string ( ) ) ) ,
121+ ) ?) )
122+ }
123+ OrtexTensor :: f64( y) => {
124+ Ok ( OrtexTensor :: f64 ( y. clone ( ) . into_shape ( shape) . map_err (
125+ |e| rustler:: Error :: Term ( Box :: new ( e. to_string ( ) ) ) ,
126+ ) ?) )
127+ }
128+ }
129+ }
130+
66131 pub fn dtype ( & self ) -> ( Atom , usize ) {
67132 match self {
68133 OrtexTensor :: s8( _) => ( ortex_atoms:: s ( ) , 8 ) ,
0 commit comments