Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add len(NadaArray) and hstack/vstack as nada-algebra funcs #11

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion nada_algebra/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,27 @@ def wrapper(*args, **kwargs):

return attr

def __setattr__(self, name, value):
def __setattr__(self, name: str, value: Any):
"""
Overrides the default behavior of setting attributes.

If the attribute name is "inner", it sets the attribute value directly.
Otherwise, it sets the attribute value on the inner object.

Args:
name (str): The name of the attribute.
value: The value to set for the attribute.
"""
if name == "inner":
super().__setattr__(name, value)
else:
setattr(self.inner, name, value)

def __len__(self):
"""
Overrides the default behavior of returning the length of the object.

Returns:
int: The length of the inner numpy array.
"""
return len(self.inner)
26 changes: 26 additions & 0 deletions nada_algebra/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,29 @@ def output(arr: NadaArray, party: Party, prefix: str):
list: A list of Output objects.
"""
return NadaArray.output_array(arr, party, prefix)


def vstack(arr_list: list) -> NadaArray:
"""
Stack arrays in sequence vertically (row wise).

Args:
arr_list (list): A list of NadaArray objects to stack.

Returns:
NadaArray: The stacked NadaArray.
"""
return NadaArray(np.vstack(arr_list))


def hstack(arr_list: list) -> NadaArray:
"""
Stack arrays in sequence horizontally (column wise).

Args:
arr_list (list): A list of NadaArray objects to stack.

Returns:
NadaArray: The stacked NadaArray.
"""
return NadaArray(np.hstack(arr_list))
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nada-algebra"
version = "0.1.1"
version = "0.2.0"
description = ""
authors = ["José Cabrero-Holgueras <[email protected]>"]
readme = "README.md"
Expand Down
Loading