Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster set_data() #109

Merged
merged 1 commit into from
Jan 16, 2021
Merged

Faster set_data() #109

merged 1 commit into from
Jan 16, 2021

Conversation

alexander-g
Copy link
Contributor

  • Modified Tensor.set_data() to directly accept a numpy array. Previously arrays were implicitly converted to lists which is slow
  • Simplified .numpy() which also results in a small performance boost

@axsaucedo
Copy link
Member

This is great @alexander-g !

@axsaucedo axsaucedo self-requested a review January 16, 2021 14:25
strides
));
.def("numpy", [](kp::Tensor& self) {
return py::array(self.data().size(), self.data().data());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, really interesting, I didn't know it could be simplified, looks good

const py::array_t<float> flatdata = np.attr("ravel")(data);
const py::buffer_info info = flatdata.request();
const float* ptr = (float*) info.ptr;
self.setData(std::vector<float>(ptr, ptr+flatdata.size()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

@axsaucedo axsaucedo added enhancement New feature or request python labels Jan 16, 2021
@axsaucedo axsaucedo merged commit 2382e63 into KomputeProject:master Jan 16, 2021
@alexander-g alexander-g deleted the set_data branch January 17, 2021 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants