From ca639b5e56be13485db01001841c84fd4247cf08 Mon Sep 17 00:00:00 2001 From: mei1127 Date: Tue, 19 Dec 2023 17:00:37 +0800 Subject: [PATCH] revised cast.js and cast_test.js --- src/cast.js | 10 +++++----- test/cast_test.js | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cast.js b/src/cast.js index d29a048..020f571 100644 --- a/src/cast.js +++ b/src/cast.js @@ -12,19 +12,19 @@ export function cast(input, type) { let outputArray; switch (type) { case 'int8': - outputArray = new Int8Array(Array.from(input.data, (num) => (Math.round(num)))); + outputArray = new Int8Array(input.data); break; case 'uint8': - outputArray = new Uint8Array(Array.from(input.data, (num) => (Math.round(num)))); + outputArray = new Uint8Array(input.data); break; case 'int32': - outputArray = new Int32Array(Array.from(input.data, (num) => (Math.round(num)))); + outputArray = new Int32Array(input.data); break; case 'uint32': - outputArray = new Uint32Array(Array.from(input.data, (num) => (Math.round(num)))); + outputArray = new Uint32Array(input.data); break; case 'int64': - outputArray = new BigInt64Array(Array.from(input.data, (num) => BigInt(Math.round(num)))); + outputArray = new BigInt64Array(Array.from(input.data, (num) => BigInt(Math.trunc(num)))); break; case 'float32': outputArray = new Float32Array(input.data); diff --git a/test/cast_test.js b/test/cast_test.js index efa8b93..0165a26 100644 --- a/test/cast_test.js +++ b/test/cast_test.js @@ -36,7 +36,7 @@ describe('test cast', function() { const expected = { shape: [5], data: [ - 0, 0, 4, 14, -14, + 0, 0, 3, 14, -14, ], }; testCast(input, 'int8', expected); @@ -52,7 +52,7 @@ describe('test cast', function() { const expected = { shape: [5], data: [ - 0, 1, 4, 14, 15, + 0, 0, 3, 14, 15, ], }; testCast(input, 'uint8', expected); @@ -62,7 +62,7 @@ describe('test cast', function() { const input = { shape: [5], data: [ - -0.25, 0.25, 3.21, 1234, -1234, + -0.25, 0.75, 3.21, 1234, -1234, ], }; const expected = { @@ -84,7 +84,7 @@ describe('test cast', function() { const expected = { shape: [5], data: [ - 1, 0, 3, 14, 15, + 0, 0, 3, 14, 15, ], }; testCast(input, 'uint32', expected); @@ -94,7 +94,7 @@ describe('test cast', function() { const input = { shape: [5], data: [ - -0.25, 0.25, 3.21, 1234, -1234, + -0.25, 0.75, 3.21, 1234, -1234, ], }; const expected = {