コード例 #1
0
ファイル: __init__.py プロジェクト: Paebbels/PoC
		def __setitem__(self, key, value):
			try:
				k = 'get' + key
			except TypeError:
				raise ValueError('Incompatible key: {} (type: {})'
												 ''.format(key, type(key)))
			if k == 'get':
				raise ValueError('Incompatible key: cannot use "" as a name')
			self._data[key] = value
			func = functools_partial(self._parser._get_conv, conv=value)
			func.converter = value
			setattr(self._parser, k, func)
			for proxy in self._parser.values():
				getter = functools_partial(proxy.get, _impl=func)
				setattr(proxy, k, getter)
コード例 #2
0
 def __setitem__(self, key, value):
     try:
         k = 'get' + key
     except TypeError:
         raise ValueError('Incompatible key: {} (type: {})'
                          ''.format(key, type(key)))
     if k == 'get':
         raise ValueError('Incompatible key: cannot use "" as a name')
     self._data[key] = value
     func = functools_partial(self._parser._get_conv, conv=value)
     func.converter = value
     setattr(self._parser, k, func)
     for proxy in self._parser.values():
         getter = functools_partial(proxy.get, _impl=func)
         setattr(proxy, k, getter)
コード例 #3
0
def _partial(middleware, handler):
    """
    Custom partial in order to propagate original fn attributes
    """
    resulting_func = functools_partial(middleware, handler=handler)
    resulting_func.__name__ = handler.__name__
    resulting_func.__module__ = handler.__module__
    resulting_func.__doc__ = handler.__doc__
    return resulting_func
コード例 #4
0
 def addModelActions(self, actionDict) :
   col = 0
   for x in actionDict :
     btn = QtGui.QPushButton(x, self.getSheet())
     btn.setFont(self.getSheet().font())
     ahandler = functools_partial(PyFinModelsApp.actionHandler, self, actionDict[x])
     self.connect(btn, QtCore.SIGNAL('clicked(bool)'), ahandler)
     self.getSheet().setCellWidget(self.sheetrow, col, btn)
     col += 1
コード例 #5
0
 def __init__(self) :
   QtGui.QMainWindow.__init__(self)
   self.ui = Ui_MainWindow()
   self.ui.setupUi(self)
   self.chartrow = 0
   self.chartcol = 0
   self.ui.frmNotify.hide()
   self.sheetrow = 0
   self.propertyChanged = functools_partial(PyFinModelsApp.propertyChangeEvent, self)
   self.connect(self.ui.tblSheet, QtCore.SIGNAL('itemChanged(QTableWidgetItem *)'), self.propertyChangeEvent)
コード例 #6
0
 def addModelActions(self, actionDict):
     col = 0
     for x in actionDict:
         btn = QtGui.QPushButton(x, self.getSheet())
         btn.setFont(self.getSheet().font())
         ahandler = functools_partial(PyFinModelsApp.actionHandler, self,
                                      actionDict[x])
         self.connect(btn, QtCore.SIGNAL('clicked(bool)'), ahandler)
         self.getSheet().setCellWidget(self.sheetrow, col, btn)
         col += 1
コード例 #7
0
 def __init__(self):
     QtGui.QMainWindow.__init__(self)
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     self.chartrow = 0
     self.chartcol = 0
     self.ui.frmNotify.hide()
     self.sheetrow = 0
     self.propertyChanged = functools_partial(
         PyFinModelsApp.propertyChangeEvent, self)
     self.connect(self.ui.tblSheet,
                  QtCore.SIGNAL('itemChanged(QTableWidgetItem *)'),
                  self.propertyChangeEvent)
コード例 #8
0
def data_sample(data_sample_queue,
                input_list,
                split,
                epoch,
                num_works,
                block_points=4096,
                block_size=1.0,
                stride=0.5,
                random_sample=False,
                sample_num=None,
                sample_aug=1):
    assert (input_list[0].endswith('npy')
            or input_list[0].endswith('h5')), "data format must be .npy or .h5"

    input_list_length = len(input_list)
    num_work = min(min(num_works, multiprocessing.cpu_count()),
                   input_list_length // 4)

    if input_list_length > 4:
        num_work = max(num_work, 4)

    chunksize = input_list_length // num_work
    print("num input_list: {}, num works: {}, chunksize: {}".format(
        input_list_length, num_work, chunksize))

    if input_list[0].endswith('npy'):
        data_sample_func = functools_partial(
            indoor3d_util.room2blocks_wrapper_normalized,
            num_point=block_points,
            block_size=block_size,
            stride=stride,
            random_sample=random_sample,
            sample_num=sample_num,
            sample_aug=sample_aug)
    elif input_list[0].endswith('h5'):

        def load_data_file(input_file):
            cur_data, cur_group, _, cur_sem = provider.loadDataFile_with_groupseglabel_stanfordindoor(
                input_file)
            return cur_data, cur_sem, cur_group

        data_sample_func = load_data_file

    def data_sample_single(input_file):
        datalabel = data_sample_func(input_file)
        if split == 'train':
            datalabel = provider.shuffle_data(*datalabel)
        return datalabel

    for _ in range(epoch):
        np.random.shuffle(input_list)
        for idx in range(chunksize + 1):
            start_idx = min(idx * num_work, input_list_length)
            end_idx = min((idx + 1) * num_work, input_list_length)
            if start_idx >= input_list_length or end_idx > input_list_length:
                continue

            with futures.ThreadPoolExecutor(num_work) as pool:
                data_sem_ins = list(
                    pool.map(data_sample_single,
                             input_list[start_idx:end_idx],
                             chunksize=1))

                for dsi in data_sem_ins:
                    shuffle_dsi = provider.shuffle_data(*dsi)
                    data_sample_queue.put(shuffle_dsi)
                    del dsi
                    gc.collect()

                pool.shutdown()
                gc.collect()
コード例 #9
0
            sw = numpy_asanyarray(sw)
    else:
        # The sum of weights is equal to the sample size (i.e. an
        # unweighted sample)
        sw = N.copy()

    return asanyarray(N, sw)


sw_fpartial = sum_fpartial
sw_ffinalise = sum_ffinalise

# ---------------------------------------------------------------------
# Sum of squares of weights
# ---------------------------------------------------------------------
sw2_f = functools_partial(sw_f, sum_of_squares=True)
sw2_fpartial = sum_fpartial
sw2_ffinalise = sum_ffinalise


# ---------------------------------------------------------------------
# Variance
# ---------------------------------------------------------------------
def var_f(a, axis=None, weights=None, masked=False, ddof=0):
    """Return a tuple containing metrics relating to the array variance.

    The tuple is a 7-tuple that contains, in the order given, the
    following variables:

    ========  ============================================================
    Variable  Description
コード例 #10
0
        def inner_wrapper(f, *args, **kwargs):
            argspec = getfullargspec(func)
            uri = URITemplate(path)
            field, path_, query = {}, {}, {}

            # Parse each args and put them in the right place
            for n, (key, val) in enumerate(argspec.annotations.items(), 1):
                if val is Field:
                    field[key] = args[n]
                elif val is Path:
                    path_[key] = args[n]
                elif val is Query:
                    query[key] = args[n]

            option['data'] = field
            option['params'] = query

            url = args[0]._base_url + str(uri.partial(path_))
            result = args[0]._oauth._req(method, url, **option)
            if returns is None:
                return result
            return returns(result)

        return decorate(func, inner_wrapper)

    return wrapper


GET = functools_partial(Request, 'GET')
POST = functools_partial(Request, 'POST')
コード例 #11
0
 def getModelActions(self):
     runModel = functools_partial(BinomialTreeModel.runModel, self)
     return {"Run Model": runModel}
コード例 #12
0
 def getModelActions(self):
   runModel = functools_partial(BinomialTreeModel.runModel, self)
   return {"Run Model": runModel}
コード例 #13
0
 def getActions(self):
     runModel = functools_partial(SimpleRandomWalk.runModel, self)
     return {"Run Model": runModel}
コード例 #14
0
def partial(func, *args, **kwargs):
    return composable(functools_partial(func, *args, **kwargs))
コード例 #15
0
def partial(fn, *args, **kwargs):
  out = functools_partial(fn, *args, **kwargs)
  out.__name__ = "partial_" + fn.__name__
  return out
コード例 #16
0
import os, sys, re, time
from collections import Counter, deque, defaultdict
from queue import Queue
from copy import copy, deepcopy
from itertools import combinations, permutations, accumulate, \
                      combinations_with_replacement
from functools import lru_cache, cmp_to_key, partial as functools_partial
from heapq import heappush, heappop, nlargest, nsmallest
from bisect import bisect_left, bisect_right
from math import ceil, floor, factorial, gcd, modf, log, log2, log10, sqrt, \
         pi, sin, cos, tan, asin, acos, atan, atan2, hypot, erf, erfc, inf, nan
sys.setrecursionlimit(5782)
# python -m cProfile -s time ha.py

print = functools_partial(print, flush=True)
input = lambda: fin.readline().strip('\n')


def printwrite(string):
    print(string)
    fout.write(str(string) + '\n')


filename = 'rect1'
fin = open(filename + '.in', 'r')
fout = open(filename + '.out', 'w')


def crop(wa, wb):
    '''
コード例 #17
0
ファイル: composed.py プロジェクト: eBay/wextracto
def partial(func, *args, **kwargs):
    return composable(functools_partial(func, *args, **kwargs))