def testTensorArrayReadWrongIndexOrDataTypeFails(self): with self.test_session(use_gpu=True): ta = tensor_array_ops.TensorArray( dtype=dtypes.float32, tensor_array_name="foo", size=3) w0 = ta.write(0, [[4.0, 5.0]]) # Test reading wrong datatype r0_bad = gen_data_flow_ops._tensor_array_read_v3( handle=w0.handle, index=0, dtype=dtypes.float64, flow_in=w0.flow) with self.assertRaisesOpError( "TensorArray dtype is float but Op requested dtype double."): r0_bad.eval() # Test reading from a different index than the one we wrote to r1 = w0.read(1) with self.assertRaisesOpError( "Could not read from TensorArray index 1 because " "it has not yet been written to."): r1.eval() # Test reading from a negative index with self.assertRaisesOpError( r"Tried to read from index -1 but array size is: 3"): ta.read(-1).eval() # Test reading from too large an index with self.assertRaisesOpError( "Tried to read from index 3 but array size is: 3"): ta.read(3).eval()
def testTensorArrayReadWrongIndexOrDataTypeFails(self): with self.test_session(use_gpu=True): ta = tensor_array_ops.TensorArray( dtype=dtypes.float32, tensor_array_name="foo", size=3) w0 = ta.write(0, [[4.0, 5.0]]) # Test reading wrong datatype r0_bad = gen_data_flow_ops._tensor_array_read_v3( handle=w0.handle, index=0, dtype=dtypes.float64, flow_in=w0.flow) with self.assertRaisesOpError( "TensorArray dtype is float but Op requested dtype double."): r0_bad.eval() # Test reading from a different index than the one we wrote to r1 = w0.read(1) with self.assertRaisesOpError( "Could not read from TensorArray index 1 because " "it has not yet been written to."): r1.eval() # Test reading from a negative index with self.assertRaisesOpError( r"Tried to read from index -1 but array size is: 3"): ta.read(-1).eval() # Test reading from too large an index with self.assertRaisesOpError( "Tried to read from index 3 but array size is: 3"): ta.read(3).eval()
def read(self, index, name=None): """See TensorArray.""" value = gen_data_flow_ops._tensor_array_read_v3(handle=self._handle, index=index, flow_in=self._flow, dtype=self._dtype, name=name) if self._element_shape: value.set_shape(self._element_shape[0].dims) return value
def read(self, index, name=None): """See TensorArray.""" value = gen_data_flow_ops._tensor_array_read_v3( handle=self._handle, index=index, flow_in=self._flow, dtype=self._dtype, name=name) if self._element_shape: value.set_shape(self._element_shape[0].dims) return value
def testTensorArrayReadWrongIndexOrDataTypeFails(self): with self.test_session(), self.test_scope(): ta = tensor_array_ops.TensorArray( dtype=dtypes.float32, tensor_array_name="foo", size=3) w0 = ta.write(0, [[4.0, 5.0]]) # Test reading wrong datatype r0_bad = gen_data_flow_ops._tensor_array_read_v3( handle=w0.handle, index=0, dtype=dtypes.float64, flow_in=w0.flow) with self.assertRaisesOpError( "TensorArray dtype is float but op has dtype double."): r0_bad.eval() # Test reading from a different index than the one we wrote to w0.read(1)
def read(self, index, name=None): """Read the value at location `index` in the TensorArray. Args: index: 0-D. int32 tensor with the index to read from. name: A name for the operation (optional). Returns: The tensor at index `index`. """ with ops.colocate_with(self._handle): value = gen_data_flow_ops._tensor_array_read_v3( handle=self._handle, index=index, flow_in=self._flow, dtype=self._dtype, name=name ) if self._element_shape: value.set_shape(self._element_shape[0].dims) return value
def read(self, index, name=None): """Read the value at location `index` in the TensorArray. Args: index: 0-D. int32 tensor with the index to read from. name: A name for the operation (optional). Returns: The tensor at index `index`. """ value = gen_data_flow_ops._tensor_array_read_v3(handle=self._handle, index=index, flow_in=self._flow, dtype=self._dtype, name=name) if self._element_shape: value.set_shape(self._element_shape[0].dims) return value
def testTensorArrayReadWrongIndexOrDataTypeFails(self): # Find two different floating point types, create an array of # the first type, but try to read the other type. if len(self.float_types) > 1: dtype1, dtype2 = list(self.float_types)[:2] with self.test_session(), self.test_scope(): ta = tensor_array_ops.TensorArray( dtype=dtype1, tensor_array_name="foo", size=3) w0 = ta.write(0, [[4.0, 5.0]]) # Test reading wrong datatype. r0_bad = gen_data_flow_ops._tensor_array_read_v3( handle=w0.handle, index=0, dtype=dtype2, flow_in=w0.flow) with self.assertRaisesOpError("TensorArray dtype is "): r0_bad.eval() # Test reading from a different index than the one we wrote to w0.read(1)
def testTensorArrayReadWrongIndexOrDataTypeFails(self): # Find two different floating point types, create an array of # the first type, but try to read the other type. if len(self.float_types) > 1: dtype1 = self.float_types[0] dtype2 = self.float_types[1] with self.test_session(), self.test_scope(): ta = tensor_array_ops.TensorArray( dtype=dtype1, tensor_array_name="foo", size=3) w0 = ta.write(0, [[4.0, 5.0]]) # Test reading wrong datatype. r0_bad = gen_data_flow_ops._tensor_array_read_v3( handle=w0.handle, index=0, dtype=dtype2, flow_in=w0.flow) with self.assertRaisesOpError("TensorArray dtype is "): r0_bad.eval() # Test reading from a different index than the one we wrote to w0.read(1)