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)
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)
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)
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)
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)
def set(self, src): array.copy(self.odata, src.odata)
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 ...
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)
def _backprop(self, ctx): array.copy(ctx.srcs[0], ctx.dst) array.copy(ctx.srcs[1], ctx.dst)
def _transmit(self, ctx): array.copy(ctx.dsts[0], ctx.src) array.copy(ctx.dsts[1], ctx.src)
def _transmit(self, ctx): array.tanh(ctx.dst, ctx.src) if ctx.trace is not None: array.copy(ctx.trace.odata, ctx.dst)
def _backprop(self, ctx): array.copy(ctx.src, ctx.dst)
def _transmit(self, ctx): array.copy(ctx.dst, ctx.src)
def _backprop(self, ctx): if ctx.grad is not None: array.radd(ctx.grad.data, ctx.dst) array.copy(ctx.src, ctx.dst)
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 ...