Skip to content

Commit

Permalink
Merge pull request #54 from BruceDai/add_sqrt
Browse files Browse the repository at this point in the history
Implement sqrt
  • Loading branch information
huningxin authored Nov 17, 2023
2 parents 00e73d1 + a55674f commit 5cba313
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/unary.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ export const sin = (input) => unary(input, Math.sin);
export const tan = (input) => unary(input, Math.tan);
export const copy = (input) => unary(input, (x) => x);
export const reciprocal = (input) => unary(input, (x) => 1 / x);
export const sqrt = (input) => unary(input, Math.sqrt);
56 changes: 56 additions & 0 deletions test/unary_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,4 +849,60 @@ describe('test unary', function() {
],
[3, 2, 2, 1]);
});

it('sqrt', function() {
// 0D scalar
testUnary('sqrt', [4], [2], []);
testUnary(
'sqrt',
[0.01, 1.44, 1.69, 2.25],
[0.1, 1.2, 1.3, 1.5],
[4]);
testUnary(
'sqrt',
[0, 1, 4, 9],
[0, 1, 2, 3],
[4]);
testUnary(
'sqrt',
[
0, 1, 4,
9, 16, 25,
],
[
0, 1, 2,
3, 4, 5,
],
[2, 3]);
testUnary(
'sqrt',
[
0, 1, 4,
9, 16, 25,
36, 49, 64,
81, 100, 121,
],
[
0, 1, 2,
3, 4, 5,
6, 7, 8,
9, 10, 11,
],
[2, 2, 3]);
testUnary(
'sqrt',
[
0, 1, 4,
9, 16, 25,
36, 49, 64,
81, 100, 121,
],
[
0, 1, 2,
3, 4, 5,
6, 7, 8,
9, 10, 11,
],
[2, 2, 3, 1]);
});
});

0 comments on commit 5cba313

Please sign in to comment.