Avoid extra copy in larry.astype #52

Closed
kwgoodman opened this Issue Mar 8, 2012 · 0 comments

Projects

None yet

1 participant

@kwgoodman
Owner

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
@kwgoodman kwgoodman added a commit that closed this issue Mar 8, 2012
@kwgoodman ENH larry.astype() is faster.
Closes #52.
cfeb7af
@kwgoodman kwgoodman closed this in cfeb7af Mar 8, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment