Skip to content

Commit 56e6362

Browse files
committed
changes
1 parent af8a86a commit 56e6362

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

ratapi/matlab.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

ratapi/wrappers.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
"""Wrappers for the interface between ratapi and MATLAB custom files."""
1+
"""Wrappers for the interface between RATapi and MATLAB custom files."""
22

3+
import os
34
import pathlib
45
from contextlib import suppress
56
from typing import Callable
67

78
import numpy as np
89
from numpy.typing import ArrayLike
910

10-
import ratapi.rat_core
11+
import RATapi.rat_core
1112

1213

1314
def start_matlab():
@@ -20,10 +21,10 @@ def start_matlab():
2021
2122
"""
2223
future = None
23-
with suppress(ImportError):
24-
import matlab.engine
25-
26-
future = matlab.engine.start_matlab(background=True)
24+
if os.environ.get("DELAY_MATLAB_START", '0') == '0':
25+
with suppress(ImportError):
26+
import matlab.engine
27+
future = matlab.engine.start_matlab(background=True)
2728

2829
return future
2930

@@ -86,6 +87,22 @@ def handle(*args):
8687
return handle
8788

8889

90+
def use_shared_matlab(name, custom_error=""):
91+
"""Start MATLAB asynchronously and returns a future to retrieve the engine later.
92+
93+
Returns
94+
-------
95+
future : matlab.engine.futureresult.FutureResult
96+
A future used to get the actual matlab engine.
97+
98+
"""
99+
with suppress(ImportError):
100+
import matlab.engine
101+
102+
MatlabWrapper.loader = matlab.engine.connect_matlab(name, background=True)
103+
return MatlabWrapper.loader
104+
105+
89106
class DylibWrapper:
90107
"""Creates a python callback for a function in dynamic library.
91108
@@ -99,7 +116,7 @@ class DylibWrapper:
99116
"""
100117

101118
def __init__(self, filename, function_name) -> None:
102-
self.engine = ratapi.rat_core.DylibEngine(filename, function_name)
119+
self.engine = RATapi.rat_core.DylibEngine(filename, function_name)
103120

104121
def getHandle(self) -> Callable[[ArrayLike, ArrayLike, ArrayLike, int, int], tuple[ArrayLike, float]]:
105122
"""Return a wrapper for the custom dynamic library function.

0 commit comments

Comments
 (0)