Skip to content

Commit

Permalink
revised cast.js and cast_test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mei1127 committed Dec 19, 2023
1 parent a4d9972 commit ca639b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/cast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions test/cast_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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 = {
Expand All @@ -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);
Expand All @@ -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 = {
Expand Down

0 comments on commit ca639b5

Please sign in to comment.