Skip to content

Commit 3d2a6ac

Browse files
authored
Feat: Add len(NadaArray) and hstack/vstack as nada-algebra funcs (#11)
* feat: added hstack and vstack as na.functions and len(NadaArray) * chore: Bump version number for release * fix: comments
1 parent 10b9ffe commit 3d2a6ac

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

nada_algebra/array.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,27 @@ def wrapper(*args, **kwargs):
462462

463463
return attr
464464

465-
def __setattr__(self, name, value):
465+
def __setattr__(self, name: str, value: Any):
466+
"""
467+
Overrides the default behavior of setting attributes.
468+
469+
If the attribute name is "inner", it sets the attribute value directly.
470+
Otherwise, it sets the attribute value on the inner object.
471+
472+
Args:
473+
name (str): The name of the attribute.
474+
value: The value to set for the attribute.
475+
"""
466476
if name == "inner":
467477
super().__setattr__(name, value)
468478
else:
469479
setattr(self.inner, name, value)
480+
481+
def __len__(self):
482+
"""
483+
Overrides the default behavior of returning the length of the object.
484+
485+
Returns:
486+
int: The length of the inner numpy array.
487+
"""
488+
return len(self.inner)

nada_algebra/funcs.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,29 @@ def output(arr: NadaArray, party: Party, prefix: str):
216216
list: A list of Output objects.
217217
"""
218218
return NadaArray.output_array(arr, party, prefix)
219+
220+
221+
def vstack(arr_list: list) -> NadaArray:
222+
"""
223+
Stack arrays in sequence vertically (row wise).
224+
225+
Args:
226+
arr_list (list): A list of NadaArray objects to stack.
227+
228+
Returns:
229+
NadaArray: The stacked NadaArray.
230+
"""
231+
return NadaArray(np.vstack(arr_list))
232+
233+
234+
def hstack(arr_list: list) -> NadaArray:
235+
"""
236+
Stack arrays in sequence horizontally (column wise).
237+
238+
Args:
239+
arr_list (list): A list of NadaArray objects to stack.
240+
241+
Returns:
242+
NadaArray: The stacked NadaArray.
243+
"""
244+
return NadaArray(np.hstack(arr_list))

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "nada-algebra"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
description = ""
55
authors = ["José Cabrero-Holgueras <jose.cabrero@nillion.com>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)