-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix circular import to allow importing models and metrics directly (#56)
Previously if you tried importing model classes (models.py) or metric classes (metrics.py) directly in your third party code, you would get a circular import error. This PR reorganizes some files to fix that issue. Co-authored-by: Safoora Yousefi <[email protected]>
- Loading branch information
Showing
49 changed files
with
247 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import json | ||
import base64 | ||
import numpy as np | ||
|
||
class NumpyEncoder(json.JSONEncoder): | ||
"""Special json encoder for numpy types""" | ||
|
||
def default(self, obj): | ||
if isinstance( | ||
obj, | ||
( | ||
np.int_, | ||
np.intc, | ||
np.intp, | ||
np.int8, | ||
np.int16, | ||
np.int32, | ||
np.int64, | ||
np.uint8, | ||
np.uint16, | ||
np.uint32, | ||
np.uint64, | ||
), | ||
): | ||
return int(obj) | ||
elif isinstance(obj, (np.float_, np.float16, np.float32, np.float64)): | ||
return float(obj) | ||
elif isinstance(obj, (np.ndarray,)): | ||
return obj.tolist() | ||
elif isinstance(obj, bytes): | ||
return base64.b64encode(obj).decode("ascii") | ||
return json.JSONEncoder.default(self, obj) |
Oops, something went wrong.