| 341 | _ = special_math_ops.einsum(axes, *inputs) |
| 342 | |
| 343 | def run_test(self, axes, expanded_axes=None): |
| 344 | expanded_axes = expanded_axes if expanded_axes is not None else axes |
| 345 | all_axes = {ax: np.random.randint(4, 12) |
| 346 | for ax in expanded_axes if ax.isalpha()} |
| 347 | |
| 348 | input_vals = [] |
| 349 | input_axes, _, _ = axes.partition('->') |
| 350 | |
| 351 | for idx in input_axes.split(','): |
| 352 | shape = [all_axes[ax] for ax in idx if ax.isalpha()] |
| 353 | input_vals.append(np.random.random(shape)) |
| 354 | |
| 355 | input_tensors = [constant_op.constant(val) for val in input_vals] |
| 356 | output_tensor = special_math_ops.einsum(axes, *input_tensors) |
| 357 | |
| 358 | with self.session(use_gpu=True): |
| 359 | output_value = self.evaluate(output_tensor) |
| 360 | |
| 361 | correct_value = 0 |
| 362 | if axes == 'ijji': |
| 363 | output = math_ops.trace(*input_tensors) |
| 364 | correct_value = self.evaluate(output) |
| 365 | else: |
| 366 | correct_value = np.einsum(axes, *input_vals) |
| 367 | err = np.abs(correct_value - output_value).max() |
| 368 | self.assertLess(err, 1e-8) |
| 369 | |
| 370 | def test_input_is_placeholder(self): |
| 371 | with ops.Graph().as_default(): |