Skip to content

Commit

Permalink
Merge pull request #52 from BruceDai/add_identity
Browse files Browse the repository at this point in the history
Implement element-wise unary operation -- copy op
  • Loading branch information
huningxin committed Nov 16, 2023
2 parents d639b2a + b74e48c commit 3da156d
Show file tree
Hide file tree
Showing 2 changed files with 62 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 @@ -27,3 +27,4 @@ export const log = (input) => unary(input, Math.log);
export const neg = (input) => unary(input, (x) => -1 * x);
export const sin = (input) => unary(input, Math.sin);
export const tan = (input) => unary(input, Math.tan);
export const copy = (input) => unary(input, (x) => x);
61 changes: 61 additions & 0 deletions test/unary_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,4 +736,65 @@ describe('test unary', function() {
],
[3, 2, 2, 1]);
});

it('copy', function() {
// 0D scalar
testUnary('copy', [1.4124068], [1.4124068], []);
testUnary(
'copy',
[1.4124068, 1.9740626, -0.06506752, 0.73539704],
[1.4124068, 1.9740626, -0.06506752, 0.73539704],
[4]);
testUnary(
'copy',
[
1.4124068, 1.9740626, -0.06506752, 0.73539704,
-0.56439203, 0.89806247, 0.12939146, -0.34816208,
-1.0759926, 0.66291636, 0.21504708, -0.71527237,
],
[
1.4124068, 1.9740626, -0.06506752, 0.73539704,
-0.56439203, 0.89806247, 0.12939146, -0.34816208,
-1.0759926, 0.66291636, 0.21504708, -0.71527237,
],
[3, 4]);
testUnary(
'copy',
[
1.4124068, 1.9740626,
-0.06506752, 0.73539704,
-0.56439203, 0.89806247,
0.12939146, -0.34816208,
-1.0759926, 0.66291636,
0.21504708, -0.71527237,
],
[
1.4124068, 1.9740626,
-0.06506752, 0.73539704,
-0.56439203, 0.89806247,
0.12939146, -0.34816208,
-1.0759926, 0.66291636,
0.21504708, -0.71527237,
],
[3, 2, 2]);
testUnary(
'copy',
[
1.4124068, 1.9740626,
-0.06506752, 0.73539704,
-0.56439203, 0.89806247,
0.12939146, -0.34816208,
-1.0759926, 0.66291636,
0.21504708, -0.71527237,
],
[
1.4124068, 1.9740626,
-0.06506752, 0.73539704,
-0.56439203, 0.89806247,
0.12939146, -0.34816208,
-1.0759926, 0.66291636,
0.21504708, -0.71527237,
],
[3, 2, 2, 1]);
});
});

0 comments on commit 3da156d

Please sign in to comment.