np.around(x).astype(int)and x.astype(int)do not give the same values. The first rounds are even (this is the same as ((x*x>=0+0.5) + (x*x<0-0.5)).astype(int)), while the last rounds are rounded to zero. Nonetheless,
y = np.trunc(x).astype(int)
z = x.astype(int)
shows y==z, but the calculation yis much slower. So functions np.truncand are np.aroundslow.
In [165]: x.dtype
Out[165]: dtype('float64')
In [168]: y.dtype
Out[168]: dtype('int64')
So np.trunc(x)rounds to zero from double to double. Then astype(int)should convert double to int64.
Internally, I don't know what python or numpy do, but I know how to do it in C. Let me discuss some hardware. With SSE4.1 you can do round, full, ceiling and trunc with double double use:
_mm_round_pd(a, 0);
_mm_round_pd(a, 1);
_mm_round_pd(a, 2);
_mm_round_pd(a, 3);
numpy SSE4.1, SSE4.1, SSE4.1, .
double int64 SSE/AVX AVX512. , double int32 , SSE2:
_mm_cvtpd_epi32(a); //round double to int32 then expand to int64
_mm_cvttpd_epi32(a); //trunc double to int32 then expand to int64
int64.
, , , int32. python , int32, , trunc int64, . , numpy SSE2, .
, , . :
_mm_cvtps_epi32(a);
_mm_cvttps_epi32(a)
int32.
, , SSE2 double int32 . AVX512 int64 , _mm512_cvtpd_epi64(a) _mm512_cvttpd_epi64(a). SSE4.1 round/trunc/floor/ceil float float double, .