当前位置: 首页>>代码示例>>Python>>正文


Python memory.Array类代码示例

本文整理汇总了Python中veles.memory.Array的典型用法代码示例。如果您正苦于以下问题:Python Array类的具体用法?Python Array怎么用?Python Array使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Array类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self, workflow, **kwargs):
     super(GradientsCalculator, self).__init__(workflow, **kwargs)
     self.vbias_grad = Array()
     self.hbias_grad = Array()
     self.weights_grad = Array()
     self.demand("hbias1", "vbias1", "hbias0", "vbias0", "weights0",
                 "weights1")
开发者ID:Samsung,项目名称:veles.znicz,代码行数:7,代码来源:rbm_units.py

示例2: clone

 def clone(self):
     for unit, attrs in self.reals.items():
         for attr in attrs:
             value = getattr(unit, attr)
             if self.is_immutable(value):
                 setattr(self, attr, value)
                 continue
             if not isinstance(value, Array):
                 cloned = getattr(self, attr, None)
                 if cloned is None:
                     setattr(self, attr, deepcopy(value))
                     continue
                 if isinstance(value, list):
                     del cloned[:]
                     cloned.extend(value)
                 elif isinstance(value, (dict, set)):
                     cloned.clear()
                     cloned.update(value)
                 elif isinstance(value, Bool):
                     cloned <<= value
                 elif isinstance(value, numpy.ndarray):
                     cloned[:] = value
                 else:
                     setattr(self, attr, deepcopy(value))
                 continue
             vec = getattr(self, attr, None)
             if vec is None:
                 vec = Array()
                 self.vectors[value] = vec
                 setattr(self, attr, vec)
             else:
                 assert isinstance(vec, Array)
             if not vec and value:
                 vec.reset(value.mem.copy())
开发者ID:2php,项目名称:veles,代码行数:34,代码来源:avatar.py

示例3: __init__

 def __init__(self, workflow, **kwargs):
     super(Uniform, self).__init__(workflow, **kwargs)
     self.num_states = kwargs.get("num_states", 256)
     self.states = Array()
     self.prng = kwargs.get("prng", get())
     self.output_bytes = kwargs.get("output_bytes", 0)
     self.output = Array()
     self.cl_const = numpy.zeros(1, dtype=numpy.int32)
开发者ID:2php,项目名称:veles,代码行数:8,代码来源:uniform.py

示例4: __init__

 def __init__(self, workflow, **kwargs):
     super(EvaluatorSoftmax, self).__init__(workflow, **kwargs)
     self.compute_confusion_matrix = kwargs.get(
         "compute_confusion_matrix", True)
     self.confusion_matrix = Array()
     self.n_err = Array()
     self.max_err_output_sum = Array()
     self.demand("labels", "max_idx")
开发者ID:vmarkovtsev,项目名称:veles.znicz,代码行数:8,代码来源:evaluator.py

示例5: Summator

class Summator(AcceleratedUnit):
    """Multiplies two vectors pointwise.
    """
    def __init__(self, workflow, **kwargs):
        super(Summator, self).__init__(workflow, **kwargs)
        self.output = Array()
        self.demand("x", "y")

    def initialize(self, device, **kwargs):
        super(Summator, self).initialize(device, **kwargs)
        if not self.output:
            self.output.reset(numpy.zeros_like(self.x.mem))
        else:
            assert self.output.shape == self.x.shape
        self.init_vectors(self.x, self.y, self.output)

    def init_unpickled(self):
        super(Summator, self).init_unpickled()
        self.sources_["summator"] = {}

    def _gpu_init(self):
        self.build_program({"OUTPUT_SIZE": self.output.size},
                           "%s_%d" %
                           (self.__class__.__name__, self.output.size),
                           dtype=self.x.dtype)
        self.assign_kernel("add_forward")
        self.set_args(self.x, self.y, self.output)

    def cuda_init(self):
        self._gpu_init()
        block_size = self.device.suggest_block_size(self._kernel_)
        self._global_size = (
            int(numpy.ceil(self.output.size / block_size)), 1, 1)
        self._local_size = (block_size, 1, 1)

    def ocl_init(self):
        self._gpu_init()
        self._global_size = (self.output.size, 1, 1)
        self._local_size = None

    def numpy_init(self):
        pass  # nothing to init

    def _gpu_run(self):
        self.unmap_vectors(self.x, self.y, self.output)
        self.execute_kernel(self._global_size, self._local_size)

    def cuda_run(self):
        self._gpu_run()

    def ocl_run(self):
        self._gpu_run()

    def numpy_run(self):
        self.x.map_read()
        self.y.map_read()
        self.output.map_invalidate()
        numpy.add(self.x.mem, self.y.mem, self.output.mem)
开发者ID:vmarkovtsev,项目名称:veles.znicz,代码行数:58,代码来源:summator.py

示例6: __init__

 def __init__(self, workflow, **kwargs):
     super(EvaluatorMSE, self).__init__(workflow, **kwargs)
     self.metrics = Array()
     self.mse = Array()
     self.labels = None
     self.class_targets = None
     self.n_err = Array()
     self.root = kwargs.get("root", True)
     self.demand("target", "normalizer")
开发者ID:Samsung,项目名称:veles.znicz,代码行数:9,代码来源:evaluator.py

示例7: __init__

 def __init__(self, workflow, **kwargs):
     super(KohonenForward, self).__init__(workflow, **kwargs)
     self.demand("input", "weights")
     self.argmins = None
     self._distances = Array()
     self.output = Array()
     self._chunk_size_ = 0
     self.weights_transposed = False
     self.total = Array() if kwargs.get("total", False) else None
     if self.total is not None:
         self.minibatch_offset = None
         self.minibatch_size = None
         self.batch_size = None
开发者ID:Samsung,项目名称:veles.znicz,代码行数:13,代码来源:kohonen.py

示例8: __init__

 def __init__(self, workflow, **kwargs):
     super(Cutter1D, self).__init__(workflow, **kwargs)
     self.alpha = kwargs.get("alpha")
     self.beta = kwargs.get("beta")
     self.output_offset = kwargs.get("output_offset", 0)
     self.output = Array()
     self.demand("alpha", "beta", "input")
开发者ID:Samsung,项目名称:veles.znicz,代码行数:7,代码来源:cutter.py

示例9: __init__

 def __init__(self, workflow, **kwargs):
     kwargs["view_group"] = kwargs.get("view_group", "WORKER")
     super(MeanDispNormalizer, self).__init__(workflow, **kwargs)
     self.output = Array()
     self.global_size = None
     self.local_size = None
     self.demand("input", "mean", "rdisp")
开发者ID:2php,项目名称:veles,代码行数:7,代码来源:mean_disp_normalizer.py

示例10: __init__

 def __init__(self, workflow, **kwargs):
     super(MultiHistogram, self).__init__(workflow, **kwargs)
     self.limit = kwargs.get("limit", 64)
     self.value = Array()
     self.n_bars = kwargs.get("n_bars", 25)
     self.hist_number = kwargs.get("hist_number", 16)
     self.demand("input")
开发者ID:2php,项目名称:veles,代码行数:7,代码来源:plotting_units.py

示例11: __init__

 def __init__(self, workflow, **kwargs):
     kwargs["view_group"] = kwargs.get("view_group", "WORKER")
     super(Forward, self).__init__(workflow, **kwargs)
     self.weights_stddev = kwargs.get("weights_stddev")
     self.bias_stddev = kwargs.get("bias_stddev", self.weights_stddev)
     self.weights_filling = kwargs.get("weights_filling", "uniform")
     self.bias_filling = kwargs.get("bias_filling", "uniform")
     self.rand = kwargs.get("rand", prng.get())
     self.weights_transposed = kwargs.get("weights_transposed", False)
     self.include_bias = kwargs.get("include_bias", True)
     self.demand("input")
     self.output = Array(shallow_pickle=True)
     self.weights = Array()
     self.bias = Array()
     self.forward_mode = False
     self.exports = ["weights", "bias", "include_bias", "weights_transposed"]
开发者ID:vmarkovtsev,项目名称:veles.znicz,代码行数:16,代码来源:nn_units.py

示例12: FixAccumulator

class FixAccumulator(Unit):
    """
    Range accumulator.
    """
    def __init__(self, workflow, **kwargs):
        super(FixAccumulator, self).__init__(workflow)
        self.bars = kwargs.get("bars", 200)
        self.type = kwargs.get("type", "relu")
        self.input = None
        self.output = Array()
        self.reset_flag = Bool(True)
        self.n_bars = [0]
        self.max = 100
        self.min = 0

    def initialize(self, **kwargs):
        self.output.mem = numpy.zeros([self.bars + 2], dtype=numpy.int64)

    def run(self):
        if self.type == "relu":
            self.max = 10000
            self.min = 0
        elif self.type == "tanh":
            self.max = 1.7159
            self.min = -1.7159
        else:
            raise error.BadFormatError("Unsupported type %s" % self.type)

        d = self.max - self.min
        if not d:
            return
        self.output.map_write()
        self.input.map_read()
        d = (self.bars - 1) / d
        if self.reset_flag:
            self.output.mem[:] = 0
        self.n_bars[0] = self.bars + 2
        for y in self.input.mem.ravel():
            if y < self.min:
                self.output[0] += 1
                continue
            if y <= self.max and y > self.min:
                i = int(numpy.floor((y - self.min) * d))
                self.output[i] += 1
                continue
            self.output[self.bars + 1] += 1
开发者ID:Samsung,项目名称:veles.znicz,代码行数:46,代码来源:accumulator.py

示例13: __init__

 def __init__(self, workflow, **kwargs):
     super(FixAccumulator, self).__init__(workflow)
     self.bars = kwargs.get("bars", 200)
     self.type = kwargs.get("type", "relu")
     self.input = None
     self.output = Array()
     self.reset_flag = Bool(True)
     self.n_bars = [0]
     self.max = 100
     self.min = 0
开发者ID:Samsung,项目名称:veles.znicz,代码行数:10,代码来源:accumulator.py

示例14: __init__

 def __init__(self, workflow, **kwargs):
     super(Deconv, self).__init__(workflow, **kwargs)
     self.unsafe_padding = kwargs.get("unsafe_padding", False)
     self.hits = Array()
     self.krn_clear_output_ = None
     self._global_size = None
     self._local_size = None
     del self.bias
     self.demand("n_kernels", "kx", "ky", "padding", "sliding",
                 "input", "weights", "output_shape_source")
开发者ID:Samsung,项目名称:veles.znicz,代码行数:10,代码来源:deconv.py

示例15: GDSummator

class GDSummator(AcceleratedUnit):
    """Gradient descent for Summator.
    """
    def __init__(self, workflow, **kwargs):
        super(GDSummator, self).__init__(workflow, **kwargs)
        self.err_x = Array()
        self.err_y = Array()
        self.demand("err_output")

    def initialize(self, device, **kwargs):
        super(GDSummator, self).initialize(device, **kwargs)

        if self.err_x:
            assert self.err_x.shape[1:] == self.err_output.shape[1:]
        if not self.err_x or self.err_x.shape[0] != self.err_output.shape[0]:
            self.err_x.reset(numpy.zeros_like(self.err_output.mem))
        if self.err_y:
            assert self.err_y.shape[1:] == self.err_output.shape[1:]
        if not self.err_y or self.err_y.shape[0] != self.err_output.shape[0]:
            self.err_y.reset(numpy.zeros_like(self.err_output.mem))
        self.init_vectors(self.err_x, self.err_y, self.err_output)

    def cuda_init(self):
        pass  # nothing to init

    def ocl_init(self):
        pass  # nothing to init

    def numpy_init(self):
        pass  # nothing to init

    def cuda_run(self):
        self.unmap_vectors(self.err_output, self.err_x, self.err_y)
        self.err_x.devmem.from_device_async(self.err_output.devmem)
        self.err_y.devmem.from_device_async(self.err_output.devmem)

    def ocl_run(self):
        self.unmap_vectors(self.err_output, self.err_x, self.err_y)
        self.device.queue_.copy_buffer(
            self.err_output.devmem, self.err_x.devmem, 0, 0,
            self.err_output.nbytes, need_event=False)
        self.device.queue_.copy_buffer(
            self.err_output.devmem, self.err_y.devmem, 0, 0,
            self.err_output.nbytes, need_event=False)

    def numpy_run(self):
        self.err_output.map_read()
        self.err_x.map_invalidate()
        self.err_y.map_invalidate()
        self.err_x.mem[:] = self.err_output.mem[:]
        self.err_y.mem[:] = self.err_output.mem[:]
开发者ID:Samsung,项目名称:veles.znicz,代码行数:51,代码来源:summator.py


注:本文中的veles.memory.Array类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。