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

[SYSTEMDS-3758] Python API Builtin triu, tril, argmin, argmax and casting Scalar <-> Matrix <-> Frame #2113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

e-strauss
Copy link
Contributor

@e-strauss e-strauss commented Sep 23, 2024

This patch adds the builtin functions tril, triu, argmin (rowIndexMin) and argmax (rowIndexMax) to the python API. Additionally, I added functionalities to the python API to

  • cast matrices, frames and scalars
  • reshape matrices

I also extended the Scalar Output Type with boolean and integer

Copy link
Contributor

@Baunsgaard Baunsgaard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the content is good, however i really hope the casting can be modified according to my comment, i am not 100% sure it is possible but it would be great.

Furthermore, the PR contains formatting of frame and scalar, that should be moved to another PR.


def __str__(self):
return "FrameNode"

def nRow(self) -> 'Scalar':
return Scalar(self.sds_context, 'nrow', [self])
def nRow(self) -> "Scalar":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am fine with changing all of the return types to use " instead of ', but does it really make a difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the formatting comes from black, as you recommended

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, maybe we should add a verification in Github actions that analyze if the code base is all formated according to black, i have seen this in other repositories such as Modyn

The check would be simple to add in a new action using:
https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#check

return Scalar(self.sds_context, "as.scalar", [self])

def to_frame(self):
from systemds.operator import Frame
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cyclic dependency, i understand it is how i thought about it as well, however, maybe we need to add it afterwards dynamically instead.

See:

https://stackoverflow.com/questions/972/adding-a-method-to-an-existing-object-instance-in-python

This would allow us to add the to_scalar, to_frame and to_matrix on the operation_node directly inside frame, matrix and scalar themselves to overwrite the operation node.

This would also allow us to have documentation on the method, since you add an empty method with docs that would throw an exception on the operation_node, and then on the import of Matrix etc it overwrite the Class method such that new instances use the overwritten method in Matrix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, currently the cyclic dependency error is avoided since the import happens inside the function, which won't be executed while importing afaik.

:param rows: number of rows
:param cols: number of columns, defaults to 1
:return: `Matrix` representing operation"""
return Matrix(self.sds_context, "matrix", [self, rows, cols])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rest of the functions looks good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move the formatting to another PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, move the formatting to another PR.

@@ -43,6 +43,8 @@ class OutputType(Enum):
NONE = auto()
SCALAR = auto()
STRING = auto()
INT = auto()
BOOLEAN = auto()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not valid, since both are instances of SCALAR,
where are they used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But isnt STRING also a value type of Scalar?

I added boolean and int there since in the scalar class, the value type of the scalar is determined by this. But you're right it would make more sense to put the value type in a different enum and create a new attribute, so that there is one field for the data type (matrix, frame, scalar) and one for the value types (double, integer, string, boolean)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, that would make more sense.

I think the reason why it is as it is now, is because someone (probably me) was lazy when making the initial version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants