Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
right=np.random.randn(3, 2),
middle=np.random.randn(2, 2))
zero = Zero.from_(a)
one = One.from_(a)
constant = Constant.from_(2.0, a)
wb = d + lr
# Aggregate all matrices.
candidates = [a, d, lr, wb, constant, one, zero, 2, 1, 0, 2.0, 1.0, 0.0]
# Check division.
allclose(a.__div__(5.0), to_np(a) / 5.0)
allclose(a.__rdiv__(5.0), 5.0 / to_np(a))
allclose(a.__truediv__(5.0), to_np(a) / 5.0)
allclose(a.__rtruediv__(5.0), 5.0 / to_np(a))
allclose(B.divide(a, 5.0), to_np(a) / 5.0)
allclose(B.divide(a, a), B.ones(to_np(a)))
# Check shapes.
for m in candidates:
assert B.shape(a) == (4, 3)
# Check interactions.
for m1, m2 in product(candidates, candidates):
allclose(m1 * m2, to_np(m1) * to_np(m2))
allclose(m1 + m2, to_np(m1) + to_np(m2))
allclose(m1 - m2, to_np(m1) - to_np(m2))
@B.divide.extend(Dense, Dense)
def divide(a, b): return B.multiply(a, 1 / b)
def _compute(self, x, y):
stretches1, stretches2 = expand(self.stretches)
return B.divide(x, stretches1), B.divide(y, stretches2)
def __div__(self, other):
return B.divide(self, other)
def feat_map(z):
z = B.divide(B.multiply(B.multiply(z, 2), B.pi), self.period)
return B.concat(B.sin(z), B.cos(z), axis=1)
def __call__(self, x, y):
dists = B.maximum(B.pw_dists(x, y), 1e-10)
return Dense(B.divide(B.log(dists + 1), dists))
def __truediv__(self, other):
return B.divide(self, other)
def __call__(self, x):
return self[0](B.divide(x, self.stretches[0]))