Skip to content

Commit

Permalink
feat: differential times a Quantity
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <[email protected]>
  • Loading branch information
nstarman committed Feb 29, 2024
1 parent 32b57be commit 421dac6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/vector/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,32 @@ def integral_cls(cls) -> type["AbstractVectorDifferential"]:
"""
raise NotImplementedError

# ===============================================================
# Binary operations

@dispatch # type: ignore[misc]
def __mul__(
self: "AbstractVectorDifferential", other: Quantity
) -> "AbstractVector":
"""Multiply the vector by a :class:`jax_quantity.Quantity`.
Examples
--------
>>> from jax_quantity import Quantity
>>> from vector import RadialDifferential
>>> dr = RadialDifferential(Quantity(1, "m/s"))
>>> vec = dr * Quantity(2, "s")
>>> vec
RadialVector(r=Quantity[PhysicalType('length')](value=f32[], unit=Unit("m")))
>>> vec.r
Quantity['length'](Array(2., dtype=float32), unit='m')
"""
return self.integral_cls.constructor(
{k[2:]: v * other for k, v in dataclass_items(self)}
)

# ===============================================================
# Convenience methods

Expand Down

0 comments on commit 421dac6

Please sign in to comment.