@@ -163,6 +163,24 @@ def __mul__(self, other: _NadaOperand) -> "NadaArray":
163
163
return NadaArray (self .inner * Integer (other ))
164
164
return NadaArray (self .inner * other )
165
165
166
+ def __pow__ (self , other : int ) -> "NadaArray" :
167
+ """Raises NadaArray to a power.
168
+
169
+ Args:
170
+ other (int): Power value.
171
+
172
+ Returns:
173
+ NadaArray: Result NadaArray.
174
+ """
175
+ if not isinstance (other , int ):
176
+ raise TypeError (
177
+ "Cannot raise `NadaArray` to power of type `%s`" % type (other ).__name__
178
+ )
179
+ result = self .copy ()
180
+ for _ in range (other - 1 ):
181
+ result = result * result
182
+ return result
183
+
166
184
def __truediv__ (self , other : _NadaOperand ) -> "NadaArray" :
167
185
"""
168
186
Perform element-wise division with broadcasting.
@@ -189,8 +207,11 @@ def __matmul__(self, other: "NadaArray") -> "NadaArray":
189
207
Returns:
190
208
NadaArray: A new NadaArray representing the result of matrix multiplication.
191
209
"""
192
- if isinstance (other , NadaArray ):
193
- return NadaArray (self .inner @ other .inner )
210
+ return NadaArray (self .inner @ other .inner )
211
+
212
+ @property
213
+ def ndim (self ) -> int :
214
+ return len (self .shape )
194
215
195
216
def dot (self , other : "NadaArray" ) -> "NadaArray" :
196
217
"""
@@ -295,10 +316,17 @@ def output_array(array: np.ndarray, party: Party, prefix: str) -> list:
295
316
),
296
317
):
297
318
return [Output (array , f"{ prefix } _0" , party )]
319
+ elif isinstance (array , (Rational , SecretRational )):
320
+ return [Output (array .value , f"{ prefix } _0" , party )]
298
321
299
322
if len (array .shape ) == 1 :
300
323
return [
301
- Output (array [i ], f"{ prefix } _{ i } " , party ) for i in range (array .shape [0 ])
324
+ (
325
+ Output (array [i ].value , f"{ prefix } _{ i } " , party )
326
+ if isinstance (array [i ], (Rational , SecretRational ))
327
+ else Output (array [i ], f"{ prefix } _{ i } " , party )
328
+ )
329
+ for i in range (array .shape [0 ])
302
330
]
303
331
return [
304
332
v
0 commit comments