Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Decoders support
Browse files Browse the repository at this point in the history
  • Loading branch information
aMarcireau committed Jan 12, 2024
1 parent 115633b commit 4d7480a
Show file tree
Hide file tree
Showing 32 changed files with 2,455 additions and 525 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
name: wheelhouse
path: wheelhouse
- run: python -m pip install --find-links wheelhouse faery
- run: python -c 'import faery'
- run: python test.py
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
*.so
.venv
__pycache__
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "python"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

[lib]
Expand All @@ -17,3 +17,7 @@ pyo3 = {version = "0.20.1", features = ["extension-module"]}
roxmltree = "0.19.0"
thiserror = "1.0"
zstd = "0.13.0"

[profile.release]
lto = "fat"
codegen-units = 1
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
{name = "International Centre for Neuromorphic Systems"},
{name = "Alexandre Marcireau"},
]
version = "0.1.0"
version = "0.1.1"
requires-python = ">=3.8"
dependencies = ["numpy>=1.24"]

Expand Down
26 changes: 23 additions & 3 deletions python/faery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,35 @@
from .stream import Stream as Stream
from .stream import TimestampOffset as TimestampOffset

if typing.TYPE_CHECKING:
from . import aedat # type: ignore
from . import dat # type: ignore
from . import event_stream # type: ignore
from . import evt # type: ignore
else:
from .faery import aedat
from .faery import dat
from .faery import event_stream
from .faery import evt


def stream_from_file(
path: typing.Union[str, pathlib.Path],
stream_id: typing.Optional[int] = None,
size_fallback: tuple[int, int] = (1280, 720),
version_fallback: str | None = None,
file_type: decoder.FileType | None = None,
) -> Stream:
if isinstance(path, str):
path = pathlib.Path(path)
return Decoder(path=path, stream_id=stream_id)
return Decoder(
path=path,
stream_id=stream_id,
size_fallback=size_fallback,
version_fallback=version_fallback,
file_type=file_type,
)


def stream_from_array(events: numpy.ndarray) -> Stream:
return Array(events=events)
def stream_from_array(events: numpy.ndarray, width: int, height: int) -> Stream:
return Array(events=events, width=width, height=height)
20 changes: 20 additions & 0 deletions python/faery/aedat.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from __future__ import annotations

import pathlib
import typing
import types

import numpy

class Decoder:
def __init__(self, path: typing.Union[pathlib.Path, str]): ...
def __enter__(self) -> Decoder: ...
def __exit__(
self,
exception_type: typing.Optional[typing.Type[BaseException]],
value: typing.Optional[BaseException],
traceback: typing.Optional[types.TracebackType],
) -> bool: ...
def __iter__(self) -> Decoder: ...
def __next__(self) -> dict[str, numpy.ndarray]: ...
def id_to_stream(self) -> dict[int, dict[str, typing.Union[str, int]]]: ...
28 changes: 28 additions & 0 deletions python/faery/dat.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import annotations

import pathlib
import typing
import types

import numpy

class Decoder:
event_type: typing.Literal["2d", "dvs", "trigger"]
width: int
height: int

def __init__(
self,
path: typing.Union[pathlib.Path, str],
size_fallback: typing.Optional[tuple[int, int]] = None,
version_fallback: typing.Optional[typing.Literal["DAT1", "DAT2"]] = None,
): ...
def __enter__(self) -> Decoder: ...
def __exit__(
self,
exception_type: typing.Optional[typing.Type[BaseException]],
value: typing.Optional[BaseException],
traceback: typing.Optional[types.TracebackType],
) -> bool: ...
def __iter__(self) -> Decoder: ...
def __next__(self) -> numpy.ndarray: ...
Loading

0 comments on commit 4d7480a

Please sign in to comment.