本文整理汇总了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")
示例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())
示例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)
示例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")
示例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)
示例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")
示例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
示例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")
示例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")
示例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")
示例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"]
示例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
示例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
示例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")
示例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[:]