nystrom-ncut 0.0.1__py3-none-any.whl → 0.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
nystrom_ncut/__init__.py CHANGED
@@ -1,4 +1,7 @@
1
- from .ncut_pytorch import NCUT
1
+ from .ncut_pytorch import (
2
+ NCUT,
3
+ axis_align,
4
+ )
2
5
  from .propagation_utils import (
3
6
  affinity_from_features,
4
7
  propagate_eigenvectors,
@@ -6,7 +9,6 @@ from .propagation_utils import (
6
9
  quantile_normalize,
7
10
  )
8
11
  from .visualize_utils import (
9
- eigenvector_to_rgb,
10
12
  rgb_from_tsne_3d,
11
13
  rgb_from_umap_sphere,
12
14
  rgb_from_tsne_2d,
@@ -18,5 +20,3 @@ from .visualize_utils import (
18
20
  propagate_rgb_color,
19
21
  get_mask,
20
22
  )
21
- from .ncut_pytorch import nystrom_ncut, ncut
22
- from .ncut_pytorch import kway_ncut, axis_align
nystrom_ncut/common.py ADDED
@@ -0,0 +1,20 @@
1
+ from typing import Any
2
+
3
+ import numpy as np
4
+ import torch
5
+ import torch.nn.functional as Fn
6
+
7
+
8
+ def ceildiv(a: int, b: int) -> int:
9
+ return -(-a // b)
10
+
11
+
12
+ def lazy_normalize(x: torch.Tensor, n: int = 1000, **normalize_kwargs: Any) -> torch.Tensor:
13
+ numel = np.prod(x.shape[:-1])
14
+ n = min(n, numel)
15
+ random_indices = torch.randperm(numel)[:n]
16
+ _x = x.flatten(0, -2)[random_indices]
17
+ if torch.allclose(torch.norm(_x, **normalize_kwargs), torch.ones(n, device=x.device)):
18
+ return x
19
+ else:
20
+ return Fn.normalize(x, **normalize_kwargs)