コード例 #1
0
    def __init__(self, size, init_value=None):
        '''Constructor for syncing array-like (one-dimensional) value.

        The `size` should be a int equal to the size of value we want to sync.
        If init_value is None, zeros will be used to initialize the table,
        otherwise the table will be initialized as the init_value.
        *Notice*: if the init_value is different in different processes, the
        average of them will be used.
        '''
        self._handler = ctypes.c_void_p()
        self._size = size
        mv_lib.MV_NewArrayTable(size, ctypes.byref(self._handler))
        if init_value is not None:
            init_value = convert_data(init_value)
            # sync add is used because we want to make sure that the initial
            # value has taken effect when the call returns.
            self.add(init_value / api.workers_num(), sync=True)
コード例 #2
0
ファイル: tables.py プロジェクト: dongruiqing/multiverso
    def __init__(self, size, init_value=None):
        '''Constructor for syncing array-like (one-dimensional) value.

        The `size` should be a int equal to the size of value we want to sync.
        If init_value is None, zeros will be used to initialize the tables,
        otherwise the table will be initialized as the init_value.
        Notice: if the init_value is different in different processes, the
        average of them will be used.
        '''
        self._handler = ctypes.c_void_p()
        self._size = size
        mv_lib.MV_NewArrayTable(size, ctypes.byref(self._handler))
        if init_value is not None:
            init_value = convert_data(init_value)
            # sync add is used because we want to make sure that the initial
            # value has taken effect when the call returns.
            self.add(init_value / api.workers_num(), sync=True)
コード例 #3
0
    def __init__(self, num_row, num_col, init_value=None):
        '''Constructor for syncing matrix-like (two-dimensional) value.

        The `num_row` should be the number of rows and the `num_col` should be
        the number of columns.

        If init_value is None, zeros will be used to initialize the table,
        otherwise the table will be initialized as the init_value.
        Notice: if the init_value is different in different processes, the
        average of them will be used.
        '''
        self._handler = ctypes.c_void_p()
        self._num_row = num_row
        self._num_col = num_col
        self._size = num_col * num_row
        mv_lib.MV_NewMatrixTable(num_row, num_col, ctypes.byref(self._handler))
        if init_value is not None:
            init_value = convert_data(init_value)
            # sync add is used because we want to make sure that the initial
            # value has taken effect when the call returns.
            self.add(init_value / api.workers_num(), sync=True)
コード例 #4
0
ファイル: tables.py プロジェクト: dongruiqing/multiverso
    def __init__(self, num_row, num_col, init_value=None):
        '''Constructor for syncing matrix-like (two-dimensional) value.

        The `num_row` should be the number of rows and the `num_col` should be
        the number of columns.

        If init_value is None, zeros will be used to initialize the tables,
        otherwise the table will be initialized as the init_value.
        Notice: if the init_value is different in different processes, the
        average of them will be used.
        '''
        self._handler = ctypes.c_void_p()
        self._num_row = num_row
        self._num_col = num_col
        self._size = num_col * num_row
        mv_lib.MV_NewMatrixTable(num_row, num_col, ctypes.byref(self._handler))
        if init_value is not None:
            init_value = convert_data(init_value)
            # sync add is used because we want to make sure that the initial
            # value has taken effect when the call returns.
            self.add(init_value / api.workers_num(), sync=True)