kwgoodman / la

Meet larry, the labeled numpy array
http://pypi.python.org/pypi/la
Other
44 stars 20 forks source link

Avoid extra copy in larry.astype #52

Closed kwgoodman closed 12 years ago

kwgoodman commented 12 years ago

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