Python源码示例:syntaxnet.util.check.IsNone()
示例1
def __init__(self, tensor=None, array=None, stride=None, dim=None):
"""Creates ops for converting the input to either format.
If 'tensor' is used, then a conversion from [stride * steps, dim] to
[steps + 1, stride, dim] is performed for dynamic_tensor reads.
If 'array' is used, then a conversion from [steps + 1, stride, dim] to
[stride * steps, dim] is performed for bulk_tensor reads.
Args:
tensor: Bulk tensor input.
array: TensorArray dynamic input.
stride: stride of bulk tensor. Not used for dynamic.
dim: dim of bulk tensor. Not used for dynamic.
"""
if tensor is not None:
check.IsNone(array, 'Cannot initialize from tensor and array')
check.NotNone(stride, 'Stride is required for bulk tensor')
check.NotNone(dim, 'Dim is required for bulk tensor')
self._bulk_tensor = tensor
with tf.name_scope('convert_to_dyn'):
tensor = tf.reshape(tensor, [stride, -1, dim])
tensor = tf.transpose(tensor, perm=[1, 0, 2])
pad = tf.zeros([1, stride, dim], dtype=tensor.dtype)
self._array_tensor = tf.concat([pad, tensor], 0)
if array is not None:
check.IsNone(tensor, 'Cannot initialize from both tensor and array')
with tf.name_scope('convert_to_bulk'):
self._bulk_tensor = convert_network_state_tensorarray(array)
with tf.name_scope('convert_to_dyn'):
self._array_tensor = array.stack()
示例2
def testCheckIsNone(self):
check.IsNone(None, 'foo')
with self.assertRaisesRegexp(ValueError, 'bar'):
check.IsNone(1, 'bar')
with self.assertRaisesRegexp(RuntimeError, 'baz'):
check.IsNone([], 'baz', RuntimeError)
示例3
def __init__(self, tensor=None, array=None, stride=None, dim=None):
"""Creates ops for converting the input to either format.
If 'tensor' is used, then a conversion from [stride * steps, dim] to
[steps + 1, stride, dim] is performed for dynamic_tensor reads.
If 'array' is used, then a conversion from [steps + 1, stride, dim] to
[stride * steps, dim] is performed for bulk_tensor reads.
Args:
tensor: Bulk tensor input.
array: TensorArray dynamic input.
stride: stride of bulk tensor. Not used for dynamic.
dim: dim of bulk tensor. Not used for dynamic.
"""
if tensor is not None:
check.IsNone(array, 'Cannot initialize from tensor and array')
check.NotNone(stride, 'Stride is required for bulk tensor')
check.NotNone(dim, 'Dim is required for bulk tensor')
self._bulk_tensor = tensor
with tf.name_scope('convert_to_dyn'):
tensor = tf.reshape(tensor, [stride, -1, dim])
tensor = tf.transpose(tensor, perm=[1, 0, 2])
pad = tf.zeros([1, stride, dim], dtype=tensor.dtype)
self._array_tensor = tf.concat([pad, tensor], 0)
if array is not None:
check.IsNone(tensor, 'Cannot initialize from both tensor and array')
with tf.name_scope('convert_to_bulk'):
self._bulk_tensor = convert_network_state_tensorarray(array)
with tf.name_scope('convert_to_dyn'):
self._array_tensor = array.stack()
示例4
def testCheckIsNone(self):
check.IsNone(None, 'foo')
with self.assertRaisesRegexp(ValueError, 'bar'):
check.IsNone(1, 'bar')
with self.assertRaisesRegexp(RuntimeError, 'baz'):
check.IsNone([], 'baz', RuntimeError)
示例5
def __init__(self, tensor=None, array=None, stride=None, dim=None):
"""Creates ops for converting the input to either format.
If 'tensor' is used, then a conversion from [stride * steps, dim] to
[steps + 1, stride, dim] is performed for dynamic_tensor reads.
If 'array' is used, then a conversion from [steps + 1, stride, dim] to
[stride * steps, dim] is performed for bulk_tensor reads.
Args:
tensor: Bulk tensor input.
array: TensorArray dynamic input.
stride: stride of bulk tensor. Not used for dynamic.
dim: dim of bulk tensor. Not used for dynamic.
"""
if tensor is not None:
check.IsNone(array, 'Cannot initialize from tensor and array')
check.NotNone(stride, 'Stride is required for bulk tensor')
check.NotNone(dim, 'Dim is required for bulk tensor')
self._bulk_tensor = tensor
with tf.name_scope('convert_to_dyn'):
tensor = tf.reshape(tensor, [stride, -1, dim])
tensor = tf.transpose(tensor, perm=[1, 0, 2])
pad = tf.zeros([1, stride, dim], dtype=tensor.dtype)
self._array_tensor = tf.concat([pad, tensor], 0)
if array is not None:
check.IsNone(tensor, 'Cannot initialize from both tensor and array')
with tf.name_scope('convert_to_bulk'):
self._bulk_tensor = convert_network_state_tensorarray(array)
with tf.name_scope('convert_to_dyn'):
self._array_tensor = array.stack()
示例6
def testCheckIsNone(self):
check.IsNone(None, 'foo')
with self.assertRaisesRegexp(ValueError, 'bar'):
check.IsNone(1, 'bar')
with self.assertRaisesRegexp(RuntimeError, 'baz'):
check.IsNone([], 'baz', RuntimeError)
示例7
def __init__(self, tensor=None, array=None, stride=None, dim=None):
"""Creates ops for converting the input to either format.
If 'tensor' is used, then a conversion from [stride * steps, dim] to
[steps + 1, stride, dim] is performed for dynamic_tensor reads.
If 'array' is used, then a conversion from [steps + 1, stride, dim] to
[stride * steps, dim] is performed for bulk_tensor reads.
Args:
tensor: Bulk tensor input.
array: TensorArray dynamic input.
stride: stride of bulk tensor. Not used for dynamic.
dim: dim of bulk tensor. Not used for dynamic.
"""
if tensor is not None:
check.IsNone(array, 'Cannot initialize from tensor and array')
check.NotNone(stride, 'Stride is required for bulk tensor')
check.NotNone(dim, 'Dim is required for bulk tensor')
self._bulk_tensor = tensor
with tf.name_scope('convert_to_dyn'):
tensor = tf.reshape(tensor, [stride, -1, dim])
tensor = tf.transpose(tensor, perm=[1, 0, 2])
pad = tf.zeros([1, stride, dim], dtype=tensor.dtype)
self._array_tensor = tf.concat([pad, tensor], 0)
if array is not None:
check.IsNone(tensor, 'Cannot initialize from both tensor and array')
with tf.name_scope('convert_to_bulk'):
self._bulk_tensor = convert_network_state_tensorarray(array)
with tf.name_scope('convert_to_dyn'):
self._array_tensor = array.stack()
示例8
def testCheckIsNone(self):
check.IsNone(None, 'foo')
with self.assertRaisesRegexp(ValueError, 'bar'):
check.IsNone(1, 'bar')
with self.assertRaisesRegexp(RuntimeError, 'baz'):
check.IsNone([], 'baz', RuntimeError)
示例9
def __init__(self, tensor=None, array=None, stride=None, dim=None):
"""Creates ops for converting the input to either format.
If 'tensor' is used, then a conversion from [stride * steps, dim] to
[steps + 1, stride, dim] is performed for dynamic_tensor reads.
If 'array' is used, then a conversion from [steps + 1, stride, dim] to
[stride * steps, dim] is performed for bulk_tensor reads.
Args:
tensor: Bulk tensor input.
array: TensorArray dynamic input.
stride: stride of bulk tensor. Not used for dynamic.
dim: dim of bulk tensor. Not used for dynamic.
"""
if tensor is not None:
check.IsNone(array, 'Cannot initialize from tensor and array')
check.NotNone(stride, 'Stride is required for bulk tensor')
check.NotNone(dim, 'Dim is required for bulk tensor')
self._bulk_tensor = tensor
with tf.name_scope('convert_to_dyn'):
tensor = tf.reshape(tensor, [stride, -1, dim])
tensor = tf.transpose(tensor, perm=[1, 0, 2])
pad = tf.zeros([1, stride, dim], dtype=tensor.dtype)
self._array_tensor = tf.concat([pad, tensor], 0)
if array is not None:
check.IsNone(tensor, 'Cannot initialize from both tensor and array')
with tf.name_scope('convert_to_bulk'):
self._bulk_tensor = convert_network_state_tensorarray(array)
with tf.name_scope('convert_to_dyn'):
self._array_tensor = array.stack()
示例10
def testCheckIsNone(self):
check.IsNone(None, 'foo')
with self.assertRaisesRegexp(ValueError, 'bar'):
check.IsNone(1, 'bar')
with self.assertRaisesRegexp(RuntimeError, 'baz'):
check.IsNone([], 'baz', RuntimeError)
示例11
def __init__(self, tensor=None, array=None, stride=None, dim=None):
"""Creates ops for converting the input to either format.
If 'tensor' is used, then a conversion from [stride * steps, dim] to
[steps + 1, stride, dim] is performed for dynamic_tensor reads.
If 'array' is used, then a conversion from [steps + 1, stride, dim] to
[stride * steps, dim] is performed for bulk_tensor reads.
Args:
tensor: Bulk tensor input.
array: TensorArray dynamic input.
stride: stride of bulk tensor. Not used for dynamic.
dim: dim of bulk tensor. Not used for dynamic.
"""
if tensor is not None:
check.IsNone(array, 'Cannot initialize from tensor and array')
check.NotNone(stride, 'Stride is required for bulk tensor')
check.NotNone(dim, 'Dim is required for bulk tensor')
self._bulk_tensor = tensor
with tf.name_scope('convert_to_dyn'):
tensor = tf.reshape(tensor, [stride, -1, dim])
tensor = tf.transpose(tensor, perm=[1, 0, 2])
pad = tf.zeros([1, stride, dim], dtype=tensor.dtype)
self._array_tensor = tf.concat([pad, tensor], 0)
if array is not None:
check.IsNone(tensor, 'Cannot initialize from both tensor and array')
with tf.name_scope('convert_to_bulk'):
self._bulk_tensor = convert_network_state_tensorarray(array)
with tf.name_scope('convert_to_dyn'):
self._array_tensor = array.stack()
示例12
def testCheckIsNone(self):
check.IsNone(None, 'foo')
with self.assertRaisesRegexp(ValueError, 'bar'):
check.IsNone(1, 'bar')
with self.assertRaisesRegexp(RuntimeError, 'baz'):
check.IsNone([], 'baz', RuntimeError)
示例13
def __init__(self, tensor=None, array=None, stride=None, dim=None):
"""Creates ops for converting the input to either format.
If 'tensor' is used, then a conversion from [stride * steps, dim] to
[steps + 1, stride, dim] is performed for dynamic_tensor reads.
If 'array' is used, then a conversion from [steps + 1, stride, dim] to
[stride * steps, dim] is performed for bulk_tensor reads.
Args:
tensor: Bulk tensor input.
array: TensorArray dynamic input.
stride: stride of bulk tensor. Not used for dynamic.
dim: dim of bulk tensor. Not used for dynamic.
"""
if tensor is not None:
check.IsNone(array, 'Cannot initialize from tensor and array')
check.NotNone(stride, 'Stride is required for bulk tensor')
check.NotNone(dim, 'Dim is required for bulk tensor')
self._bulk_tensor = tensor
with tf.name_scope('convert_to_dyn'):
tensor = tf.reshape(tensor, [stride, -1, dim])
tensor = tf.transpose(tensor, perm=[1, 0, 2])
pad = tf.zeros([1, stride, dim], dtype=tensor.dtype)
self._array_tensor = tf.concat([pad, tensor], 0)
if array is not None:
check.IsNone(tensor, 'Cannot initialize from both tensor and array')
with tf.name_scope('convert_to_bulk'):
self._bulk_tensor = convert_network_state_tensorarray(array)
with tf.name_scope('convert_to_dyn'):
self._array_tensor = array.stack()
示例14
def testCheckIsNone(self):
check.IsNone(None, 'foo')
with self.assertRaisesRegexp(ValueError, 'bar'):
check.IsNone(1, 'bar')
with self.assertRaisesRegexp(RuntimeError, 'baz'):
check.IsNone([], 'baz', RuntimeError)
示例15
def __init__(self, tensor=None, array=None, stride=None, dim=None):
"""Creates ops for converting the input to either format.
If 'tensor' is used, then a conversion from [stride * steps, dim] to
[steps + 1, stride, dim] is performed for dynamic_tensor reads.
If 'array' is used, then a conversion from [steps + 1, stride, dim] to
[stride * steps, dim] is performed for bulk_tensor reads.
Args:
tensor: Bulk tensor input.
array: TensorArray dynamic input.
stride: stride of bulk tensor. Not used for dynamic.
dim: dim of bulk tensor. Not used for dynamic.
"""
if tensor is not None:
check.IsNone(array, 'Cannot initialize from tensor and array')
check.NotNone(stride, 'Stride is required for bulk tensor')
check.NotNone(dim, 'Dim is required for bulk tensor')
self._bulk_tensor = tensor
if dim >= 0:
# These operations will fail if |dim| is negative.
with tf.name_scope('convert_to_dyn'):
tensor = tf.reshape(tensor, [stride, -1, dim])
tensor = tf.transpose(tensor, perm=[1, 0, 2])
pad = tf.zeros([1, stride, dim], dtype=tensor.dtype)
self._array_tensor = tf.concat([pad, tensor], 0)
if array is not None:
check.IsNone(tensor, 'Cannot initialize from both tensor and array')
with tf.name_scope('convert_to_bulk'):
self._bulk_tensor = convert_network_state_tensorarray(array)
with tf.name_scope('convert_to_dyn'):
self._array_tensor = array.stack()
示例16
def testCheckIsNone(self):
check.IsNone(None, 'foo')
with self.assertRaisesRegexp(ValueError, 'bar'):
check.IsNone(1, 'bar')
with self.assertRaisesRegexp(RuntimeError, 'baz'):
check.IsNone([], 'baz', RuntimeError)
示例17
def __init__(self, tensor=None, array=None, stride=None, dim=None):
"""Creates ops for converting the input to either format.
If 'tensor' is used, then a conversion from [stride * steps, dim] to
[steps + 1, stride, dim] is performed for dynamic_tensor reads.
If 'array' is used, then a conversion from [steps + 1, stride, dim] to
[stride * steps, dim] is performed for bulk_tensor reads.
Args:
tensor: Bulk tensor input.
array: TensorArray dynamic input.
stride: stride of bulk tensor. Not used for dynamic.
dim: dim of bulk tensor. Not used for dynamic.
"""
if tensor is not None:
check.IsNone(array, 'Cannot initialize from tensor and array')
check.NotNone(stride, 'Stride is required for bulk tensor')
check.NotNone(dim, 'Dim is required for bulk tensor')
self._bulk_tensor = tensor
if dim >= 0:
# These operations will fail if |dim| is negative.
with tf.name_scope('convert_to_dyn'):
tensor = tf.reshape(tensor, [stride, -1, dim])
tensor = tf.transpose(tensor, perm=[1, 0, 2])
pad = tf.zeros([1, stride, dim], dtype=tensor.dtype)
self._array_tensor = tf.concat([pad, tensor], 0)
if array is not None:
check.IsNone(tensor, 'Cannot initialize from both tensor and array')
with tf.name_scope('convert_to_bulk'):
self._bulk_tensor = convert_network_state_tensorarray(array)
with tf.name_scope('convert_to_dyn'):
self._array_tensor = array.stack()
示例18
def testCheckIsNone(self):
check.IsNone(None, 'foo')
with self.assertRaisesRegexp(ValueError, 'bar'):
check.IsNone(1, 'bar')
with self.assertRaisesRegexp(RuntimeError, 'baz'):
check.IsNone([], 'baz', RuntimeError)