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

Refactor binary-operations #11

Open
snunez1 opened this issue Aug 21, 2023 · 7 comments
Open

Refactor binary-operations #11

snunez1 opened this issue Aug 21, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@snunez1
Copy link

snunez1 commented Aug 21, 2023

This consists of:

  1. Developing a high level generic API based on numpy's linear algebra operations. Best location is probably array-operations
  2. Implement them in lisp by refactoring or replacing the existing functions

Then implement the same in LLA so the API's match.

@snunez1 snunez1 added the enhancement New feature or request label Aug 21, 2023
@snunez1 snunez1 self-assigned this Aug 21, 2023
@snunez1
Copy link
Author

snunez1 commented Sep 2, 2023

I have just pushed a branch that implements greatly simplified versions of the functions in binary-operations. This also introduces a new package linalg. I propose that as we refactor, we move to a single name space and drop linear-algebra and linear-algebra (or possibly have linalg as a nickname if we like linear-algebra for stylistic reasons.

Some notes:

  • It isn't feasible to have an external definition of the generic functions due to packaging. Well, it's possible, but fragile and ugly. I think it's simpler to just have both linalg and lla agree to use the same function names, and then import on a selective basis, as was suggested in Develop backend dispatch pattern #6.
  • I have dropped scaling parameters in the new implementations. A lot of effort seems to have gone into making scaling various parameters as part of the internals of the function call. I think it's better to make it explicit: call scale on an array before passing it. See the binops tests for an example of what the new style looks like.
  • I have left the original functions in the same package. As well I've only added tests for the new functions that mirror the old ones. The reason is that we may need them during the transition, especially with the specialised matrix types (hermitian, etc). Although, I question whether they are worth keeping. I'll open an issue for this.

@beberman, are you able to work on completing the tests? I have converted a few to show how it's done; it's search and replace from here on. I've got some critical coursework to prepare, and if you could get these tests completed it will be a huge step forward for us, plus get another pair of eyes on the work.

@beberman
Copy link
Collaborator

beberman commented Sep 8, 2023 via email

@beberman
Copy link
Collaborator

beberman commented Sep 12, 2023 via email

@snunez1
Copy link
Author

snunez1 commented Sep 13, 2023

  1. It appears that all the destructive operations nadd, nmultiply ect. will no longer be supported. All operations now generate a new array. Clearly there are memory costs to this decision. Does it matter? I'm not certain which has faster cpu performance.

The way it's written now, all the operations are destructive, they're just not named as such. I don't think the destructive/non-consing distinction makes sense when dealing with arrays. I am not aware of any other libraries (Numpy, R) that work this way either. It seems a relic of old-lisp where everything was cons based and those were expensive operations. Happy to reconsider though.

  1. The code in src/kernel/binary-operations has the scaled-binary-operations commented out. This actually leads to this entire file being non-functional so it should be deleted?

It can be deleted. I left it there as a reminder in case we had to go back and refer to them whilst updating the specialised matrix types, but I supposed we can also use git history for that.

  1. The file src/linalg was created (copied) from lla and put in the linalg name space. Why is it in that name space? I see that you say this introduced the new package but why in this refactor did you introduce that new package? I think the decision to either stick with linear-algebra or move to linalg should be made now. Then this package can have consistent names and then those names can be used in the tests. I would like to get the src code into the final form before rewriting the tests. A lot of the tests can just be deleted. There is no reason to test scaling the first, second, and both vectors before adding since scale is now destructive it just needs to be tested individually and then add and multiply can be tested individually.

The intention is to merge linear-algebra and linear-algebra-kernel into a single namespace. Since we were talking about linalg, I chose that, but it could just as easily be linear-algebra. If you want to complete the namespace refactoring, I agree that now's a good time to do so. As for scaling: agreed. Some of the tests he wrote don't make any sense and are duplicates to a large degree and we can greatly simplify the tests too.

@beberman
Copy link
Collaborator

beberman commented Sep 13, 2023 via email

@beberman
Copy link
Collaborator

beberman commented Sep 13, 2023 via email

@snunez1
Copy link
Author

snunez1 commented Sep 13, 2023

I'm also confused about what's happening with the underlying types here. It appears that your new code relies on the built in vector type which eliminates the distinction between row and column vectors (I'm ok with that). It is also using the built-in array type. However the code in data-vector at least and potentially the other type files is still using the linear-algebra types. So how would you like to refactor that code? Let's resolve this before testing. Best, -Brian On Wed, Sep 13, 2023 at 9:08 AM Brian Eberm

Correct, there's no benefit to a specialised dense array type, only added complexity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants