Embeddings npyblock equals - CyrilB1531/lodestar GitHub Wiki
Development build. This page describes
main, not a released package. The latest published Lodestar.Embeddings is 0.7.0 — read its documentation.
Home › Embeddings › Loading vocabularies
Value equality over the elements and the shape.
public bool Equals(NpyBlock other)Parameters — other is the block to compare against.
Returns — bool, true when both blocks hold the same number of elements with equal values in
the same order, and declare the same shape.
Example — two reads of the same bytes.
using Lodestar.Embeddings.Persistence;
using var buffer = new MemoryStream();
NpyFile.Write(buffer, [1f, 2f, 3f, 4f], 2, 2);
byte[] bytes = buffer.ToArray();
NpyBlock first = NpyFile.Read(new ReadOnlyMemory<byte>(bytes));
NpyBlock second = NpyFile.Read(new ReadOnlyMemory<byte>(bytes));
bool equal = first.Equals(second); // => TrueRemarks — a record struct over ReadOnlyMemory<float> and a list would compare both by
reference, so two reads of one file were unequal
(the equality rule
is why this one is written out). Elements compare the way float.Equals does, so NaN equals
NaN. OwnedArray is not compared: who owns the array is not part of the block's value.
Applies to — net10.0, netstandard2.0.
See also — NpyBlock, NpyBlock.GetHashCode.