-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add test coverage for VBuffer #1804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,21 +110,23 @@ public Float this[int index] | |
} | ||
} | ||
|
||
public void CopyTo(Float[] dst, int index, int count) | ||
public void CopyTo(Span<Float> dst, int index, int count) | ||
{ | ||
Contracts.Assert(0 <= count && count <= _size); | ||
Contracts.Assert(dst != null); | ||
Contracts.Assert(0 <= index && index <= dst.Length - count); | ||
Array.Copy(Items, _base, dst, index, count); | ||
for (int i = 0; i < count; i++) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I think this code is going away with #1657) You don't need to copy element by element. Instead you can say |
||
dst[index + i] = Items[_base + i]; | ||
} | ||
|
||
public void CopyTo(int start, Float[] dst, int index, int count) | ||
public void CopyTo(int start, Span<Float> dst, int index, int count) | ||
{ | ||
Contracts.Assert(0 <= count); | ||
Contracts.Assert(0 <= start && start <= _size - count); | ||
Contracts.Assert(dst != null); | ||
Contracts.Assert(0 <= index && index <= dst.Length - count); | ||
Array.Copy(Items, start + _base, dst, index, count); | ||
for (int i = 0; i < count; i++) | ||
dst[index + i] = Items[start + _base + i]; | ||
} | ||
|
||
public void CopyFrom(ReadOnlySpan<Float> src) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,19 @@ public static int ArgMax<T>(this T[] arr) where T : IComparable<T> | |
return argMax; | ||
} | ||
|
||
public static int ArgMax<T>(this ReadOnlySpan<T> span) where T : IComparable<T> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to remove the method above this, since arrays are implicitly convertible to ReadOnlySpan. #Resolved |
||
{ | ||
if (span.Length == 0) | ||
return -1; | ||
int argMax = 0; | ||
for (int i = 1; i < span.Length; i++) | ||
{ | ||
if (span[i].CompareTo(span[argMax]) > 0) | ||
argMax = i; | ||
} | ||
return argMax; | ||
} | ||
|
||
public static int ArgMin<T>(this T[] arr, int prefix) where T : IComparable<T> | ||
{ | ||
int length = arr.Length < prefix ? arr.Length : prefix; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curios, what it stands for?
random general values?