########################################################################### # ALGLIB 3.11.0 (source code generated 2017-05-11) # Copyright (c) Sergey Bochkanov (ALGLIB project). # # >>> SOURCE LICENSE >>> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation (www.fsf.org); either version 2 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # A copy of the GNU General Public License is available at # http://www.fsf.org/licensing/licenses # >>> END OF LICENSE >>> ########################################################################## import sys import os import clr import System DT_BOOL = 1 DT_INT = 2 DT_REAL = 3 DT_COMPLEX = 4 X_SET = 1 # data are copied into x-vector/matrix; previous contents of x-structure is freed X_CREATE = 2 # x-vector/matrix is created, its previous contents is ignored X_REWRITE = 3 # data are copied into x-structure; size of Python structure must be equal to the x-structure size curdir = os.path.dirname(__file__) if curdir=="": curdir = "." _net_candidates = [] _net_candidates.append(os.path.join(os.path.relpath(curdir),"alglibnet2.dll")) _net_candidates.append(os.path.join(sys.prefix,"alglibnet2.dll")) _net_candidates.append(os.path.join(os.sep+"usr","local","alglibnet2.dll")) for _candidate in _net_candidates: if os.path.isfile(_candidate): clr.AddReferenceToFileAndPath(_candidate) import alglib as _net_alglib break def xsign(val): if val<0.0: return -1.0 if val>0.0: return +1.0 return 0.0 def setnworkers(nworkers): _net_alglib.setnworkers(nworkers) # # Checks that all values from list V are equal and returns first one. # In case they are not equal, this function throws RuntimeError with message MSG. # def check_equality_and_get(v,msg): cnt = len(v) r = v[0] i = 1 while i0: cols = len(v[0]) else: cols = 0 if cols==0: rows = 0 # # allocation # if dt==DT_BOOL: x = System.Array.CreateInstance(bool, rows, cols) if dt==DT_INT: x = System.Array.CreateInstance(int, rows, cols) if dt==DT_REAL: x = System.Array.CreateInstance(float, rows, cols) if dt==DT_COMPLEX: x = System.Array.CreateInstance(_net_alglib.complex, rows, cols) # # copy # copy_listlist_to_net(v, x, dt) return x # # conversion from .NET vector to Python vector # # Parameters: # * x .NET vector # * dt datatype code # def list_from_net(x, dt): cnt = x.GetLength(0) if cnt==0: return [] r = [0]*cnt if dt==DT_COMPLEX: i = 0 while i0: cols = len(v[0]) else: cols = 0 if cols==0: rows = 0 # # copy # i = 0 while i