-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unexcellent
committed
Nov 13, 2024
1 parent
991c2b5
commit 5dd38de
Showing
5 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Generic, TypeVar | ||
|
||
import numpy as np | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
class Vector(Generic[T]): | ||
"""A vector of either quanity or numeric elements.""" | ||
|
||
_elements: np.array | ||
|
||
def __init__(self, elements: list | tuple | np.ndarray) -> None: | ||
self._elements = np.array(elements) | ||
|
||
@classmethod | ||
def __class_getitem__(cls, *_: object) -> type: | ||
"""Return this class for type hinting.""" | ||
return cls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import pytest | ||
|
||
import numpy as np | ||
|
||
from quantio import Vector, Length | ||
|
||
|
||
def test_init(): | ||
actual: Vector[Length] = Vector([Length.zero(), Length.zero()]) | ||
assert np.all(actual._elements == np.array([Length.zero(), Length.zero()])) | ||
|
||
|
||
def test_init_with_type_hint(): | ||
actual = Vector[Length]([Length.zero(), Length.zero()]) | ||
assert np.all(actual._elements == np.array([Length.zero(), Length.zero()])) | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest.main([__file__, "-v"]) |