Alien-XGBoost
view release on metacpan or search on metacpan
xgboost/rabit/python/rabit.py view on Meta::CPAN
"""
Reliable Allreduce and Broadcast Library.
Author: Tianqi Chen
"""
# pylint: disable=unused-argument,invalid-name,global-statement,dangerous-default-value,
import cPickle as pickle
import ctypes
import os
import sys
import warnings
import numpy as np
# version information about the doc
__version__ = '1.0'
_LIB = None
def _find_lib_path(dll_name):
"""Find the rabit dynamic library files.
Returns
-------
lib_path: list(string)
List of all found library path to rabit
"""
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
# make pythonpack hack: copy this directory one level upper for setup.py
dll_path = [curr_path,
os.path.join(curr_path, '../lib/'),
os.path.join(curr_path, './lib/')]
if os.name == 'nt':
dll_path = [os.path.join(p, dll_name) for p in dll_path]
else:
dll_path = [os.path.join(p, dll_name) for p in dll_path]
lib_path = [p for p in dll_path if os.path.exists(p) and os.path.isfile(p)]
#From github issues, most of installation errors come from machines w/o compilers
if len(lib_path) == 0 and not os.environ.get('XGBOOST_BUILD_DOC', False):
raise RuntimeError(
'Cannot find Rabit Libarary in the candicate path, ' +
'did you install compilers and run build.sh in root path?\n'
'List of candidates:\n' + ('\n'.join(dll_path)))
return lib_path
# load in xgboost library
def _loadlib(lib='standard', lib_dll=None):
"""Load rabit library."""
global _LIB
if _LIB is not None:
warnings.warn('rabit.int call was ignored because it has'\
' already been initialized', level=2)
return
if lib_dll is not None:
_LIB = lib_dll
return
if lib == 'standard':
dll_name = 'librabit'
else:
dll_name = 'librabit_' + lib
if os.name == 'nt':
dll_name += '.dll'
else:
dll_name += '.so'
_LIB = ctypes.cdll.LoadLibrary(_find_lib_path(dll_name)[0])
_LIB.RabitGetRank.restype = ctypes.c_int
_LIB.RabitGetWorldSize.restype = ctypes.c_int
_LIB.RabitVersionNumber.restype = ctypes.c_int
def _unloadlib():
"""Unload rabit library."""
global _LIB
del _LIB
_LIB = None
# reduction operators
MAX = 0
MIN = 1
SUM = 2
BITOR = 3
def init(args=None, lib='standard', lib_dll=None):
"""Intialize the rabit module, call this once before using anything.
( run in 0.603 second using v1.01-cache-2.11-cpan-5b529ec07f3 )