Skip to content

Commit

Permalink
Merge branch 'romain_dev_from_clean' of https://github.com/openspyrit…
Browse files Browse the repository at this point in the history
…/spyrit into romain_dev_from_clean
  • Loading branch information
romainphan committed Jun 11, 2024
2 parents 0d95434 + 6f6c284 commit 673834d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions spyrit/core/meas.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,18 @@ def _set_P(self, H_static: torch.tensor) -> None:
torch.cat([H_pos, H_neg], 1).view(2 * H_static.shape[0], H_static.shape[1]),
requires_grad=False,
)

def _build_pinv(self, tensor: torch.tensor, reg: str, eta: float
) -> torch.tensor:


def _build_pinv(self, tensor: torch.tensor, reg: str, eta: float) -> torch.tensor:

if reg == "L1":
pinv = torch.linalg.pinv(tensor, atol=eta)

elif reg == "L2":
if tensor.shape[0] >= tensor.shape[1]:
pinv = (
torch.linalg.inv(tensor.T @ tensor
+ eta * torch.eye(tensor.shape[1]))
torch.linalg.inv(
tensor.T @ tensor + eta * torch.eye(tensor.shape[1])
)
@ tensor.T
)
else:
Expand All @@ -347,7 +347,7 @@ def _build_pinv(self, tensor: torch.tensor, reg: str, eta: float
+ "choose either 'L1', 'L2' or 'H1'."
)
return pinv

def _attributeslist(self) -> list:
_list = [
("M", "self.M", _Base),
Expand Down Expand Up @@ -507,7 +507,7 @@ def get_H(self) -> torch.tensor:
)
return self.H

def build_H_pinv(self, reg: str = 'L1', eta: float = 1e-3) -> None:
def build_H_pinv(self, reg: str = "L1", eta: float = 1e-3) -> None:
"""Used to set the pseudo inverse of the measurement matrix :math:`H`
using `torch.linalg.pinv`. The result is stored in the attribute
:attr:`H_pinv`.
Expand Down
2 changes: 1 addition & 1 deletion spyrit/core/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def neumann_boundary(img_shape):
Returns:
:class:`torch.tensor`: The finite difference matrix.
.. note::
This function returns the same matrix as :func:`finite_diff_mat` with
the Neumann boundary condition. Internal implementation is different
Expand Down

0 comments on commit 673834d

Please sign in to comment.