Skip to content

Commit

Permalink
Rename usages of tf.mul, tf.neg, tf.sub that are used internally
Browse files Browse the repository at this point in the history
Change: 142595367
  • Loading branch information
aselle authored and tensorflower-gardener committed Dec 20, 2016
1 parent d2b92f2 commit cb4acf5
Show file tree
Hide file tree
Showing 40 changed files with 242 additions and 225 deletions.
4 changes: 2 additions & 2 deletions tensorflow/contrib/layers/python/layers/embedding_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def _sampled_scattered_embedding_lookup(
math_ops.range(0, dimension), 0), array_ops.shape(values))
else:
dimension = array_ops.shape(sampled_candidates)[
math_ops.sub(array_ops.rank(sampled_candidates), 1)]
math_ops.subtract(array_ops.rank(sampled_candidates), 1)]
sampled_candidates_shape = array_ops.shape(sampled_candidates)
dimension_tensor = array_ops.reshape(dimension, shape=[1,])
expected_shape = array_ops.concat_v2([values_shape, dimension_tensor], 0)
Expand Down Expand Up @@ -539,7 +539,7 @@ def _sampled_scattered_embedding_lookup_sparse(params,
array_ops.constant([-1., 1.]), sp_values.values, dimension=dimension,
sampled_candidates=sampled_candidates, hash_key=hash_key,
name="signs_lookup")
embeddings = math_ops.mul(signs, embeddings, name="signs_hash")
embeddings = math_ops.multiply(signs, embeddings, name="signs_hash")

if segment_ids.dtype != dtypes.int32:
segment_ids = math_ops.cast(segment_ids, dtypes.int32)
Expand Down
6 changes: 3 additions & 3 deletions tensorflow/contrib/layers/python/layers/target_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ def problem_type(self):
def _weighted_loss(self, loss, weight_tensor):
"""Returns cumulative weighted loss."""
unweighted_loss = array_ops.reshape(loss, shape=(-1,))
weighted_loss = math_ops.mul(unweighted_loss,
array_ops.reshape(
weight_tensor, shape=(-1,)))
weighted_loss = math_ops.multiply(unweighted_loss,
array_ops.reshape(
weight_tensor, shape=(-1,)))
return weighted_loss

def training_loss(self, logits, target, features, name="training_loss"):
Expand Down
3 changes: 2 additions & 1 deletion tensorflow/contrib/layers/python/ops/sparse_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def dense_to_sparse_tensor(dense_tensor, ignore_value=None):
shape_multipliers = array_ops.stack(
_multiplier_helper(array_ops.unstack(dense_shape)[1:]))
offsets = math_ops.reduce_sum(
math_ops.mul(higher_dims, shape_multipliers), reduction_indices=[1])
math_ops.multiply(higher_dims, shape_multipliers),
reduction_indices=[1])
flat_indices = math_ops.add(flat_indices, offsets)
values = array_ops.gather(flat_tensor, flat_indices)
return sparse_tensor.SparseTensor(indices, values, dense_shape)
6 changes: 3 additions & 3 deletions tensorflow/contrib/learn/python/learn/estimators/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,9 +1171,9 @@ def _combine_eval(self, all_model_fn_ops):
def _weighted_loss(loss, weight):
"""Returns cumulative weighted loss as 1d `Tensor`."""
with ops.name_scope(None, "weighted_loss", (loss, weight)) as name:
return math_ops.mul(array_ops.reshape(loss, shape=(-1,)),
array_ops.reshape(weight, shape=(-1,)),
name=name)
return math_ops.multiply(array_ops.reshape(loss, shape=(-1,)),
array_ops.reshape(weight, shape=(-1,)),
name=name)


def _weight_tensor(features, weight_column_name):
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/contrib/learn/python/learn/ops/losses_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ def softmax_classifier(tensor_in,
with ops.name_scope(name, 'softmax_classifier', [tensor_in, labels]):
logits = nn.xw_plus_b(tensor_in, weights, biases)
if class_weight is not None:
logits = math_ops.mul(logits, class_weight)
logits = math_ops.multiply(logits, class_weight)
return nn.softmax(logits), loss_ops.softmax_cross_entropy(logits, labels)
16 changes: 8 additions & 8 deletions tensorflow/contrib/linear_optimizer/python/ops/sdca_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def _linear_predictions(self, examples):
for sfc, sv in zip(examples['sparse_features'], sparse_variables):
# TODO(sibyl-Aix6ihai): following does not take care of missing features.
result += math_ops.segment_sum(
math_ops.mul(
math_ops.multiply(
array_ops.gather(sv, sfc.feature_indices), sfc.feature_values),
sfc.example_indices)
dense_features = self._convert_n_to_tensor(examples['dense_features'])
Expand Down Expand Up @@ -454,27 +454,27 @@ def unregularized_loss(self, examples):
examples['example_weights']), dtypes.float64)

if self._options['loss_type'] == 'logistic_loss':
return math_ops.reduce_sum(math_ops.mul(
return math_ops.reduce_sum(math_ops.multiply(
sigmoid_cross_entropy_with_logits(predictions, labels),
weights)) / math_ops.reduce_sum(weights)

if self._options['loss_type'] in ['hinge_loss', 'smooth_hinge_loss']:
# hinge_loss = max{0, 1 - y_i w*x} where y_i \in {-1, 1}. So, we need to
# first convert 0/1 labels into -1/1 labels.
all_ones = array_ops.ones_like(predictions)
adjusted_labels = math_ops.sub(2 * labels, all_ones)
adjusted_labels = math_ops.subtract(2 * labels, all_ones)
# Tensor that contains (unweighted) error (hinge loss) per
# example.
error = nn_ops.relu(math_ops.sub(all_ones, math_ops.mul(adjusted_labels,
predictions)))
weighted_error = math_ops.mul(error, weights)
error = nn_ops.relu(math_ops.subtract(
all_ones, math_ops.multiply(adjusted_labels, predictions)))
weighted_error = math_ops.multiply(error, weights)
return math_ops.reduce_sum(weighted_error) / math_ops.reduce_sum(
weights)

# squared loss
err = math_ops.sub(labels, predictions)
err = math_ops.subtract(labels, predictions)

weighted_squared_err = math_ops.mul(math_ops.square(err), weights)
weighted_squared_err = math_ops.multiply(math_ops.square(err), weights)
# SDCA squared loss function is sum(err^2) / (2*sum(weights))
return (math_ops.reduce_sum(weighted_squared_err) /
(2.0 * math_ops.reduce_sum(weights)))
Expand Down
23 changes: 12 additions & 11 deletions tensorflow/contrib/losses/python/losses/loss_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _scale_losses(losses, weights):
reduction_indices = list(range(start_index, losses.get_shape().ndims))
reduced_losses = math_ops.reduce_sum(losses,
reduction_indices=reduction_indices)
reduced_losses = math_ops.mul(reduced_losses, weights)
reduced_losses = math_ops.multiply(reduced_losses, weights)
return math_ops.reduce_sum(reduced_losses)


Expand Down Expand Up @@ -181,7 +181,7 @@ def _num_present(losses, weights, per_batch=False):
math_ops.to_float(batch_size))
num_per_batch = array_ops.where(math_ops.equal(weights, 0),
0.0, num_per_batch)
num_per_batch = math_ops.mul(array_ops.ones(
num_per_batch = math_ops.multiply(array_ops.ones(
array_ops.reshape(batch_size, [1])), num_per_batch)
return num_per_batch if per_batch else math_ops.reduce_sum(num_per_batch)

Expand All @@ -197,7 +197,7 @@ def _num_present(losses, weights, per_batch=False):
[weights.get_shape().ndims], [-1])
num_to_broadcast = math_ops.to_float(math_ops.reduce_prod(broadcast_dims))

num_per_batch = math_ops.mul(num_nonzero_per_batch, num_to_broadcast)
num_per_batch = math_ops.multiply(num_nonzero_per_batch, num_to_broadcast)
return num_per_batch if per_batch else math_ops.reduce_sum(num_per_batch)


Expand Down Expand Up @@ -295,7 +295,7 @@ def absolute_difference(predictions, labels=None, weights=1.0, scope=None):
predictions.get_shape().assert_is_compatible_with(labels.get_shape())
predictions = math_ops.to_float(predictions)
labels = math_ops.to_float(labels)
losses = math_ops.abs(math_ops.sub(predictions, labels))
losses = math_ops.abs(math_ops.subtract(predictions, labels))
return compute_weighted_loss(losses, weights, scope=scope)


Expand Down Expand Up @@ -458,9 +458,9 @@ def log_loss(predictions, labels=None, weights=1.0, epsilon=1e-7, scope=None):
predictions.get_shape().assert_is_compatible_with(labels.get_shape())
predictions = math_ops.to_float(predictions)
labels = math_ops.to_float(labels)
losses = -math_ops.mul(
losses = -math_ops.multiply(
labels,
math_ops.log(predictions + epsilon)) - math_ops.mul(
math_ops.log(predictions + epsilon)) - math_ops.multiply(
(1 - labels), math_ops.log(1 - predictions + epsilon))
return compute_weighted_loss(losses, weights, scope=scope)

Expand All @@ -487,8 +487,9 @@ def hinge_loss(logits, labels=None, scope=None):
# We first need to convert binary labels to -1/1 labels (as floats).
labels = math_ops.to_float(labels)
all_ones = array_ops.ones_like(labels)
labels = math_ops.sub(2 * labels, all_ones)
return nn_ops.relu(math_ops.sub(all_ones, math_ops.mul(labels, logits)))
labels = math_ops.subtract(2 * labels, all_ones)
return nn_ops.relu(
math_ops.subtract(all_ones, math_ops.multiply(labels, logits)))


@deprecated("2016-12-30", "Use tf.losses.mean_squared_error instead.")
Expand Down Expand Up @@ -522,7 +523,7 @@ def mean_squared_error(predictions, labels=None, weights=1.0, scope=None):
predictions.get_shape().assert_is_compatible_with(labels.get_shape())
predictions = math_ops.to_float(predictions)
labels = math_ops.to_float(labels)
losses = math_ops.square(math_ops.sub(predictions, labels))
losses = math_ops.square(math_ops.subtract(predictions, labels))
return compute_weighted_loss(losses, weights, scope=scope)


Expand Down Expand Up @@ -574,7 +575,7 @@ def mean_pairwise_squared_error(
labels = math_ops.to_float(labels)
weights = math_ops.to_float(ops.convert_to_tensor(weights))

diffs = math_ops.sub(predictions, labels)
diffs = math_ops.subtract(predictions, labels)

# Need to verify here since the function doesn't use compute_weighted_loss
if diffs.get_shape().ndims is None:
Expand Down Expand Up @@ -638,6 +639,6 @@ def cosine_distance(
predictions = math_ops.to_float(predictions)
labels = math_ops.to_float(labels)

radial_diffs = math_ops.mul(predictions, labels)
radial_diffs = math_ops.multiply(predictions, labels)
losses = 1 - math_ops.reduce_sum(radial_diffs, reduction_indices=[dim,])
return compute_weighted_loss(losses, weights, scope=scope)
4 changes: 2 additions & 2 deletions tensorflow/contrib/metrics/python/metrics/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def accuracy(predictions, labels, weights=None):
is_correct = math_ops.cast(
math_ops.equal(predictions, labels), dtypes.float32)
if weights is not None:
is_correct = math_ops.mul(is_correct, weights)
num_values = math_ops.mul(weights, array_ops.ones_like(is_correct))
is_correct = math_ops.multiply(is_correct, weights)
num_values = math_ops.multiply(weights, array_ops.ones_like(is_correct))
return math_ops.div(math_ops.reduce_sum(is_correct),
math_ops.reduce_sum(num_values))
return math_ops.reduce_mean(is_correct)
23 changes: 12 additions & 11 deletions tensorflow/contrib/metrics/python/ops/metric_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _count_condition(values, weights=None, metrics_collections=None,
values = math_ops.to_float(values)
if weights is not None:
weights = math_ops.to_float(weights)
values = math_ops.mul(values, weights)
values = math_ops.multiply(values, weights)

value_tensor = array_ops.identity(count)
update_op = state_ops.assign_add(count, math_ops.reduce_sum(values))
Expand Down Expand Up @@ -318,7 +318,7 @@ def _broadcast_weights(weights, values):
values_shape.is_fully_defined() and
weights_shape.is_compatible_with(values_shape)):
return weights
return math_ops.mul(
return math_ops.multiply(
weights, array_ops.ones_like(values), name='broadcast_weights')


Expand Down Expand Up @@ -1542,7 +1542,7 @@ def sparse_average_precision_at_k(predictions, labels, k):
precision_per_k = math_ops.div(
math_ops.to_double(tp_per_k), math_ops.to_double(retrieved_per_k),
name='precision_per_k')
relevant_precision_per_k = math_ops.mul(
relevant_precision_per_k = math_ops.multiply(
precision_per_k, math_ops.to_double(relevant_per_k),
name='relevant_precision_per_k')

Expand Down Expand Up @@ -1710,7 +1710,7 @@ def _sparse_true_positive_at_k(predictions_idx,
tp = math_ops.to_double(tp)
if weights is not None:
weights = math_ops.to_double(weights)
tp = math_ops.mul(tp, weights)
tp = math_ops.multiply(tp, weights)
return tp


Expand Down Expand Up @@ -1798,7 +1798,7 @@ def _sparse_false_positive_at_k(predictions_idx,
fp = math_ops.to_double(fp)
if weights is not None:
weights = math_ops.to_double(weights)
fp = math_ops.mul(fp, weights)
fp = math_ops.multiply(fp, weights)
return fp


Expand Down Expand Up @@ -1887,7 +1887,7 @@ def _sparse_false_negative_at_k(predictions_idx,
fn = math_ops.to_double(fn)
if weights is not None:
weights = math_ops.to_double(weights)
fn = math_ops.mul(fn, weights)
fn = math_ops.multiply(fn, weights)
return fn


Expand Down Expand Up @@ -2329,11 +2329,12 @@ def streaming_pearson_correlation(predictions,

pearson_r = _safe_div(
cov,
math_ops.mul(math_ops.sqrt(var_predictions), math_ops.sqrt(var_labels)),
math_ops.multiply(math_ops.sqrt(var_predictions),
math_ops.sqrt(var_labels)),
'pearson_r')
with ops.control_dependencies(
[update_cov, update_var_predictions, update_var_labels]):
update_op = _safe_div(update_cov, math_ops.mul(
update_op = _safe_div(update_cov, math_ops.multiply(
math_ops.sqrt(update_var_predictions),
math_ops.sqrt(update_var_labels)), 'update_op')

Expand Down Expand Up @@ -2393,16 +2394,16 @@ def streaming_mean_cosine_distance(predictions, labels, dim, weights=None,
predictions, labels, weights = _remove_squeezable_dimensions(
predictions, labels, weights)
predictions.get_shape().assert_is_compatible_with(labels.get_shape())
radial_diffs = math_ops.mul(predictions, labels)
radial_diffs = math_ops.multiply(predictions, labels)
radial_diffs = math_ops.reduce_sum(radial_diffs,
reduction_indices=[dim,],
keep_dims=True)
mean_distance, update_op = streaming_mean(radial_diffs, weights,
None,
None,
name or 'mean_cosine_distance')
mean_distance = math_ops.sub(1.0, mean_distance)
update_op = math_ops.sub(1.0, update_op)
mean_distance = math_ops.subtract(1.0, mean_distance)
update_op = math_ops.subtract(1.0, update_op)

if metrics_collections:
ops.add_to_collections(metrics_collections, mean_distance)
Expand Down
10 changes: 5 additions & 5 deletions tensorflow/contrib/tensor_forest/python/tensor_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,11 @@ def average_size(self):
# pylint: disable=unused-argument
def training_loss(self, features, labels, data_spec=None,
name='training_loss'):
return math_ops.neg(self.average_size(), name=name)
return math_ops.negative(self.average_size(), name=name)

# pylint: disable=unused-argument
def validation_loss(self, features, labels):
return math_ops.neg(self.average_size())
return math_ops.negative(self.average_size())

def average_impurity(self):
"""Constructs a TF graph for evaluating the leaf impurity of a forest.
Expand Down Expand Up @@ -832,8 +832,8 @@ def training_graph(self,
# Calculate values to put into scatter update for total counts.
total_cleared = array_ops.tile(
array_ops.expand_dims(
math_ops.neg(array_ops.ones_like(accumulators_cleared,
dtype=dtypes.float32)), 1),
math_ops.negative(array_ops.ones_like(accumulators_cleared,
dtype=dtypes.float32)), 1),
[1, self.params.num_output_columns])
total_reset = array_ops.tile(
array_ops.expand_dims(
Expand All @@ -852,7 +852,7 @@ def training_graph(self,
# Calculate values to put into scatter update for candidate splits.
split_features_updates = array_ops.tile(
array_ops.expand_dims(
math_ops.neg(array_ops.ones_like(
math_ops.negative(array_ops.ones_like(
cleared_and_allocated_accumulators)), 1),
[1, self.params.num_splits_to_consider])
updates.append(state_ops.scatter_update(
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/python/client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ def partial_run(self, handle, fetches, feed_dict=None):
b = array_ops.placeholder(dtypes.float32, shape=[])
c = array_ops.placeholder(dtypes.float32, shape=[])
r1 = math_ops.add(a, b)
r2 = math_ops.mul(r1, c)
r2 = math_ops.multiply(r1, c)
h = sess.partial_run_setup([r1, r2], [a, b, c])
res = sess.partial_run(h, r1, feed_dict={a: 1, b: 2})
Expand Down
10 changes: 5 additions & 5 deletions tensorflow/python/client/session_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ def runTestPartialRun(self, sess):
b = array_ops.placeholder(dtypes.float32, shape=[])
c = array_ops.placeholder(dtypes.float32, shape=[])
r1 = math_ops.add(a, b)
r2 = math_ops.mul(r1, c)
r2 = math_ops.multiply(r1, c)

h = sess.partial_run_setup([r1, r2], [a, b, c])
res = sess.partial_run(h, r1, feed_dict={a: 1, b: 2})
Expand All @@ -1350,7 +1350,7 @@ def runTestPartialRunIncomplete(self, sess):
b = array_ops.placeholder(dtypes.float32, shape=[])
c = array_ops.placeholder(dtypes.float32, shape=[])
r1 = math_ops.add(a, b)
r2 = math_ops.mul(r1, c)
r2 = math_ops.multiply(r1, c)

h = sess.partial_run_setup([r1, r2], [a, b, c])
res = sess.partial_run(h, r1, feed_dict={a: 1, b: 2})
Expand All @@ -1361,7 +1361,7 @@ def runTestConcurrentPartialRun(self, sess):
b = array_ops.placeholder(dtypes.float32, shape=[])
c = array_ops.placeholder(dtypes.float32, shape=[])
r1 = math_ops.add(a, b)
r2 = math_ops.mul(r1, c)
r2 = math_ops.multiply(r1, c)

h1 = sess.partial_run_setup([r1], [a, b, c])
h2 = sess.partial_run_setup([r1, r2], [a, b, c])
Expand All @@ -1380,7 +1380,7 @@ def runTestManyPartialRun(self, sess):
a = constant_op.constant(2.0, dtypes.float32)
for i in xrange(steps):
inputs.append(array_ops.placeholder(dtypes.float32, shape=[]))
a = math_ops.mul(a, inputs[i])
a = math_ops.multiply(a, inputs[i])
outputs.append(a)

h = sess.partial_run_setup(outputs, inputs)
Expand Down Expand Up @@ -1528,7 +1528,7 @@ def testBuildCostModel(self):
a = array_ops.placeholder(dtypes.float32, shape=[])
b = math_ops.add(a, a)
c = array_ops.identity(b)
d = math_ops.mul(c, c)
d = math_ops.multiply(c, c)
for step in xrange(120):
run_metadata = config_pb2.RunMetadata()
sess.run(d, feed_dict={a: 1.0},
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/python/debug/cli/analyzer_cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ def setUpClass(cls):
y = control_flow_ops.with_dependencies(
[x], y, name="control_deps/ctrl_dep_y")

z = math_ops.mul(x, y, name="control_deps/z")
z = math_ops.multiply(x, y, name="control_deps/z")

z = control_flow_ops.with_dependencies(
[x, y], z, name="control_deps/ctrl_dep_z")
Expand Down
Loading

0 comments on commit cb4acf5

Please sign in to comment.