Make sure the shape and dtype of the two tensor's lists are compatible. Args: ts0: an object convertible to a list of `tf.Tensor`. ts1: an object convertible to a list of `tf.Tensor`. Raises: ValueError: if any pair of tensors (same index in ts0 and ts1) have a dtype or a shap
(ts0, ts1)
| 39 | |
| 40 | |
| 41 | def _check_ts_compatibility(ts0, ts1): |
| 42 | """Make sure the shape and dtype of the two tensor's lists are compatible. |
| 43 | |
| 44 | Args: |
| 45 | ts0: an object convertible to a list of `tf.Tensor`. |
| 46 | ts1: an object convertible to a list of `tf.Tensor`. |
| 47 | Raises: |
| 48 | ValueError: if any pair of tensors (same index in ts0 and ts1) have |
| 49 | a dtype or a shape which is not compatible. |
| 50 | """ |
| 51 | ts0 = _util.make_list_of_t(ts0) |
| 52 | ts1 = _util.make_list_of_t(ts1) |
| 53 | if len(ts0) != len(ts1): |
| 54 | raise ValueError("ts0 and ts1 have different sizes: {} != {}".format( |
| 55 | len(ts0), len(ts1))) |
| 56 | for t0, t1 in zip(ts0, ts1): |
| 57 | # check dtype |
| 58 | dtype0, dtype1 = t0.dtype, t1.dtype |
| 59 | if not dtype0.is_compatible_with(dtype1): |
| 60 | raise ValueError("Dtypes {} and {} are not compatible.".format(dtype0, |
| 61 | dtype1)) |
| 62 | # check shape |
| 63 | shape0, shape1 = t0.get_shape(), t1.get_shape() |
| 64 | if not shape0.is_compatible_with(shape1): |
| 65 | raise ValueError("Shapes {} and {} are not compatible.".format(shape0, |
| 66 | shape1)) |
| 67 | |
| 68 | |
| 69 | class _RerouteMode(object): |
no test coverage detected