-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmixturedata.py
More file actions
64 lines (49 loc) · 1.58 KB
/
mixturedata.py
File metadata and controls
64 lines (49 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from typing import (
Collection,
Generic,
TypeVar,
Union,
Sequence,
Any,
List,
)
# from singledispatchmethod import singledispatchmethod # pip install
from dataclasses import dataclass
import numpy as np
T = TypeVar("T")
@dataclass
class MixtureParameters(Generic[T]):
__slots__ = ["weights", "components"]
weights: np.ndarray
components: Sequence[T]
# class Array(Collection[T], Generic[T]):
# def __getitem__(self, key):
# ...
# def __setitem__(self, key, vaule):
# ...
# @dataclass
# class MixtureParametersList(Generic[T]):
# weights: np.ndarray
# components: Array[Sequence[T]]
# @classmethod
# def allocate(cls, shape: Union[int, Tuple[int, ...]], component_type: T):
# shape = (shape,) if isinstance(shape, int) else shape
# # TODO
# raise NotImplementedError
# @singledispatchmethod
# def __getitem__(self, key: Any) -> "MixtureParametersList[T]":
# return MixtureParametersList(self.weights[key], self.components[key])
# @__getitem__.register
# def _(self, key: int) -> MixtureParameters:
# return MixtureParameters(self.weights[key], self.components[key])
# def __setitem__(
# self,
# key: Union[int, slice],
# value: "Union[MixtureParameters[T], MixtureParametersList[T]]",
# ) -> None:
# self.weights[key] = value.weights
# self.components[key] = value.components
# def __len__(self):
# return self.weights.shape[0]
# def __iter__(self):
# yield from (self[k] for k in range(len(self)))