def test_softmax_ce_with_logits(self): my_graph = ad.SoftmaxCEWithLogits(labels=self.my_w3, logits=self.my_w4) tf_graph = tf.nn.softmax_cross_entropy_with_logits(labels=self.tf_w3, logits=self.tf_w4) wrt_vars = [self.my_w4] tf_vars = [self.tf_w4] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def custom_einsum_f(self, op_str, my_args, my_wrt, tf_args=None, tf_wrt=None): my_graph = ad.Einsum(op_str, *my_args) if tf_args and tf_wrt is not None: tf_graph = tf.einsum(op_str, *tf_args) utils.custom_test(self, my_graph, my_wrt, tf_graph, tf_wrt) else: utils.custom_test(self, my_graph, my_wrt)
def test_softmax0(self): # is this a correct test? Should the gradients always be this small? my_graph = ad.Softmax(self.my_w4) tf_graph = tf.nn.softmax(self.tf_w4) wrt_vars = [self.my_w4] tf_vars = [self.tf_w4] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_reshape(self): shp = (1, 15) my_graph = ad.Reshape(self.my_w1, shp) tf_graph = tf.reshape(self.tf_w1, shp) wrt_vars = [self.my_w1] tf_vars = [self.tf_w1] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_pad(self): pad_val = [[1, 0], [2, 2]] constant_values = [0, 0] my_graph = ad.Pad(self.my_w0, pad_val, constant_values=constant_values) tf_graph = tf.pad(self.tf_w0, pad_val, constant_values=constant_values[0]) wrt_vars = [self.my_w0] tf_vars = [self.tf_w0] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_negate(self): my_graph = ad.Negate(self.my_w0) tf_graph = tf.negative(self.tf_w0) wrt_vars = [self.my_w0] tf_vars = [self.tf_w0] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_normal_distribution(self): my_graph = ad.NormalDistribution(self.my_w5, 0, 1) wrt_vars = [self.my_w5] utils.custom_test(self, my_graph, wrt_vars)
def test_frobenius_norm(self): my_graph = ad.FrobeniusNorm(self.my_w3) tf_graph = tf.norm(self.tf_w3) wrt_vars = [self.my_w3] tf_vars = [self.tf_w3] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_concat2(self): my_graph = ad.Concat(self.my_w2, self.my_w3, axis=1) tf_graph = tf.concat([self.tf_w2, self.tf_w3], axis=1) wrt_vars = [self.my_w2, self.my_w3] tf_vars = [self.tf_w2, self.tf_w3] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_concat1(self): my_graph = ad.Concat(self.my_w0, self.my_w2, axis=0) tf_graph = tf.concat([self.tf_w0, self.tf_w2], axis=0) wrt_vars = [self.my_w0, self.my_w2] tf_vars = [self.tf_w0, self.tf_w2] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_reducesumkeepdims1(self): axes = [0, 2] my_graph = ad.ReduceSumKeepDims(self.my_w3, axes=axes) wrt_vars = [self.my_w3] utils.custom_test(self, my_graph, wrt_vars)
def test_all(self): my_vars = [self.my_x, self.my_w1, self.my_w2] tf_vars = [self.tf_x, self.tf_w1, self.tf_w2] utils.custom_test(self, self.my_graph, my_vars, self.tf_graph, tf_vars)
def test_recipr(self): my_graph = ad.Recipr(self.my_w0) tf_graph = tf.reciprocal(self.tf_w0) wrt_vars = [self.my_w0] tf_vars = [self.tf_w0] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_relu(self): my_graph = ad.ReLU(self.my_w0) tf_graph = tf.nn.relu(self.tf_w0) wrt_vars = [self.my_w0] tf_vars = [self.tf_w0] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_sigmoid(self): my_graph = ad.Sigmoid(self.my_w0) tf_graph = tf.nn.sigmoid(self.tf_w0) wrt_vars = [self.my_w0] tf_vars = [self.tf_w0] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_slice5(self): my_graph = self.my_w1[::-2] tf_graph = self.tf_w1[::-2] wrt_vars = [self.my_w1] tf_vars = [self.tf_w1] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_slice3(self): my_graph = self.my_w1[2, 2:4] tf_graph = self.tf_w1[2, 2:4] wrt_vars = [self.my_w1] tf_vars = [self.tf_w1] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def custom_test(self, my_graph, tf_graph, my_vars, tf_vars): utils.custom_test(self, my_graph, my_vars, tf_graph, tf_vars)
def test_softmax2(self): my_graph = ad.Softmax(self.my_w6) tf_graph = tf.nn.softmax(self.tf_w6) wrt_vars = [self.my_w6] tf_vars = [self.tf_w6] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_identity(self): my_graph = ad.Identity(self.my_w0) tf_graph = tf.identity(self.tf_w0) wrt_vars = [self.my_w0] tf_vars = [self.tf_w0] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_all(self): my_vars = [self.my_x, self.my_w, self.my_b, self.var_mul] tf_vars = [self.tf_x, self.tf_w, self.tf_b, self.tf_mul] utils.custom_test(self, self.my_graph, my_vars, self.tf_graph, tf_vars)
def test_tanh(self): my_graph = ad.Tanh(self.my_w0) tf_graph = tf.tanh(self.tf_w0) wrt_vars = [self.my_w0] tf_vars = [self.tf_w0] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_mul(self): my_graph = self.my_h * self.my_b0 * self.my_b1 + self.my_b2 tf_graph = self.tf_h * self.tf_b0 * self.tf_b1 + self.tf_b2 wrt_vars = [self.my_b0, self.my_b1, self.my_b2] tf_vars = [self.tf_b0, self.tf_b1, self.tf_b2] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)
def test_matmul(self): my_graph = ad.MatMul(self.my_w0, self.my_w1) tf_graph = tf.matmul(self.tf_w0, self.tf_w1) wrt_vars = [self.my_w0, self.my_w1] tf_vars = [self.tf_w0, self.tf_w1] utils.custom_test(self, my_graph, wrt_vars, tf_graph, tf_vars)