-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9bfe688
commit 5c7e22b
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,34 @@ | ||
from .form import Form | ||
from typing import List,overload, Literal, Optional | ||
from ..typing import TensorLike | ||
from ..sparse import COOTensor | ||
|
||
from ..backend import backend_manager as bm | ||
|
||
|
||
|
||
|
||
class LinearBlockForm(Form): | ||
_V = None | ||
|
||
def __init__(self, blocks:List): | ||
self.blocks = blocks | ||
self.sparse_shape = self._get_sparse_shape() | ||
|
||
def _get_sparse_shape(self): | ||
shape = [i._get_sparse_shape() for i in self.blocks] | ||
return (bm.sum(shape), ) | ||
|
||
@overload | ||
def assembly(self, *, retain_ints: bool=False) -> TensorLike: ... | ||
@overload | ||
def assembly(self, *, format: Literal['coo'], retain_ints: bool=False) -> COOTensor: ... | ||
@overload | ||
def assembly(self, *, format: Literal['dense'], retain_ints: bool=False) -> TensorLike: ... | ||
def assembly(self, *, format='dense', retain_ints: bool=False): | ||
self._V = [i.assembly(format=format, retain_ints=retain_ints)for i in self.blocks] | ||
self._v = bm.concatenate(self._V) | ||
return self._V | ||
|
||
Form.register(LinearBlockForm) | ||
|
This file contains 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