MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Dimension

Class Dimension

tensorflow/python/framework/tensor_shape.py:181–699  ·  view source on GitHub ↗

Represents the value of one dimension in a TensorShape.

Source from the content-addressed store, hash-verified

179
180@tf_export(v1=["Dimension"])
181class Dimension(object):
182 """Represents the value of one dimension in a TensorShape."""
183
184 def __init__(self, value):
185 """Creates a new Dimension with the given value."""
186 if value is None:
187 self._value = None
188 elif isinstance(value, Dimension):
189 self._value = value.value
190 elif isinstance(value, dtypes.DType):
191 raise TypeError("Cannot convert %s to Dimension" % value)
192 else:
193 self._value = int(value)
194 if (not isinstance(value, compat.bytes_or_text_types) and
195 self._value != value):
196 raise ValueError("Ambiguous dimension: %s" % value)
197 if self._value < 0:
198 raise ValueError("Dimension %d must be >= 0" % self._value)
199
200 def __repr__(self):
201 return "Dimension(%s)" % repr(self._value)
202
203 def __str__(self):
204 value = self._value
205 return "?" if value is None else str(value)
206
207 def __eq__(self, other):
208 """Returns true if `other` has the same known value as this Dimension."""
209 try:
210 other = as_dimension(other)
211 except (TypeError, ValueError):
212 return NotImplemented
213 if self._value is None or other.value is None:
214 return None
215 return self._value == other.value
216
217 def __ne__(self, other):
218 """Returns true if `other` has a different known value from `self`."""
219 try:
220 other = as_dimension(other)
221 except (TypeError, ValueError):
222 return NotImplemented
223 if self._value is None or other.value is None:
224 return None
225 return self._value != other.value
226
227 def __int__(self):
228 return self._value
229
230 # This is needed for Windows.
231 # See https://github.com/tensorflow/tensorflow/pull/9780
232 def __long__(self):
233 return self._value
234
235 def __index__(self):
236 # Allow use in Python 3 range
237 return self._value
238

Callers 13

dimension_at_indexFunction · 0.70
merge_withMethod · 0.70
__add__Method · 0.70
__sub__Method · 0.70
__rsub__Method · 0.70
__mul__Method · 0.70
__floordiv__Method · 0.70
__rfloordiv__Method · 0.70
__mod__Method · 0.70
as_dimensionFunction · 0.70
__getitem__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected