Store information about the Tensor: Is it sparse?, map_op, and rank.
| 384 | |
| 385 | |
| 386 | class _SparseMetaData(object): |
| 387 | """Store information about the Tensor: Is it sparse?, map_op, and rank.""" |
| 388 | |
| 389 | def __init__(self, sparse, map_op, rank): |
| 390 | """Create the metadata. |
| 391 | |
| 392 | Args: |
| 393 | sparse: Python boolean. |
| 394 | map_op: The `Operation` that created the `SparseTensorsMap` in question. |
| 395 | This Op contains information about the underlying Map object and the |
| 396 | dtype of the original data. |
| 397 | rank: The statically known rank of the `SparseTensor`. |
| 398 | """ |
| 399 | self._sparse = sparse |
| 400 | self._map_op = map_op |
| 401 | self._rank = tensor_shape.Dimension(rank) |
| 402 | |
| 403 | def __eq__(self, other): |
| 404 | if self.sparse != other.sparse: |
| 405 | return False |
| 406 | if not self.sparse: |
| 407 | return True |
| 408 | # If map_ops are not the same, the data source is not the same. |
| 409 | if (self.map_op is not None) != (other.map_op is not None): |
| 410 | return False |
| 411 | if self.map_op != other.map_op: |
| 412 | return False |
| 413 | if not self.rank.is_compatible_with(other.rank): |
| 414 | return False |
| 415 | return True |
| 416 | |
| 417 | def __ne__(self, other): |
| 418 | return not self.__eq__(other) |
| 419 | |
| 420 | def __str__(self): |
| 421 | return "[SparseMetaData(%s, %s, %s)]" % (self.sparse, self.map_op.name, |
| 422 | self.rank) |
| 423 | |
| 424 | def merge_with(self, other): |
| 425 | if self != other: |
| 426 | raise ValueError("SparseMetaData objects are incompatible: %s vs. %s" |
| 427 | % (self, other)) |
| 428 | if self.sparse: |
| 429 | self.rank.merge_with(other.rank) |
| 430 | return self |
| 431 | |
| 432 | @property |
| 433 | def map_op(self): |
| 434 | return self._map_op |
| 435 | |
| 436 | @property |
| 437 | def sparse(self): |
| 438 | return self._sparse |
| 439 | |
| 440 | @property |
| 441 | def rank(self): |
| 442 | return self._rank |
| 443 |