Skip to content

Commit 13a338c

Browse files
check for torch.linalg.lstsq instead of inconsistent torch.__version__
1 parent dec5429 commit 13a338c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

torchstain/torch/normalizers/macenko.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ def __init__(self):
1414
[0.7201, 0.8012],
1515
[0.4062, 0.5581]])
1616
self.maxCRef = torch.tensor([1.9705, 1.0308])
17-
self.deprecated_torch = torch.__version__ < (1,9,0)
17+
18+
# Avoid using deprecated torch.lstsq (since 1.9.0)
19+
self.updated_lstsq = hasattr(torch.linalg, 'lstsq')
1820

1921
def __convert_rgb2od(self, I, Io, beta):
2022
I = I.permute(1, 2, 0)
@@ -50,7 +52,7 @@ def __find_concentration(self, OD, HE):
5052
Y = OD.T
5153

5254
# determine concentrations of the individual stains
53-
if self.deprecated_torch:
55+
if not self.updated_lstsq:
5456
return torch.lstsq(Y, HE)[0][:2]
5557

5658
return torch.linalg.lstsq(HE, Y)[0]

0 commit comments

Comments
 (0)