def test_cross_entropy(self, constructor):
     # cross_entropy in pytorch combines softmax and the cross-entropy function
     sl_function = lambda x, labels: sl_F.cross_entropy(
         sl_F.softmax(x), labels.detach())
     torch_function = lambda x, labels: torch_F.cross_entropy(
         x, labels.long())
     evaluate_function_with_pytorch(sl_function, torch_function,
                                    constructor)
示例#2
0
 def test_exp(self, constructor):
     evaluate_function_with_pytorch(lambda x: x.exp(), lambda x: x.exp(),
                                    constructor)
示例#3
0
 def test_sum_self_keepdims(self, constructor):
     evaluate_function_with_pytorch(lambda x: x.sum(axis=0, keepdims=False),
                                    lambda x: x.sum(axis=0, keepdims=False),
                                    constructor)
示例#4
0
 def test_transpose(self, constructor):
     evaluate_function_with_pytorch(lambda x: x.T, lambda x: x.T,
                                    constructor)
示例#5
0
 def test_reshape(self, constructor):
     evaluate_function_with_pytorch(lambda x: x.reshape(
         (-1, 1)), lambda x: x.reshape((-1, 1)), constructor)
示例#6
0
 def test_mean(self, constructor):
     evaluate_function_with_pytorch(lambda x: x.mean(), lambda x: x.mean(),
                                    constructor)
示例#7
0
 def test_matmul(self, constructor):
     constructor[1][-1] = constructor[1][
         -1][::-1]  # change the size of last argument to match matmul
     evaluate_function_with_pytorch(operator.matmul, operator.matmul,
                                    constructor)
示例#8
0
 def test_pow(self, constructor):
     constructor[
         0] = np.random.rand  # overriding function to keep the tests real valued
     evaluate_function_with_pytorch(operator.pow, operator.pow, constructor)
示例#9
0
 def test_div(self, constructor):
     evaluate_function_with_pytorch(operator.truediv, operator.truediv,
                                    constructor)
示例#10
0
 def test_mul(self, constructor):
     evaluate_function_with_pytorch(operator.mul, operator.mul, constructor)
示例#11
0
 def test_sub(self, constructor):
     evaluate_function_with_pytorch(operator.sub, operator.sub, constructor)
示例#12
0
 def test_sum(self, constructor):
     evaluate_function_with_pytorch(operator.add, operator.add, constructor)
示例#13
0
 def test_log(self, constructor):
     constructor[
         0] = np.random.rand  # overriding function to keep the tests real valued
     evaluate_function_with_pytorch(lambda x: x.log(), lambda x: x.log(),
                                    constructor)
示例#14
0
 def test_softmax(self, constructor):
     # adding extra pow function to make the softmax derivatives bigger
     sl_function = lambda x: (sl_F.softmax(x)**4.2).sum()
     torch_function = lambda x: (torch_F.softmax(x, dim=-1)**4.2).sum()
     evaluate_function_with_pytorch(sl_function, torch_function,
                                    constructor)
示例#15
0
 def test_relu(self, constructor):
     evaluate_function_with_pytorch(sl_F.relu, torch_F.relu, constructor)