Represents a typed scalar or tensor of fixed shape. A Scalar is a leaf in a schema tree, translating to exactly one tensor in the dataset's underlying storage. Usually, the tensor storing the actual values of this field is a 1D tensor, representing a series of values in its domain.
| 676 | |
| 677 | |
| 678 | class Scalar(Field): |
| 679 | """Represents a typed scalar or tensor of fixed shape. |
| 680 | |
| 681 | A Scalar is a leaf in a schema tree, translating to exactly one tensor in |
| 682 | the dataset's underlying storage. |
| 683 | |
| 684 | Usually, the tensor storing the actual values of this field is a 1D tensor, |
| 685 | representing a series of values in its domain. It is possible however to |
| 686 | have higher rank values stored as a Scalar, as long as all entries have |
| 687 | the same shape. |
| 688 | |
| 689 | E.g.: |
| 690 | |
| 691 | Scalar(np.float64) |
| 692 | |
| 693 | Scalar field of type float64. Caffe2 will expect readers and |
| 694 | datasets to expose it as a 1D tensor of doubles (vector), where |
| 695 | the size of the vector is determined by this fields' domain. |
| 696 | |
| 697 | Scalar((np.int32, 5)) |
| 698 | |
| 699 | Tensor field of type int32. Caffe2 will expect readers and |
| 700 | datasets to implement it as a 2D tensor (matrix) of shape (L, 5), |
| 701 | where L is determined by this fields' domain. |
| 702 | |
| 703 | Scalar((str, (10, 20))) |
| 704 | |
| 705 | Tensor field of type str. Caffe2 will expect readers and |
| 706 | datasets to implement it as a 3D tensor of shape (L, 10, 20), |
| 707 | where L is determined by this fields' domain. |
| 708 | |
| 709 | If the field type is unknown at construction time, call Scalar(), that will |
| 710 | default to np.void as its dtype. |
| 711 | |
| 712 | It is an error to pass a structured dtype to Scalar, since it would contain |
| 713 | more than one field. Instead, use from_dtype, which will construct |
| 714 | a nested `Struct` field reflecting the given dtype's structure. |
| 715 | |
| 716 | A Scalar can also contain a blob, which represents the value of this |
| 717 | Scalar. A blob can be either a numpy.ndarray, in which case it contain the |
| 718 | actual contents of the Scalar, or a BlobReference, which represents a |
| 719 | blob living in a caffe2 Workspace. If blob of different types are passed, |
| 720 | a conversion to numpy.ndarray is attempted. |
| 721 | """ |
| 722 | |
| 723 | __slots__: Sequence[str] = ("_metadata", "dtype", "_original_dtype", "_blob") |
| 724 | |
| 725 | def __init__(self, dtype=None, blob=None, metadata=None): |
| 726 | self._metadata = None |
| 727 | self.set(dtype, blob, metadata, unsafe=True) |
| 728 | super().__init__([]) |
| 729 | |
| 730 | def field_names(self): |
| 731 | return [''] |
| 732 | |
| 733 | def field_type(self): |
| 734 | return self.dtype |
| 735 |
no outgoing calls
searching dependent graphs…