Add comprehensive unit tests for animl/reid/#275
Merged
Conversation
Agent-Logs-Url: https://github.com/conservationtechlab/animl-py/sessions/e39dd8c7-1dce-45ff-8b61-605739ccb918 Co-authored-by: tkswanson <4371698+tkswanson@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add comprehensive unit tests for reid distance functions
Add comprehensive unit tests for Apr 23, 2026
animl/reid/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No unit tests existed for
src/animl/reid/. This addstests/test_reid.pywith full coverage of the distance, miewid, and inference modules, following the sameunittest.TestCaseconventions astest_classification.py.Test classes
TestRemoveDiagonal— shape correctness, non-squareValueError, diagonal removalTestEuclideanSquaredDistance— output shape, self-distance=0, known values (3²+4²=25), non-negativityTestCosineDistance— identical/orthogonal/opposite vectors, range clamped to [0, 2]TestComputeDistanceMatrix— numpy and torch inputs,(m,n)shapes, unknown metric raisesValueError, 1-D input raisesAssertionError, self-diagonal ≈ 0TestComputeBatchedDistanceMatrix— shape, batched vs. unbatched parity, torch tensor input,batch_size > nTestL2Norm— unit-norm output per row, shape invarianceTestGeM— forward shape(b, c, 1, 1),reprcontainsp=andeps=TestMiewIdNet—pretrained=False(no network I/O);extract_featreturns 2-D tensor with correct batch dim;forwardoutput equalsextract_featTestLoadMiew— skipped viaunittest.SkipTestwhen neithermodels/miewid.ptnormodels/miewid.onnxis present; validates.frameworkattribute and eval modeTestExtractMiewEmbeddings— skipped when model or ground-truth CSV is absent; checks ndarray return, row count, positive embedding dim, finiteness, andValueErroron missingfile_col38 tests total; 2 model-dependent classes skip gracefully in environments without downloaded weights.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
dns.google/usr/bin/python python -c import numpy; import torch; import animl(dns block)/usr/bin/python python -m unittest discover -s tests -p test_reid.py -v(dns block)one.one.one.one/usr/bin/python python -c import numpy; import torch; import animl(dns block)/usr/bin/python python -m unittest discover -s tests -p test_reid.py -v(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Create
tests/test_reid.pyon thedevbranch with comprehensive unit tests forsrc/animl/reid/. Follow the exact same style astests/test_classification.py—unittest.TestCasesubclasses,setUpClasswithunittest.SkipTestfor model-dependent classes, andunittest.main()at the bottom.Source modules to test
src/animl/reid/distance.pyremove_diagonal(A)— removes diagonal from a squaretorch.Tensor; raisesValueErroron non-squareeuclidean_squared_distance(input1, input2)— returnstorch.Tensorof shape(m, n)cosine_distance(input1, input2)— returnstorch.Tensorof shape(m, n)compute_distance_matrix(input1, input2, metric)— wrapper; accepts numpy or torch; returnsnp.ndarray; raisesValueErroron unknown metric or wrong dimscompute_batched_distance_matrix(input1, input2, metric, batch_size)— batched version usingscipy.spatial.distance.cdist; returnsnp.ndarraysrc/animl/reid/inference.pyload_miew(file_path, device)— loads.pt(torch) or.onnxmodel; sets.frameworkattrextract_miew_embeddings(miew_model, manifest, file_col, batch_size, num_workers, device)— returnsnp.ndarray; raisesValueErrorwhenfile_colmissingsrc/animl/reid/miewid.pyl2_norm(input, axis)— returns unit-norm tensorGeM— pooling module, forward produces a tensorMiewIdNet— instantiates on CPU withpretrained=False;extract_featreturns correct embedding shapeTest classes to implement
TestRemoveDiagonalNo model needed. Use
torch.Tensorinputs.TestEuclideanSquaredDistanceNo model needed.
TestCosineDistanceNo model needed.
TestComputeDistanceMatrixNo model needed.