Skip to content

Conversation

@tbaudier
Copy link
Contributor

https://discourse.itk.org/t/torch-import-time/6354

Torch takes time to import. In types.py torch is imported to check if it's present or not in the environment, but it's never used.

Now, torch is detected with importlib.metadata.

PR Checklist

  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)
  • Updated API documentation (or API not changed)
  • Added license to new files (if any)
  • Added Python wrapping to new files (if any) as described in ITK Software Guide Section 9.5
  • Added ITK examples for all new major features (if any)

Refer to the ITK Software Guide for
further development details if necessary.

@github-actions github-actions bot added type:Performance Improvement in terms of compilation or execution time area:Python wrapping Python bindings for a class labels Dec 14, 2023
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for contributing a pull request! 🙏

Welcome to the ITK community! 🤗👋☀️

We are glad you are here and appreciate your contribution. Please keep in mind our community participation guidelines. 📜
More support and guidance on the contribution process can be found in our contributing guide. 📖

This is an automatic message. Allow for time for the ITK community to be able to read the pull request and comment
on it.

Copy link
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

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

@tbaudier thank you for the contribution! 🙏

Please see a comment inline that could help with the CI failures.

Could also please apply the same method to the other packages in the same file?

https://discourse.itk.org/t/torch-import-time/6354
Torch takes time to import. In types.py torch is imported
to check if it's present or not in the environment, but
it's never used.
Now, torch is detected with importlib.metadata and imported
later.

Do the same thing with xarray
@tbaudier
Copy link
Contributor Author

Sorry, I committed the src files but my modified files were in the built folder. Now it's ok.

I tested this code and it worked well:

import torch
import numpy as np
a = np.random.rand(10,10)
t = torch.from_numpy(a)
smoothed = itk.median_image_filter(a, radius=2)

According to your advise, I did the modification for xarray too but I did not test it.

For numpy ArrayType, I changed anything because it seems that metadata does not work with submodules

Copy link
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

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

@tbaudier thank you!

@thewtex thewtex merged commit 29d4f98 into InsightSoftwareConsortium:master Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Python wrapping Python bindings for a class type:Performance Improvement in terms of compilation or execution time

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants