Check the `base` storage atom.
(self, base: Atom)
| 1048 | return self.dtype.base.itemsize |
| 1049 | |
| 1050 | def _checkbase(self, base: Atom) -> None: |
| 1051 | """Check the `base` storage atom.""" |
| 1052 | if base.kind == "enum": |
| 1053 | raise TypeError( |
| 1054 | "can not use an enumerated atom " |
| 1055 | "as a storage atom: %r" % base |
| 1056 | ) |
| 1057 | |
| 1058 | # Check whether the storage atom can represent concrete values |
| 1059 | # in the enumeration... |
| 1060 | basedtype = base.dtype |
| 1061 | pyvalues = [value for (name, value) in self.enum] |
| 1062 | try: |
| 1063 | npgenvalues = np.array(pyvalues) |
| 1064 | except ValueError: |
| 1065 | raise TypeError("concrete values are not uniformly-shaped") |
| 1066 | try: |
| 1067 | npvalues = np.array(npgenvalues, dtype=basedtype.base) |
| 1068 | except ValueError: |
| 1069 | raise TypeError( |
| 1070 | "storage atom type is incompatible with " |
| 1071 | "concrete values in the enumeration" |
| 1072 | ) |
| 1073 | if npvalues.shape[1:] != basedtype.shape: |
| 1074 | raise TypeError( |
| 1075 | "storage atom shape does not match that of " |
| 1076 | "concrete values in the enumeration" |
| 1077 | ) |
| 1078 | if npvalues.tolist() != npgenvalues.tolist(): |
| 1079 | raise TypeError( |
| 1080 | "storage atom type lacks precision for " |
| 1081 | "concrete values in the enumeration" |
| 1082 | ) |
| 1083 | |
| 1084 | # ...with some implementation limitations. |
| 1085 | if npvalues.dtype.kind not in ["i", "u"]: |
| 1086 | raise NotImplementedError( |
| 1087 | "only integer concrete values " |
| 1088 | "are supported for the moment, sorry" |
| 1089 | ) |
| 1090 | if len(npvalues.shape) > 1: |
| 1091 | raise NotImplementedError( |
| 1092 | "only scalar concrete values " |
| 1093 | "are supported for the moment, sorry" |
| 1094 | ) |
| 1095 | |
| 1096 | def _get_init_args(self) -> dict[str, Any]: |
| 1097 | """Get a dictionary of instance constructor arguments.""" |