|
3 | 3 | and manipulation of arrays and party objects.
|
4 | 4 | """
|
5 | 5 |
|
6 |
| -from typing import Any, Callable, List, Sequence, Tuple, Union |
| 6 | +from typing import Any, Callable, List, Optional, Sequence, Tuple, Union |
7 | 7 |
|
8 | 8 | import numpy as np
|
9 | 9 | from nada_dsl import (Boolean, Integer, Output, Party, PublicInteger,
|
|
60 | 60 | ]
|
61 | 61 |
|
62 | 62 |
|
63 |
| -def parties(num: int, prefix: str = "Party") -> List[Party]: |
| 63 | +def parties(num: int, party_names: Optional[List[str]] = None) -> List[Party]: |
64 | 64 | """
|
65 | 65 | Create a list of Party objects with specified names.
|
66 | 66 |
|
67 | 67 | Args:
|
68 | 68 | num (int): The number of parties to create.
|
69 |
| - prefix (str, optional): The prefix to use for party names. Defaults to "Party". |
| 69 | + party_names (List[str], optional): Party names to use. Defaults to None. |
| 70 | +
|
| 71 | + Raises: |
| 72 | + ValueError: Raised when incorrect number of party names is supplied. |
70 | 73 |
|
71 | 74 | Returns:
|
72 |
| - List[Party]: A list of Party objects with names in the format "{prefix}{i}". |
| 75 | + List[Party]: A list of Party objects. |
73 | 76 | """
|
74 |
| - return [Party(name=f"{prefix}{i}") for i in range(num)] |
| 77 | + if party_names is None: |
| 78 | + party_names = [f"Party{i}" for i in range(num)] |
| 79 | + |
| 80 | + if len(party_names) != num: |
| 81 | + num_supplied_parties = len(party_names) |
| 82 | + raise ValueError( |
| 83 | + f"Incorrect number of party names. Expected {num}, received {num_supplied_parties}" |
| 84 | + ) |
| 85 | + |
| 86 | + return [Party(name=party_name) for party_name in party_names] |
75 | 87 |
|
76 | 88 |
|
77 | 89 | def __from_numpy(arr: np.ndarray, nada_type: NadaCleartextNumber) -> List:
|
|
0 commit comments