-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from gmrukwa/develop
Release 2.3.8
- Loading branch information
Showing
76 changed files
with
6,236 additions
and
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# Git | ||
.git/ | ||
|
||
# PyCharm | ||
.idea/ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# dotenv | ||
.env | ||
|
||
# virtualenv | ||
.venv | ||
venv/ | ||
ENV/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
# local tests | ||
data.csv | ||
xy.csv | ||
result |
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 |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
pip install --no-cache-dir -r requirements.txt | ||
|
||
python setup.py sdist bdist_wheel | ||
python setup.py sdist | ||
|
||
ls dist |
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,22 @@ | ||
"""This just builds the native extension for testing purposes""" | ||
|
||
from glob import glob | ||
from setuptools import setup, Extension | ||
import numpy | ||
|
||
setup( | ||
packages=[], | ||
# @gmrukwa: https://packaging.python.org/discussions/install-requires-vs-requirements/ | ||
install_requires=[ | ||
'numpy>=0.12.1', | ||
], | ||
python_requires='>=3.5,<=3.7', | ||
ext_modules=[ | ||
Extension('gamred_native', | ||
sources=glob('gamred_native/*.c'), | ||
include_dirs=['gamred_native', numpy.get_include()], | ||
define_macros=[ | ||
('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION'), | ||
]), | ||
], | ||
) |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__version__ = '2.3.6' | ||
__version__ = '2.3.8' | ||
|
||
from ._seeding import seeded | ||
from ._utils import DivikResult | ||
|
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 |
---|---|---|
@@ -1,102 +1,34 @@ | ||
"""Access to MATLAB legacy functionalities.""" | ||
|
||
from contextlib import contextmanager | ||
import logging | ||
import os | ||
import platform | ||
import warnings | ||
|
||
import gamred_native as gn | ||
import numpy as np | ||
|
||
|
||
# noinspection SpellCheckingInspection | ||
_MATLAB_SEARCH_PATHS = \ | ||
"/usr/local/MATLAB/MATLAB_Runtime/v96/runtime/glnxa64:" + \ | ||
"/usr/local/MATLAB/MATLAB_Runtime/v96/bin/glnxa64:" + \ | ||
"/usr/local/MATLAB/MATLAB_Runtime/v96/sys/os/glnxa64:" + \ | ||
"/usr/local/MATLAB/MATLAB_Runtime/v96/extern/bin/glnxa64:" | ||
|
||
|
||
_local_system = platform.system() | ||
|
||
if _local_system == 'Windows': | ||
# Must be here. Doesn't work as contextmanager. | ||
# If you think different increase counter of wasted hours: 4 | ||
os.environ['PATH'] = os.environ['PATH'].lower() | ||
|
||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
@contextmanager | ||
def _matlab_paths(): | ||
if _local_system == 'Linux': | ||
_logger.log(logging.INFO, 'Modifying LD_LIBRARY_PATH.') | ||
old_env = os.environ.get('LD_LIBRARY_PATH', '') | ||
os.environ['LD_LIBRARY_PATH'] = _MATLAB_SEARCH_PATHS + old_env | ||
_logger.log(logging.INFO, os.environ['LD_LIBRARY_PATH']) | ||
elif _local_system == 'Darwin': | ||
raise NotImplementedError('OSX hosts are not supported.') | ||
try: | ||
yield | ||
finally: | ||
if _local_system == 'Linux': | ||
_logger.log(logging.INFO, 'Restoring LD_LIBRARY_PATH.') | ||
# noinspection PyUnboundLocalVariable | ||
os.environ['LD_LIBRARY_PATH'] = old_env | ||
_logger.log(logging.INFO, os.environ['LD_LIBRARY_PATH']) | ||
|
||
|
||
_engine = None | ||
|
||
|
||
def _ensure_engine(): | ||
global _engine | ||
if _engine is None: | ||
with _matlab_paths(): | ||
import MatlabAlgorithms.MsiAlgorithms | ||
# noinspection PyPackageRequirements | ||
import matlab | ||
_engine = MatlabAlgorithms.MsiAlgorithms.initialize() | ||
return _engine | ||
|
||
|
||
class MatlabError(Exception): | ||
"""Thrown when legacy computations failed.""" | ||
|
||
pass | ||
def find_thresholds(values: np.ndarray, max_components: int = 10) \ | ||
-> np.ndarray: | ||
"""Find candidate thresholds for decomposition of values by GMM. | ||
Parameters | ||
---------- | ||
values: | ||
vector of values to decompose | ||
def find_thresholds(values: np.ndarray, max_components: int = 10, | ||
throw_on_engine_error: bool = True) -> np.ndarray: | ||
"""Find candidate thresholds for decomposition of values by GMM. | ||
max_components: | ||
maximal number of components to decompose into | ||
@param values: vector of values to decompose | ||
@param max_components: maximal number of components to decompose into | ||
@param throw_on_engine_error: if true, an exception will be raised if | ||
legacy code fails. Returns empty thresholds array otherwise. | ||
@return: array of candidate thresholds from crossings between GMM | ||
components | ||
Returns | ||
------- | ||
array of candidate thresholds from crossings between GMM components | ||
""" | ||
with _matlab_paths(): | ||
engine = _ensure_engine() | ||
# noinspection PyUnresolvedReferences | ||
import MatlabAlgorithms.MsiAlgorithms | ||
# noinspection PyPackageRequirements | ||
import matlab | ||
with warnings.catch_warnings(): | ||
warnings.simplefilter("ignore") | ||
values = matlab.double([[element] for element in values.ravel()]) | ||
try: | ||
thresholds = engine.fetch_thresholds(values, | ||
'MaxComponents', | ||
float(max_components), | ||
'DisableWarnings', | ||
True, | ||
nargout=1) | ||
except Exception as ex: | ||
if throw_on_engine_error: | ||
raise MatlabError() from ex | ||
else: | ||
return np.array([]) | ||
return np.array(thresholds).ravel() | ||
if values.size <= max_components: | ||
max_components = values.size | ||
if values.size == 0: | ||
return np.array([]) | ||
if max_components <= 0: | ||
raise ValueError("max_components must be positive") | ||
if values.ndim != 1: | ||
raise ValueError("values must be 1D array") | ||
values = np.ascontiguousarray(values) | ||
offset = np.min(values) | ||
if np.min(values) == np.max(values): | ||
return np.array([]) | ||
return gn.find_thresholds(values - offset, max_components) + offset |
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
Oops, something went wrong.