Repository navigation
Configure densification. - #210
Conversation
Codecov Report
@@ Coverage Diff @@
## master #210 +/- ##
==========================================
+ Coverage 97.66% 97.67% +<.01%
==========================================
Files 11 11
Lines 1502 1505 +3
==========================================
+ Hits 1467 1470 +3
Misses 35 35
Continue to review full report at Codecov.
|
| import os | ||
|
|
||
| _AUTO_DENSIFICATION_ENABLED = bool(int(os.environ.get('SPARSE_AUTO_DENSIFY', '1'))) | ||
|
|
There was a problem hiding this comment.
I would also add
def set_auto_densify(flag):
"""
Enable or disable automatic densification
By default it is enabled, unless the environment variable ``SPARSE_AUTO_DENSIFY`` is ``0``.
If automatic densification is disabled, calls like ``np.array(COO)`` will raise ``RuntimeError``.
"""
global _AUTO_DENSIFICATION_ENABLED
_AUTO_DENSIFICATION_ENABLED = flagThere was a problem hiding this comment.
The problem is that that isn't thread safe. For example, if you do it with Dask or whatever else, it can blow stuff up.
An environment variable loaded at import time is guaranteed to be thread safe.
There was a problem hiding this comment.
Can we add a warning to the function that it isn't thread safe. I think if it is only called right after import it should be fine too.
There was a problem hiding this comment.
I'm worried about exactly the use-case you describe, too. :-) Libraries setting this option and users getting confused about what's happening, unfortunately there's no clear way to make it user facing but not library facing.
There was a problem hiding this comment.
unfortunately there's no clear way to make it user facing but not library facing.
That's in the same category as numpy.set_printoptions, np.seterr, private class attributes, etc. - just don't mess with it as a library. It doesn't happen a lot, and if it does the first person who notices files a bug against that library.
|
Someone pulled out Dask's config system into a separate package.
https://github.com/pytroll/donfig
If we need more configuration in the future it might be worth considering.
https://docs.dask.org/en/latest/configuration.html
…On Tue, Nov 20, 2018 at 4:47 AM Hameer Abbasi ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In sparse/__init__.py
<#210 (comment)>:
> @@ -7,3 +7,9 @@
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
+
+import os
+
+_AUTO_DENSIFICATION_ENABLED = bool(int(os.environ.get('SPARSE_AUTO_DENSIFY', '1')))
+
The problem is that that isn't thread safe. For example, if you do it with
Dask or whatever else, it can blow stuff up.
An environment variable loaded at import time is guaranteed to be thread
safe.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#210 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszDT6fLc_pylLqjFvzbekjyPyGiUJks5uw8-WgaJpZM4Yp7CW>
.
|
Add an environment variable to allow configuration of densification.