(self, X, out, *args, **kwargs)
| 24 | self.engine = None |
| 25 | |
| 26 | def _evaluate(self, X, out, *args, **kwargs): |
| 27 | |
| 28 | # if the matlab engine has not been started yet do this now |
| 29 | if self.engine is None: |
| 30 | # prepare the folder where the matlab files are |
| 31 | folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'code') |
| 32 | |
| 33 | # get the engine ready to start |
| 34 | eng = MatlabEngine.get_instance() |
| 35 | |
| 36 | # change directory to be able to execute the files |
| 37 | eng.cd(folder, nargout=0) |
| 38 | |
| 39 | # this can be used to initialize variables or load data if necessary - only called once |
| 40 | eng._initialize(nargout=0) |
| 41 | |
| 42 | # store it in the object |
| 43 | self.engine = eng |
| 44 | |
| 45 | eng = self.engine |
| 46 | |
| 47 | # convert the input to a matlab readable format |
| 48 | mat_X = matlab.double(X.tolist()) |
| 49 | |
| 50 | # execute the matlab function and take what is returned |
| 51 | if not self.has_constraints(): |
| 52 | mat_F = eng.evaluate(mat_X, nargout=1) |
| 53 | out["F"] = np.array(mat_F) |
| 54 | else: |
| 55 | mat_F, mat_G = eng.evaluate(mat_X, nargout=2) |
| 56 | out["F"], out["G"] = np.array(mat_F), np.array(mat_G) |
| 57 | |
| 58 | |
| 59 | if __name__ == '__main__': |
nothing calls this directly
no test coverage detected