Ejemplo n.º 1
0
def permutate_and_take_min(h: np.array, A: np.array, B: np.array) -> np.array:
    hashes = h.repeat(A.shape[0]).reshape(h.shape[0], A.shape[0])
    hashes = (A * hashes + B) % _mersenne_prime
    # minhashes = np.empty(hashes.shape[1])
    # for i in range(hashes.shape[1]):
    #     minhashes[i] = hashes[:, i].min()
    minhashes = [hashes[:, i].min() for i in range(hashes.shape[1])]
    return minhashes
Ejemplo n.º 2
0
 def to_tensor(self,
               arr: np.array,
               normalize: bool = False,
               repeat_channels: int = None) -> torch.Tensor:
     """
     Transform an array to a torch Tensor of type Float64 and shape [C, W, H]
     """
     if normalize:
         arr = arr / arr.max()
     else:
         arr = arr * 1.0
     arr = torch.tensor(arr, device=self._device)
     if len(arr.shape) <= 2:
         arr = arr.unsqueeze(0)
     if repeat_channels:
         arr = arr.repeat(repeat_channels, 1, 1)
     return arr