diff --git a/src/unary.js b/src/unary.js index 1d45243..8bbb5e1 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 copy = (input) => unary(input, (x) => x); diff --git a/test/unary_test.js b/test/unary_test.js index be8899a..3e7a86d 100644 --- a/test/unary_test.js +++ b/test/unary_test.js @@ -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]); + }); });