Skip to content

Commit

Permalink
Hidden LLamaTokenData* and exposed span instead
Browse files Browse the repository at this point in the history
  • Loading branch information
martindevans committed May 12, 2024
1 parent bf33a19 commit 60ddd44
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions LLama/Native/LLamaTokenDataArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,28 @@ public struct LLamaTokenDataArrayNative
/// A pointer to an array of LlamaTokenData
/// </summary>
/// <remarks>Memory must be pinned in place for all the time this LLamaTokenDataArrayNative is in use</remarks>
public unsafe LLamaTokenData* data;
private unsafe LLamaTokenData* _data;

/// <summary>
/// Number of LLamaTokenData in the array
/// </summary>
public ulong size;


/// <summary>
/// A pointer to an array of LlamaTokenData
/// </summary>
/// <remarks>Memory must be pinned in place for all the time this LLamaTokenDataArrayNative is in use</remarks>
public Span<LLamaTokenData> data
{
get
{
unsafe
{
return new Span<LLamaTokenData>(_data, checked((int)size));
}
}
}

/// <summary>
/// Indicates if the items in the array are sorted
/// </summary>
Expand All @@ -393,7 +408,7 @@ public static MemoryHandle Create(LLamaTokenDataArray array, out LLamaTokenDataA
{
native = new LLamaTokenDataArrayNative
{
data = (LLamaTokenData*)handle.Pointer,
_data = (LLamaTokenData*)handle.Pointer,
size = (ulong)array.Data.Length,
sorted = array.Sorted
};
Expand Down

0 comments on commit 60ddd44

Please sign in to comment.