|View source on GitHub|
Represents linear combination of things.
cirq.LinearDict( terms: Optional[Mapping[TVector, Scalar]] = None, validator: Callable[[TVector], bool] = None ) -> None
LinearDict implements the basic linear algebraic operations of vector addition and scalar multiplication for linear combinations of abstract vectors. Keys represent the vectors, values represent their coefficients. The only requirement on the keys is that they be hashable (i.e. are immutable and implement hash and eq with equal objects hashing to equal values).
A consequence of treating keys as opaque is that all relationships between the keys other than equality are ignored. In particular, keys are allowed to be linearly dependent.
||Mapping of abstract vectors to coefficients in the linear combination being initialized.|
||Optional predicate that determines whether a vector is valid or not. Dictionary and linear algebra operations that would lead to the inclusion of an invalid vector into the combination raise ValueError exception. By default all vectors are valid.|
clean( *, atol: float = 1e-09 ) -> 'TSelf'
Remove terms with coefficients of absolute value atol or less.
D.clear() -> None. Remove all items from D.
copy() -> 'TSelf'
fromkeys( vectors, coefficient=0 )
get( vector, default=0 )
D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
items() -> ItemsView[TVector, Scalar]
D.items() -> a set-like object providing a view on D's items
keys() -> KeysView[TVector]
D.keys() -> a set-like object providing a view on D's keys
pop( key, default=__marker )
D.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised.
D.popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple; but raise KeyError if D is empty.
setdefault( key, default=None )
D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D
update( *args, **kwargs )
D.update([E, ]**F) -> None. Update D from mapping/iterable E and F. If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
values() -> ValuesView[Scalar]
D.values() -> an object providing a view on D's values
__add__( other: 'TSelf' ) -> 'TSelf'
__bool__() -> bool
__contains__( vector: Any ) -> bool
__eq__( other: Any ) -> bool
Checks whether two linear combinations are exactly equal.
Presence or absence of terms with coefficients exactly equal to zero does not affect outcome.
Not appropriate for most practical purposes due to sensitivity to numerical error in floating point coefficients. Use cirq.approx_eq() instead.
__getitem__( vector: TVector ) -> Scalar
__iter__() -> Iterator[TVector]
__len__() -> int
__mul__( a: Scalar ) -> 'TSelf'
__ne__( other: Any ) -> bool
Checks whether two linear combinations are not exactly equal.
__neg__() -> 'TSelf'
__rmul__( a: Scalar ) -> 'TSelf'
__sub__( other: 'TSelf' ) -> 'TSelf'
__truediv__( a: Scalar ) -> 'TSelf'