-
Notifications
You must be signed in to change notification settings - Fork 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
To array and to sparse functions are ready for linearoperator #368
base: devel
Are you sure you want to change the base?
Conversation
if BoS == "b": | ||
comm = self.domain.spaces[0].cart.comm | ||
elif BoS == "s": | ||
comm = self.domain.cart.comm |
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.
If it is not a Blockvector
or a Stencilvector
then comm
is not defined. I would add an assert
in the beginning.
psydac/linalg/basic.py
Outdated
# We iterate over all the entries that belong to rank number currentrank | ||
for i in itertools.product(*itterables): | ||
if (rank == currentrank): | ||
v[i] = 1.0 |
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 a single line v[i] = (rank == currentrank)
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 tried to implement this using.
v[i] = float(rank == currentrank).
For the sequential tests, it worked. But for the parallel tests, it failed.
I am unsure why, so I left it as is.
psydac/linalg/basic.py
Outdated
else: | ||
# I cannot conceive any situation where this error should be thrown, but I put it here just in case something unexpected happens. | ||
raise Exception( | ||
'Function toarray_struphy() only supports Stencil Vectors or Block Vectors.') |
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 you meant tosparse()
. An assert at the beginning would be better
# V is either a BlockVector or a StencilVector depending on the domain of the linear operator. | ||
if BoS == "b": | ||
# we collect all starts and ends in two big lists | ||
starts = [vi.starts for vi in v] |
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 it is possible to use the same code for both cases BoS == 'b'
and BoS == 's'
with some small changes, for instance:
starts = [vi.starts] if BoS == "s" else [vi.starts for vi in v]
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.
Although there are some similarities between the code for the BlockVectorSpaces and the StencilVectorSpaces, there are also a sizeable number of differences. Therefore, getting rid of the big if(BoS =="b")- elif(BoS =="s") would result in having to write a myriad of more tiny if-elif pairs. Which would negatively affect the readability of the code.
psydac/linalg/basic.py
Outdated
colarr.append(col) | ||
row.append(l) | ||
if (rank == currentrank): | ||
v[i] = 0.0 |
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.
and then v[i] -= (rank == currentrank)
psydac/linalg/basic.py
Outdated
#We need to determine if we are a blockvector or a stencilvector but we are not able to use | ||
#the BlockVectorSpace and StencilVectorSpace classes in here. So we use the following char. | ||
#This char is either a b for Blockvectors or an s for Stencilvectors | ||
BoS= str(self.domain)[15] |
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.
If in the future this string changes then tosparse()
would stop working. A potential alternative would be:
BoS = 'b' if hasattr(self.domain, 'spaces') else 's'
… _tosparse_array, that contains the functionality to get both the sparse matrix and the full matrix
…ide the main for loop that kept allocating memory unecessarily
@mateomarin97 We see that you have made changes to the code after Elena's questions, but it is not clear what exactly they are for. Could you please answer explicitly? |
Hello. The changes were just aesthetic. I made the code more readable by implementing the suggestions Elena mentioned. The only thing stopping this function from being ready is that for the sparse matrix case, I could not write a Pyccel kernel to replace the for loop that appends the new matrices entries since Pyccel did not support Python lists. As the code stands it works but it is too slow due to this problem. |
Now that I think about it I am fairly certain I have a newer version of this branch that I did not push. I will push it later. |
The default toarray and tosparse functions have been added to linearoperator.
Also, parallel tests for these functions have been written.