kwgoodman/la — Issue #52: Avoid extra copy in larry.astype
Author: kwgoodman
Created: 2012-03-08 20:32:57+00:00
State: open

Current larry.astype:

y = self.copy()
y.x = y.x.astype(dtype)
return y

Proposed:

label = self.copylabel()
x = self.x.astype(dtype)
return larry(x, label, validate=False)

Current:

I[1] lar = la.rand(1000, 1000)
I[2] lar.dtype
O[2] dtype('float64')
I[3] timeit lar.astype(np.float32)
1000 loops, best of 3: 1.57 ms per loop

Proposed:

I[1] lar = la.rand(1000, 1000)
I[2] timeit lar.astype(np.float32)
1000 loops, best of 3: 766 us per loop