| 279 | pass |
| 280 | |
| 281 | def get_initial_state(self, inputs=None, batch_size=None, dtype=None): |
| 282 | if inputs is not None: |
| 283 | # Validate the given batch_size and dtype against inputs if provided. |
| 284 | inputs = ops.convert_to_tensor(inputs, name="inputs") |
| 285 | if batch_size is not None: |
| 286 | if tensor_util.is_tensor(batch_size): |
| 287 | static_batch_size = tensor_util.constant_value( |
| 288 | batch_size, partial=True) |
| 289 | else: |
| 290 | static_batch_size = batch_size |
| 291 | if inputs.shape.dims[0].value != static_batch_size: |
| 292 | raise ValueError( |
| 293 | "batch size from input tensor is different from the " |
| 294 | "input param. Input tensor batch: {}, batch_size: {}".format( |
| 295 | inputs.shape.dims[0].value, batch_size)) |
| 296 | |
| 297 | if dtype is not None and inputs.dtype != dtype: |
| 298 | raise ValueError( |
| 299 | "dtype from input tensor is different from the " |
| 300 | "input param. Input tensor dtype: {}, dtype: {}".format( |
| 301 | inputs.dtype, dtype)) |
| 302 | |
| 303 | batch_size = inputs.shape.dims[0].value or array_ops.shape(inputs)[0] |
| 304 | dtype = inputs.dtype |
| 305 | if batch_size is None or dtype is None: |
| 306 | raise ValueError( |
| 307 | "batch_size and dtype cannot be None while constructing initial " |
| 308 | "state: batch_size={}, dtype={}".format(batch_size, dtype)) |
| 309 | return self.zero_state(batch_size, dtype) |
| 310 | |
| 311 | def zero_state(self, batch_size, dtype): |
| 312 | """Return zero-filled state tensor(s). |