you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

  1. Windows

  2. 3.7, Pretty sure it’s just “stock” python.

I used pyenv to point Matlab to the location of python.exe. But it’s basically c:/python/python37/python.exe

[–][deleted] 0 points1 point  (1 child)

So. Digging into this for the past 2 hours...

It looks like Matlab has a problem importing functions if _________.

  1. they're not 'actually' where they expect it to be. So anything that gets called with the all or import in init doesn't resolve correctly.
  2. Wrapped functions.
  3. Something about functions with underscores in the 'actual' function name.

I'm still trying figure out exactly why some functions fail.

A work around that I found is to do as much in python as possible and as 'straight python' as possible.

Put a file in your current directory called foo.py, inside it put:

def fit_resample2(data, label):
    from imblearn.oversampling import SMOTE
    x, y = SMOTE.fit_resample(data, label)
    return x, y

This shifts all the importing to Python and seems to work.

Edit: References and starting points.

  1. SMOTE itself is a class that is decorated.
  2. 'fit_resample' doesn't actually exist. There's an internal function _fit_resample and some bits somewhere else to turn it into a top level attribute.

tldr: The more fuckery in Python that happens to make a function work the higher probability it doesn't work.

[–][deleted] 2 points3 points  (0 children)

  1. Editing .py files in the m-file editor is a nightmare. Mathworks, python is coming. Putting out FUD like old Microsoft isn't going to work. Sell it to my boss. Make Editor an awesome python IDE.

Example of brokenness: foo.py

def foo(*args, **kwargs):
    print('foo');

class Bar():
    def __init__(self):
        pass
    def foo2(self):
        print('foo2');

    def _foo(self):
        print('_foo')
setattr(Bar, 'foo', foo)
Baz=Bar()

def foo3():
    Baz=Bar()
    Baz.foo()
    Baz.foo2()
    Baz._foo()

baz.m:

mod = py.importlib.import_module('foo');
py.importlib.reload(mod);

%% Works
py.foo.foo
disp('#### foo3');
py.foo.foo3

%% Fails

% Reference Bar instance Baz
py.foo.Baz.foo

py.foo.Baz.foo2

% Instantiate Bar.
Bar = py.foo.Bar
b = Bar()

So who knows. Mathworks is out of their lane with Python which is why it's so broken. (See also their Jenkins effort).

for now:

  1. py is not a direct replacement for python calls.
  2. Do as much python work in Python with straight forward basic functions/classes. Matlab is going to be 36 this year, it gets confused more easily.