Skip to content

Commit 0e40eb1

Browse files
committed
fix: wrong pred array size
1 parent f49edd3 commit 0e40eb1

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/__tests__/test.ts renamed to src/__tests__/index.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ describe('linear sum problem', () => {
2727
const { columnAssignments, rowAssignments } = linearSumAssignment(diff, {
2828
maximaze: false,
2929
});
30-
expect(columnAssignments).toMatchCloseTo([1, 2, 0, 3, 4, -1]);
31-
expect(rowAssignments).toMatchCloseTo([2, 0, 1, 3, 4]);
30+
expect(columnAssignments).toMatchCloseTo([2, 0, 1, 3, 4]);
31+
expect(rowAssignments).toMatchCloseTo([1, 2, 0, 3, 4, -1]);
3232
});
3333
it('differents size: rows < columns', () => {
3434
const a = [3.1, 1.1, 1.9, 3.99, 5.2];
@@ -44,14 +44,14 @@ describe('linear sum problem', () => {
4444
});
4545
it('before failing case', () => {
4646
const diff = [
47-
[0.10000000000000009, 0.5, 0.6000000000000001, 1.1],
48-
[0.3999999999999999, 0, 0.10000000000000009, 0.6000000000000001],
49-
[0.8999999999999999, 0.5, 0.3999999999999999, 0.10000000000000009],
47+
[0.010000000000000009, 0.3999999999999999, 0.5, 1.0099999999999998],
48+
[0.49, 0.10000000000000009, 0, 0.5099999999999998],
49+
[0.99, 0.6000000000000001, 0.5, 0.009999999999999787],
5050
];
5151
const { columnAssignments, rowAssignments } = linearSumAssignment(diff, {
5252
maximaze: false,
5353
});
54-
expect(columnAssignments).toMatchCloseTo([0, 1, 2, -1]);
55-
expect(rowAssignments).toMatchCloseTo([0, 1, 2]);
54+
expect(columnAssignments).toMatchCloseTo([0, -1, 1, 2]);
55+
expect(rowAssignments).toMatchCloseTo([0, 2, 3]);
5656
});
5757
});

src/getShortestPath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function getShortestPath(options: GetShortestPathOptions) {
2424
let nbRows = matrix.rows;
2525
let nbColumns = matrix.columns;
2626

27-
let pred = new Float64Array(nbColumns);
27+
let pred = new Float64Array(nbRows);
2828
let scannedColumns = new Float64Array(nbColumns);
2929
let scannedRows = new Float64Array(nbRows);
3030

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ export default function linearSumAssignment(
1414
const { maximaze = true } = options;
1515

1616
let matrix = Matrix.checkMatrix(input);
17-
1817
let didFlip = false;
19-
if (matrix.columns < matrix.rows) {
18+
if (matrix.columns > matrix.rows) {
2019
didFlip = true;
2120
matrix = matrix.transpose();
2221
}

0 commit comments

Comments
 (0)