-
Notifications
You must be signed in to change notification settings - Fork 25
Modifications for linear algebra #18
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module linsolve | ||
|
||
|
||
using SparseArrays,Sparspak,DynamicQuantities, LinearAlgebra | ||
using GenericLinearAlgebra | ||
|
||
function makeproblem(n;dimA=DynamicQuantities.Dimensions(length=1),dimb=DynamicQuantities.Dimensions(tim=1)) | ||
A=-sprand(n,n,0.5)+100I | ||
SparseMatrixCSC(size(A)...,A.colptr,A.rowval,Quantity.(A.nzval,dimA)), Quantity.(rand(n),dimb) | ||
|
||
# [ Quantity(b0[i],length=1) for i=1:n] | ||
#DynamicQuantities.Quantity.(rand(10),time=1) | ||
end | ||
|
||
|
||
function densetest(n) | ||
As,b=makeproblem(n) | ||
A=Matrix(As) | ||
lu(A)\b | ||
end | ||
|
||
function sparsetest(n) | ||
A,b=makeproblem(n) | ||
sparspaklu(A)\b | ||
end | ||
|
||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't you want a DimensionError to still be raised even if
iszero
is true? If adding a 2D vector to a 3D vector, you would always want to raise an error, regardless of if one of them was zero, no?It might not even be the case that
iszero
is defined for all possibleQuantity
, since the value of aQuantity
might be an abstract object, rather than just a scalar realThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use case is that there are places where a value is initialized with zero, and than += or -= are used to add other quantities to it.
This can be solved also e.g. in Sparspak. But IMHO it this belongs to the algebraic properties of Quantity. What is
zero
and what isone
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like other unit packages also raise DimensionErrors even if the value is zero. e.g., astropy:
likewise with Unitful.jl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "zero meters" + "one second" raising an error makes the most sense as a default? Thoughts?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Sparspak maybe you can do:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had it running like this, so for sparspak I certainly could switch to this. But sparspak may not be the only place where this functionality may be needed.
Fundamentally this leads to the question how units are working algebraically. I'll try to think more about it to find a less ad-hoc approach.
IMHO it would be good if DynamicQuantities could be used like Dual numbers, MultiFloats, Measurements and the like as a drop-in replacement for Float64.
But I am aware that this may be not everyone's version for this package.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think even if there are a few additional packages that need this, it is better left out of the main package, because it will slow down every call to
+
with 3x as many comparisons on the dimensions (i.e., rather than justdimension(l) == dimension(r)
, now it has to also computedimension(l) == Dimensions()
anddimension(r) == Dimensions()
).