From 82c7fda449701ac369fbd7daf27912d8ce13830c Mon Sep 17 00:00:00 2001 From: BruceDai Date: Fri, 10 Nov 2023 15:51:38 +0800 Subject: [PATCH 1/3] Implement identity --- src/unary.js | 1 + test/unary_test.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/unary.js b/src/unary.js index 1d45243..52b6a2d 100644 --- a/src/unary.js +++ b/src/unary.js @@ -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 identity = (input) => unary(input, (x) => x); diff --git a/test/unary_test.js b/test/unary_test.js index be8899a..9ec5fc6 100644 --- a/test/unary_test.js +++ b/test/unary_test.js @@ -736,4 +736,63 @@ describe('test unary', function() { ], [3, 2, 2, 1]); }); + + it('identity', function() { + testUnary( + 'identity', + [1.4124068, 1.9740626, -0.06506752, 0.73539704], + [1.4124068, 1.9740626, -0.06506752, 0.73539704], + [4]); + testUnary( + 'identity', + [ + 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( + 'identity', + [ + 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( + 'identity', + [ + 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]); + }); }); From fbb53ffedb42e9df316a31ae1a8ed30e582292db Mon Sep 17 00:00:00 2001 From: BruceDai Date: Mon, 13 Nov 2023 14:39:08 +0800 Subject: [PATCH 2/3] Add 0D scalar test for identity op --- test/unary_test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unary_test.js b/test/unary_test.js index 9ec5fc6..a34f110 100644 --- a/test/unary_test.js +++ b/test/unary_test.js @@ -738,6 +738,8 @@ describe('test unary', function() { }); it('identity', function() { + // 0D scalar + testUnary('identity', [1.4124068], [1.4124068], []); testUnary( 'identity', [1.4124068, 1.9740626, -0.06506752, 0.73539704], From b74e48ca16fb2d6a0e1aafbae1e7aa31ee658c6d Mon Sep 17 00:00:00 2001 From: BruceDai Date: Tue, 14 Nov 2023 16:59:14 +0800 Subject: [PATCH 3/3] Rename identity to copy --- src/unary.js | 2 +- test/unary_test.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/unary.js b/src/unary.js index 52b6a2d..8bbb5e1 100644 --- a/src/unary.js +++ b/src/unary.js @@ -27,4 +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 identity = (input) => unary(input, (x) => x); +export const copy = (input) => unary(input, (x) => x); diff --git a/test/unary_test.js b/test/unary_test.js index a34f110..3e7a86d 100644 --- a/test/unary_test.js +++ b/test/unary_test.js @@ -737,16 +737,16 @@ describe('test unary', function() { [3, 2, 2, 1]); }); - it('identity', function() { + it('copy', function() { // 0D scalar - testUnary('identity', [1.4124068], [1.4124068], []); + testUnary('copy', [1.4124068], [1.4124068], []); testUnary( - 'identity', + 'copy', [1.4124068, 1.9740626, -0.06506752, 0.73539704], [1.4124068, 1.9740626, -0.06506752, 0.73539704], [4]); testUnary( - 'identity', + 'copy', [ 1.4124068, 1.9740626, -0.06506752, 0.73539704, -0.56439203, 0.89806247, 0.12939146, -0.34816208, @@ -759,7 +759,7 @@ describe('test unary', function() { ], [3, 4]); testUnary( - 'identity', + 'copy', [ 1.4124068, 1.9740626, -0.06506752, 0.73539704, @@ -778,7 +778,7 @@ describe('test unary', function() { ], [3, 2, 2]); testUnary( - 'identity', + 'copy', [ 1.4124068, 1.9740626, -0.06506752, 0.73539704,