Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: constructor #30

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/vector/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import jax
import jax.numpy as jnp
from jax_quantity import Quantity
from plum import dispatch

from ._utils import dataclass_items, full_shaped

Expand Down Expand Up @@ -43,6 +44,17 @@
types. All fields of the vector are expected to be components of the vector.
"""

# ---------------------------------------------------------------
# Constructors

@classmethod
@dispatch # type: ignore[misc]
def constructor(
cls: "type[AbstractVectorBase]", obj: Mapping[str, Any], /
) -> "AbstractVectorBase":
"""Construct a vector from a mapping."""
return cls(**obj)

Check warning on line 56 in src/vector/_base.py

View check run for this annotation

Codecov / codecov/patch

src/vector/_base.py#L56

Added line #L56 was not covered by tests

# ===============================================================
# Array

Expand Down