1# Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15"""This module defines tensor utilities not found in TensorFlow. 16 17The reason these utilities are not defined in TensorFlow is because they may 18not be not fully robust, although they work in the vast majority of cases. So 19we define them here in order for their behavior to be consistently verified. 20""" 21 22from __future__ import absolute_import 23from __future__ import division 24from __future__ import print_function 25 26from tensorflow.python.framework import dtypes 27from tensorflow.python.framework import tensor_util 28from tensorflow.python.ops import tensor_array_ops 29 30 31def is_tensor_array(t): 32 return isinstance(t, tensor_array_ops.TensorArray) 33 34 35def is_tensor_list(t): 36 # TODO(mdan): This is just a heuristic. 37 # With TF lacking support for templated types, this is unfortunately the 38 # closest we can get right now. A dedicated op ought to be possible to 39 # construct. 40 return (tensor_util.is_tensor(t) and t.dtype == dtypes.variant and 41 not t.shape.ndims) 42