Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Commit

Permalink
One Hot: Fixes CPU result dtype (#1110)
Browse files Browse the repository at this point in the history
  • Loading branch information
manrajgrover authored and bileschi committed Jun 17, 2018
1 parent b5b5430 commit 833475d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/kernels/backend_cpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,7 @@ export class MathBackendCPU implements KernelBackend {
for (let event = 0; event < indices.size; ++event) {
res[event * depth + indices.get(event)] = onValue;
}
return ops.tensor2d(res, [indices.size, depth]);
return ops.tensor2d(res, [indices.size, depth], 'int32');
}

private broadcastedBinaryOp(
Expand Down
8 changes: 8 additions & 0 deletions src/ops/array_ops_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,14 @@ describeWithFlags('oneHot', ALL_ENVS, () => {
const indices = tf.tensor1d([0, 1], 'float32');
expect(() => tf.oneHot(indices, 2)).toThrowError();
});

it('check output dtype', () => {
const expectedType = 'int32';
const indices = tf.tensor1d([0, 1], 'int32');
const res = tf.oneHot(indices, 2);

expect(res.dtype).toEqual(expectedType);
});
});

describeWithFlags('linspace', ALL_ENVS, () => {
Expand Down

0 comments on commit 833475d

Please sign in to comment.