示例#1
0
	def geterr(self, err):
		for nc, ne in zip(self.nodes, err.nodes):
			if nc is not None:
				nc.geterr(ne)
		for pc, pe in zip(self.paths, err.paths):
			if pe is not None:
				array.copy(pe, pc)
示例#2
0
	def _transmit(self, ctx):
		if ctx.trace is not None:
			array.softmax(ctx.trace.odata, ctx.src)
			if ctx.dst is not None:
				array.copy(ctx.dst, ctx.trace.odata)
		else:
			Softmax._transmit(self, ctx)
示例#3
0
	def setmem(self, mem):
		for nc, nm in zip(self.nodes, mem.nodes):
			if nc is not None:
				nc.setmem(nm)
		for pc, pm in zip(self.paths, mem.paths):
			if pm is not None:
				array.copy(pc, pm)
示例#4
0
	def _transmit(self, ctx):
		array.copy(ctx.accum, ctx.src[0])
		for i in range(1, self.inum):
			array.radd(ctx.accum, ctx.srcs[i])

		for i in range(self.onum):
			array.copy(ctx.dsts[i], ctx.accum)
示例#5
0
	def _backprop(self, ctx):
		array.copy(ctx.accum, ctx.dst[0])
		for i in range(1, self.onum):
			array.radd(ctx.accum, ctx.dsts[i])

		for i in range(self.inum):
			array.copy(ctx.srcs[i], ctx.accum)
示例#6
0
		def set(self, src):
			array.copy(self.odata, src.odata)
示例#7
0
	factory = array.newFactory(dtype=np.int32)

with Case('_FactoryCPU.empty'):
	a = factory.empty((4, 5))
	assert(a.np.shape == (4, 5))

with Case('_FactoryCPU.zeros'):
	a = factory.zeros((4, 5))
	assert(np.sum(a.get()**2) == 0)

with Case('_FactoryCPU.copynp'):
	npa = np.array([1, 2, 3, 4])
	a = factory.copynp(npa)
	assert(a.np[0] == 1 and a.np[3] == 4)
	assert(a.np is not npa)

with Case('_FactoryCPU.copy'):
	a = factory.copynp(np.array([1, 2, 3]))
	b = factory.copy(a)
	assert(np.all(b.np == a.np))
	assert(a.np is not b.np)

with Case('copy'):
	a, b = factory.empty(4), factory.empty(4)
	a.np[0] = 1
	array.copy(b, a)
	a.np[0] = 2
	assert(b.np[0] == 1)

# to be continued ...
示例#8
0
	def _transmit(self, ctx):
		if ctx.trace is not None:
			array.copy(ctx.trace.idata, ctx.src)
		array.dot(ctx.dst, ctx.src, ctx.state.data)
示例#9
0
	def _backprop(self, ctx):
		array.copy(ctx.srcs[0], ctx.dst)
		array.copy(ctx.srcs[1], ctx.dst)
示例#10
0
	def _transmit(self, ctx):
		array.copy(ctx.dsts[0], ctx.src)
		array.copy(ctx.dsts[1], ctx.src)
示例#11
0
	def _transmit(self, ctx):
		array.tanh(ctx.dst, ctx.src)
		if ctx.trace is not None:
			array.copy(ctx.trace.odata, ctx.dst)
示例#12
0
	def _backprop(self, ctx):
		array.copy(ctx.src, ctx.dst)
示例#13
0
	def _transmit(self, ctx):
		array.copy(ctx.dst, ctx.src)
示例#14
0
	def _backprop(self, ctx):
		if ctx.grad is not None:
			array.radd(ctx.grad.data, ctx.dst)
		array.copy(ctx.src, ctx.dst)
示例#15
0
    factory = array.newFactory(dtype=np.int32)

with Case('_FactoryCPU.empty'):
    a = factory.empty((4, 5))
    assert (a.np.shape == (4, 5))

with Case('_FactoryCPU.zeros'):
    a = factory.zeros((4, 5))
    assert (np.sum(a.get()**2) == 0)

with Case('_FactoryCPU.copynp'):
    npa = np.array([1, 2, 3, 4])
    a = factory.copynp(npa)
    assert (a.np[0] == 1 and a.np[3] == 4)
    assert (a.np is not npa)

with Case('_FactoryCPU.copy'):
    a = factory.copynp(np.array([1, 2, 3]))
    b = factory.copy(a)
    assert (np.all(b.np == a.np))
    assert (a.np is not b.np)

with Case('copy'):
    a, b = factory.empty(4), factory.empty(4)
    a.np[0] = 1
    array.copy(b, a)
    a.np[0] = 2
    assert (b.np[0] == 1)

# to be continued ...