Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Feb 1, 2022
1 parent 19812a5 commit b3470ff
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
32 changes: 32 additions & 0 deletions tests/test_decorator.py
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-

"""Trivial version test."""

import unittest

import torch

from torch_max_mem import maximize_memory_utilization


def knn(x, y, batch_size, k: int = 3):
return torch.cat(
[
torch.cdist(x[start: start + batch_size], y).topk(k=k, dim=0, largest=False).indices
for start in range(0, x.shape[0], batch_size)
],
dim=0,
)


wrapped_knn = maximize_memory_utilization(parameter_name="batch_size")(knn)


class TestDecorator(unittest.TestCase):
"""Test the decorator."""

def test_knn(self):
x = torch.rand(100, 100)
y = torch.rand(200, 100)
for batch_size in [1, 10, x.shape[0]]:
self.assertEqual(knn(x, y, batch_size), wrapped_knn(x, y, batch_size=x.shape[0]))
19 changes: 0 additions & 19 deletions tests/test_version.py

This file was deleted.

0 comments on commit b3470ff

Please sign in to comment.