diff --git a/src/lib/validate-input.js b/src/lib/validate-input.js index f437aa4..f9e95bf 100644 --- a/src/lib/validate-input.js +++ b/src/lib/validate-input.js @@ -454,7 +454,7 @@ export function validateTriangularParams(input, {diagonal = 0} = {}) { if (i !== j) { throw new Error('The input should be a 2-D tensor of [N, N] shape.'); } - if (!Number.isInteger(diagonal) || diagonal >= i || diagonal <= -i) { - throw new Error(`The diagonal should be an integer in the interval [${1 - i}, ${i - 1}].`); + if (!Number.isInteger(diagonal)) { + throw new Error(`The diagonal should be an integer.`); } } diff --git a/test/triangular_test.js b/test/triangular_test.js index 4c29eb6..5763104 100644 --- a/test/triangular_test.js +++ b/test/triangular_test.js @@ -57,6 +57,30 @@ describe('test triangular', function() { ); }); + it('triangular fully zero diagonal=4', function() { + testTriangular( + { + shape: [3, 3], + data: [ + 7, 1, 2, + 9, 4, 8, + 2, 6, 3, + ], + }, + { + shape: [3, 3], + data: [ + 0, 0, 0, + 0, 0, 0, + 0, 0, 0, + ], + }, + { + diagonal: 4, + }, + ); + }); + it('triangular diagonal=-1', function() { testTriangular( { @@ -81,6 +105,30 @@ describe('test triangular', function() { ); }); + it('triangular fully copied diagonal=-4', function() { + testTriangular( + { + shape: [3, 3], + data: [ + 7, 1, 2, + 9, 4, 8, + 2, 6, 3, + ], + }, + { + shape: [3, 3], + data: [ + 7, 1, 2, + 9, 4, 8, + 2, 6, 3, + ], + }, + { + diagonal: -4, + }, + ); + }); + it('triangular upper=false', function() { testTriangular( { @@ -130,6 +178,31 @@ describe('test triangular', function() { ); }); + it('triangular fully copied upper=false diagonal=4 ', function() { + testTriangular( + { + shape: [3, 3], + data: [ + 7, 1, 2, + 9, 4, 8, + 2, 6, 3, + ], + }, + { + shape: [3, 3], + data: [ + 7, 1, 2, + 9, 4, 8, + 2, 6, 3, + ], + }, + { + upper: false, + diagonal: 4, + }, + ); + }); + it('triangular upper=false diagonal=-1', function() { testTriangular( { @@ -154,4 +227,29 @@ describe('test triangular', function() { }, ); }); + + it('triangular fully zero upper=false diagonal=-4', function() { + testTriangular( + { + shape: [3, 3], + data: [ + 7, 1, 2, + 9, 4, 8, + 2, 6, 3, + ], + }, + { + shape: [3, 3], + data: [ + 0, 0, 0, + 0, 0, 0, + 0, 0, 0, + ], + }, + { + upper: false, + diagonal: -4, + }, + ); + }); });