Skip to content

Commit

Permalink
Fix slicing out of order
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsoulanille committed Apr 20, 2023
1 parent b1fe5eb commit b86ee6e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tfjs-core/src/io/weights_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ function search<T>(sortedArray: T[], compare: (t: T) => number): number {
let max = sortedArray.length;

while (min <= max) {
const middle = Math.floor((max - min) / 2);
const middle = Math.floor((max - min) / 2) + min;
const side = compare(sortedArray[middle]);

if (side === 0) {
Expand Down
6 changes: 6 additions & 0 deletions tfjs-core/src/io/weights_loader_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,12 @@ describe('CompositeArrayBuffer', () => {
expectArraysEqual(new Uint8Array(composite.slice(7, 1000)),
[7,8,9,10,11,12,13,14,15,16]);
});

it(`${buffersType}: slices multiple ranges out of order`, () => {
expectArraysEqual(new Uint8Array(composite.slice(13, 15)), [13, 14]);
expectArraysEqual(new Uint8Array(composite.slice(0, 2)), [0, 1]);
expectArraysEqual(new Uint8Array(composite.slice(9, 13)), [9, 10, 11, 12]);
});
}

it('can be passed an empty arraybuffer', () => {
Expand Down

0 comments on commit b86ee6e

Please sign in to comment.