def __init__(self, gams_dir=None, lazy_load=True): """ Initializes a GdxFile object by connecting to GAMS and creating a pointer. Throws a GdxError if either of those operations fail. """ self.lazy_load = lazy_load self._version = None self._producer = None self._filename = None self._symbols = OrderedDict() NeedsGamsDir.__init__(self, gams_dir=gams_dir) self._H = self._create_gdx_object() self.universal_set = GdxSymbol('*', GamsDataType.Set, dims=1, file=None, index=0) self.universal_set._file = self # get special values self.special_values = gdxcc.doubleArray(gdxcc.GMS_SVIDX_MAX) gdxcc.gdxGetSpecialValues(self.H, self.special_values) self.gdx_to_np_svs = {} self.np_to_gdx_svs = {} for i in range(gdxcc.GMS_SVIDX_MAX): if i >= len(NUMPY_SPECIAL_VALUES): break gdx_val = self.special_values[i] self.gdx_to_np_svs[gdx_val] = NUMPY_SPECIAL_VALUES[i] self.np_to_gdx_svs[i] = gdx_val atexit.register(self.cleanup) return
def load_specials(gams_dir_finder): """ Load special values Needs to be called after gdxcc is loaded. Populates the module attributes SPECIAL_VALUES, GDX_TO_NP_SVS, and NP_TO_GDX_SVS. Parameters ---------- gams_dir_finder : :class:`gdxpds.tools.GamsDirFinder` """ global SPECIAL_VALUES global GDX_TO_NP_SVS global NP_TO_GDX_SVS H = gdxcc.new_gdxHandle_tp() rc = gdxcc.gdxCreateD(H, gams_dir_finder.gams_dir, gdxcc.GMS_SSSIZE) if not rc: raise Exception(rc[1]) # get special values special_values = gdxcc.doubleArray(gdxcc.GMS_SVIDX_MAX) gdxcc.gdxGetSpecialValues(H, special_values) SPECIAL_VALUES = [] GDX_TO_NP_SVS = {} NP_TO_GDX_SVS = {} for i in range(gdxcc.GMS_SVIDX_MAX): if i >= len(NUMPY_SPECIAL_VALUES): break SPECIAL_VALUES.append(special_values[i]) gdx_val = special_values[i] GDX_TO_NP_SVS[gdx_val] = NUMPY_SPECIAL_VALUES[i] NP_TO_GDX_SVS[NUMPY_SPECIAL_VALUES[i]] = gdx_val gdxcc.gdxFree(H)