Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions tfjs-core/src/tensor_util_env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,18 @@ export function convertToTensor<T extends Tensor>(
export function convertToTensorArray<T extends Tensor>(
arg: Array<T|TensorLike>, argName: string, functionName: string,
parseAsDtype: DataType|'numeric'|'string_or_numeric' = 'numeric'): T[] {
let tensors = arg as T[];

if (!Array.isArray(arg)) {
throw new Error(
`Argument ${argName} passed to ${functionName} must be a ` +
'`Tensor[]` or `TensorLike[]`');
if ((arg as T) instanceof getGlobalTensorClass()) {
tensors = [arg];
} else {
throw new Error(
`Argument ${argName} passed to ${functionName} must be a ` +
'`Tensor[]` or `TensorLike[]`');
}
}
const tensors = arg as T[];

return tensors.map(
(t, i) =>
convertToTensor(t, `${argName}[${i}]`, functionName, parseAsDtype));
Expand Down