@@ -212,8 +212,14 @@ def set_best_sizes(self, val=None, n_word=None, n_frac=None, max_error=1.0e-6, n
212
212
if np .iscomplexobj (val ):
213
213
val = np .array ([val .real , val .imag ])
214
214
215
+ # define numpy integer type
216
+ if self .signed :
217
+ int_dtype = np .int64
218
+ else :
219
+ int_dtype = np .uint64
220
+
215
221
# find fractional parts
216
- frac_vals = np .abs (np .subtract (val , val .astype (int ))).ravel ()
222
+ frac_vals = np .abs (np .subtract (val , val .astype (int_dtype ))).ravel ()
217
223
218
224
# n_frac estimation
219
225
if n_frac is None :
@@ -233,7 +239,7 @@ def set_best_sizes(self, val=None, n_word=None, n_frac=None, max_error=1.0e-6, n
233
239
n_frac = int (max (n_frac_calcs ))
234
240
235
241
# max raw value (integer) estimation
236
- n_int = max ( np .ceil (np .log2 (np .max (np .abs ( val * (1 << n_frac ) + 0.5 )))).astype (int ) - n_frac , 0 )
242
+ n_int = max ( np .ceil (np .log2 (np .max (np .abs ( val * (1 << n_frac ) + 0.5 )))).astype (int_dtype ) - n_frac , 0 )
237
243
238
244
# size assignement
239
245
if n_word is None :
@@ -279,11 +285,11 @@ def set_val(self, val, raw=False, vdtype=None):
279
285
if self .signed :
280
286
val_max = (1 << (self .n_word - 1 )) - 1
281
287
val_min = - val_max - 1
282
- val_dtype = 'int'
288
+ val_dtype = np . int64
283
289
else :
284
290
val_max = (1 << self .n_word ) - 1
285
291
val_min = 0
286
- val_dtype = 'uint'
292
+ val_dtype = np . uint64
287
293
288
294
# conversion factor
289
295
if raw :
@@ -330,12 +336,15 @@ def astype(self, dtype=None):
330
336
if dtype is None :
331
337
dtype = self .vdtype
332
338
333
- if dtype == float :
334
- val = self .val / 2.0 ** self .n_frac
335
- elif dtype == int or dtype == 'uint' :
336
- val = self .val .astype (dtype ) // 2 ** self .n_frac
337
- elif dtype == complex :
338
- val = (self .val .real + 1j * self .val .imag ) / 2.0 ** self .n_frac
339
+ if self .val is not None :
340
+ if dtype == float or np .issubdtype (dtype , np .floating ):
341
+ val = self .val / 2.0 ** self .n_frac
342
+ elif dtype == int or dtype == 'uint' or dtype == 'int' or np .issubdtype (dtype , np .integer ):
343
+ val = self .val .astype (dtype ) // 2 ** self .n_frac
344
+ elif dtype == complex or np .issubdtype (dtype , np .complexfloating ):
345
+ val = (self .val .real + 1j * self .val .imag ) / 2.0 ** self .n_frac
346
+ else :
347
+ val = self .val / 2.0 ** self .n_frac
339
348
else :
340
349
val = None
341
350
@@ -541,14 +550,14 @@ def __pow__(self, n):
541
550
n_word = self .n_word * n
542
551
n_frac = self .n_frac * n
543
552
544
- y = Fxp (self .get_val () ** n , signed = self .signed or x .signed , n_word = n_word , n_frac = n_frac )
553
+ y = Fxp (self .get_val () ** n , signed = self .signed or n .signed , n_word = n_word , n_frac = n_frac )
545
554
return y
546
555
547
556
def __rpow__ (self , n ):
548
557
n_word = self .n_word * n
549
558
n_frac = self .n_frac * n
550
559
551
- y = Fxp (n ** self .get_val (), signed = self .signed or x .signed , n_word = n_word , n_frac = n_frac )
560
+ y = Fxp (n ** self .get_val (), signed = self .signed or n .signed , n_word = n_word , n_frac = n_frac )
552
561
return y
553
562
554
563
__ipow__ = __pow__
@@ -565,7 +574,7 @@ def __rshift__(self, n):
565
574
566
575
def __lshift__ (self , n ):
567
576
if self .shifting == 'expand' :
568
- n_word = max (self .n_word , np .ceil (np .log2 (np .abs (self .val )+ 0.5 )). astype ( int ) + self .signed + n )
577
+ n_word = max (self .n_word , int ( np .max ( np . ceil (np .log2 (np .abs (self .val )+ 0.5 ))) ) + self .signed + n )
569
578
else :
570
579
n_word = self .n_word
571
580
0 commit comments