Open ashvardanian opened 3 months ago
was able to get a .NET7 env locally.
can easily reproduce on the indicated SHA:
dotnet test -c Debug --logger "console;verbosity=detailed" --filter "FullyQualifiedName=Cloud.Unum.USearch.Tests.UsearchIndexTests.PersistAndRestore" > csharp-debug-macos-arm64.txt
The active test run was aborted. Reason: Test host process crashed
Test Run Aborted.
it would appear that something about the cleanup in the finally block (and the accesses on the out arrays), causes the crash. here’s the full isolated output w a ton of dubug statements sprinkled throughout the test and the search method.
is it possible it’s a race related to how the memory for those inout arrays is freed after it’s pinned?
i don’t know much about c# semantics, but when I comment out the handles free calls in the finally block, it passes about 1/5 of the time?! it still mostly fails tho.
Happy to spelunk further if this gives you any useful info!
think I found it:
index initialized as f64, seemingly intentionally by the comment which says "don't quantize": https://github.com/unum-cloud/usearch/blob/75eb7736158e2d8001481f1fb612c2697482ff8b/csharp/src/Cloud.Unum.USearch.Tests/USearchIndexTests.cs#L57
but the vector (as indexed and queried) is a float/f32, rather than a double/f64: https://github.com/unum-cloud/usearch/blob/75eb7736158e2d8001481f1fb612c2697482ff8b/csharp/src/Cloud.Unum.USearch.Tests/USearchIndexTests.cs#L64
this should do it:
diff --git a/csharp/src/Cloud.Unum.USearch.Tests/USearchIndexTests.cs b/csharp/src/Cloud.Unum.USearch.Tests/USearchIndexTests.cs
index f69b9e5..508b119 100644
--- a/csharp/src/Cloud.Unum.USearch.Tests/USearchIndexTests.cs
+++ b/csharp/src/Cloud.Unum.USearch.Tests/USearchIndexTests.cs
@@ -61,7 +61,7 @@ public class UsearchIndexTests
expansionSearch: 19 // Control the quality of search, optional
);
- var vector = new float[] { 0.2f, 0.6f, 0.4f };
+ var vector = new double[] { 0.2f, 0.6f, 0.4f };
index.Add(42, vector);
I'll put up a PR w this patch and unfiltering the test here in a few.
Interesting. I believe using double is a good idea, but in either case the process shouldn't crash... I'd simply expect the following assertion to fail. So there may be a problem inferring the type of vector, assuming a larger buffer, writing out-of-bounds... and finally crashing. Can it be the case?
yes something to that effect sounds likely — is it necessary the query vector align w the index precision type? and should add check/enforce the precision isn’t less than the index precision?
quantization is one thing, so more precise must be allowed but an improperly configured index silently allowing less precise data seems like a potential footgun. perhaps it could cast the input vector to the appropriate type given the index’s expected precision as a middle ground?
is it necessary the query vector align w the index precision type?
No, those are independent variables.
should add check/enforce the precision isn’t less than the index precision?
No need for that.
perhaps it could cast the input vector to the appropriate type given the index’s expected precision as a middle ground?
It performs the needed casts under the hood already.
What's weird - this only appears on MacOS... and only with C# bindings/tests.
Are there tests that exercise a similar code path on other platforms or for other languages? It seems like a mistake, rather than an intentional test case designed to pass a smaller than expected value.
But agreed it ideally shouldn’t crash regardless.
Not exactly the same test, but it should be easy to add in test.cpp using the test_punned_add_remove_vector function on the main-dev branch as a reference.
Describe the bug
Weirdly, all C# tests pass on most platforms, but one of them fails on MacOS, and I don't know where it's coming from.
Steps to reproduce
On macOS with Arm-based chips:
This fails. But excluding that one test fixes things.
Expected behavior
Tests passing
USearch version
33c997e3b5f2ef7f8e28942961576d1cf52bc3a5
Operating System
macOS Sonoma
Hardware architecture
Arm
Which interface are you using?
Other bindings
Contact Details
No response
Are you open to being tagged as a contributor?
.git
history as a contributorIs there an existing issue for this?
Code of Conduct