def sum(x, axis=None): if isinstance(x, list): x = tf.pack(x) if axis is None: result = tf.reduce_sum(x) result_shape = [] else: if axis < 0: axis = x.ndim + axis result = tf.reduce_sum(x, axis) result_shape = get_raw_dimensions(x) result_shape = list(result_shape[:axis]) + list(result_shape[axis + 1:]) if get_raw_dimensions(result).ndims is None: result.set_shape(result_shape) return result
def sum(x, axis=None): if isinstance(x, list): x = tf.pack(x) if axis is None: result = tf.reduce_sum(x) result_shape = [] else: if axis < 0: axis = x.ndim + axis result = tf.reduce_sum(x, axis) result_shape = get_raw_dimensions(x) result_shape = list(result_shape[:axis]) + list( result_shape[axis + 1:]) if get_raw_dimensions(result).ndims is None: result.set_shape(result_shape) return result
def _tf_sub(self, other): self_dim = list(get_raw_dimensions(self)) other_dim = list(get_raw_dimensions(other)) if isinstance(self, tf.Variable): self = self._AsTensor() if isinstance(other, tf.Variable): other = other._AsTensor() result = _old_sub(self, other) result_dim = get_raw_dimensions(result) if result_dim.ndims is None: # we could infer the shape in this case if len(self_dim) > len(other_dim): result.set_shape(self_dim) else: result.set_shape(other_dim) return result
def _tf_rmul(self, other): self_dim = list(get_raw_dimensions(self)) other_dim = list(get_raw_dimensions(other)) if isinstance(self, tf.Variable): self = self._AsTensor() if isinstance(other, tf.Variable): other = other._AsTensor() if not self.dtype.is_floating and (isinstance(other, float) or other.dtype.is_floating): self = tf.cast(self, tf.float32) result = _old_rmul(self, other) result_dim = get_raw_dimensions(result) if result_dim.ndims is None: # we could infer the shape in this case if len(self_dim) > len(other_dim): result.set_shape(self_dim) else: result.set_shape(other_dim) return result
def exp(x): result = tf.exp(x) if get_raw_dimensions(result).ndims is None: result.set_shape(get_raw_dimensions(x)) return result