Skip to content

Commit fe558b0

Browse files
Deprecate tf.select since it is getting replaced by tf.where.
Change: 140632089
1 parent a3b8ea6 commit fe558b0

26 files changed

Lines changed: 94 additions & 79 deletions

File tree

RELEASE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ BUS_ANY was used.
2424
`Saver` a list of variable renames. Examples of variable scope changes
2525
include `RNN` -> `rnn` in `tf.nn.rnn`, `tf.nn.dynamic_rnn` and moving from
2626
`Linear/Matrix` -> `weights` and `Linear/Bias` -> `biases` in most RNN cells.
27+
* Deprecated tf.select op. tf.where should be used instead.
2728

2829
# Release 0.11.0
2930

tensorflow/contrib/bayesflow/python/ops/special_math.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
from tensorflow.python.framework import constant_op
2525
from tensorflow.python.framework import ops
26+
from tensorflow.python.ops import array_ops
2627
from tensorflow.python.ops import math_ops
2728

2829
__all__ = [
@@ -90,9 +91,9 @@ def _ndtr(x):
9091
0.5 * math.sqrt(2.), dtype=x.dtype, name="half_sqrt_2")
9192
w = x * half_sqrt_2
9293
z = math_ops.abs(w)
93-
y = math_ops.select(math_ops.less(z, half_sqrt_2),
94+
y = array_ops.where(math_ops.less(z, half_sqrt_2),
9495
1. + math_ops.erf(w),
95-
math_ops.select(math_ops.greater(w, 0.),
96+
array_ops.where(math_ops.greater(w, 0.),
9697
2. - math_ops.erfc(z),
9798
math_ops.erfc(z)))
9899
return 0.5 * y
@@ -180,10 +181,10 @@ def log_ndtr(x, series_order=3, name="log_ndtr"):
180181
# the gradient of a select involves the calculation 1*dy+0*(-inf)=nan
181182
# regardless of whether dy is finite. Note that the minimum is a NOP if
182183
# the branch is chosen.
183-
return math_ops.select(
184+
return array_ops.where(
184185
math_ops.greater(x, upper_segment),
185186
-_ndtr(-x), # log(1-x) ~= -x, x << 1
186-
math_ops.select(math_ops.greater(x, lower_segment),
187+
array_ops.where(math_ops.greater(x, lower_segment),
187188
math_ops.log(_ndtr(math_ops.maximum(x, lower_segment))),
188189
_log_ndtr_lower(math_ops.minimum(x, lower_segment),
189190
series_order)))

tensorflow/contrib/distributions/python/ops/beta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def _mode(self):
252252
mode = (self.a - 1.)/ (self.a_b_sum - 2.)
253253
if self.allow_nan_stats:
254254
nan = np.array(np.nan, dtype=self.dtype.as_numpy_dtype())
255-
return math_ops.select(
255+
return array_ops.where(
256256
math_ops.logical_and(
257257
math_ops.greater(self.a, 1.),
258258
math_ops.greater(self.b, 1.)),

tensorflow/contrib/distributions/python/ops/bijector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ def _process_scale(self, scale, event_ndims):
14681468
batch_ndims: `Tensor` (0D, `int32`). The ndims of the `batch` portion.
14691469
"""
14701470
ndims = array_ops.rank(scale)
1471-
left = math_ops.select(
1471+
left = array_ops.where(
14721472
math_ops.reduce_any([
14731473
math_ops.reduce_all([
14741474
math_ops.equal(ndims, 0),
@@ -1478,7 +1478,7 @@ def _process_scale(self, scale, event_ndims):
14781478
math_ops.equal(ndims, 2),
14791479
math_ops.equal(event_ndims, 1)
14801480
])]), 1, 0)
1481-
right = math_ops.select(math_ops.equal(event_ndims, 0), 2, 0)
1481+
right = array_ops.where(math_ops.equal(event_ndims, 0), 2, 0)
14821482
pad = array_ops.concat(0, (
14831483
array_ops.ones([left], dtype=dtypes.int32),
14841484
array_ops.shape(scale),

tensorflow/contrib/distributions/python/ops/dirichlet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def _mode(self):
239239
if self.allow_nan_stats:
240240
nan = np.array(np.nan, dtype=self.dtype.as_numpy_dtype())
241241
shape = array_ops.concat(0, (self.batch_shape(), self.event_shape()))
242-
return math_ops.select(
242+
return array_ops.where(
243243
math_ops.greater(self.alpha, 1.),
244244
mode,
245245
array_ops.fill(shape, nan, name="nan"))

tensorflow/contrib/distributions/python/ops/distribution_util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def rotate_transpose(x, shift, name="rotate_transpose"):
335335
# Finally, we transform shift by modulo length so it can be specified
336336
# independently from the array upon which it operates (like python).
337337
ndims = array_ops.rank(x)
338-
shift = math_ops.select(math_ops.less(shift, 0),
338+
shift = array_ops.where(math_ops.less(shift, 0),
339339
math_ops.mod(-shift, ndims),
340340
ndims - math_ops.mod(shift, ndims))
341341
first = math_ops.range(0, shift)
@@ -396,8 +396,8 @@ def pick_vector(cond,
396396
false_vector.name, false_vector.dtype))
397397
n = array_ops.shape(true_vector)[0]
398398
return array_ops.slice(array_ops.concat(0, (true_vector, false_vector)),
399-
[math_ops.select(cond, 0, n)],
400-
[math_ops.select(cond, n, -1)])
399+
[array_ops.where(cond, 0, n)],
400+
[array_ops.where(cond, n, -1)])
401401

402402

403403
def gen_new_seed(seed, salt):

tensorflow/contrib/distributions/python/ops/gamma.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _mode(self):
208208
mode = (self.alpha - 1.) / self.beta
209209
if self.allow_nan_stats:
210210
nan = np.array(np.nan, dtype=self.dtype.as_numpy_dtype())
211-
return math_ops.select(
211+
return array_ops.where(
212212
self.alpha >= 1.,
213213
mode,
214214
array_ops.fill(self.batch_shape(), nan, name="nan"))

tensorflow/contrib/distributions/python/ops/inverse_gamma.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def _mean(self):
185185
mean = self.beta / (self.alpha - 1.)
186186
if self.allow_nan_stats:
187187
nan = np.array(np.nan, dtype=self.dtype.as_numpy_dtype())
188-
return math_ops.select(
188+
return array_ops.where(
189189
self.alpha > 1., mean,
190190
array_ops.fill(self.batch_shape(), nan, name="nan"))
191191
else:
@@ -204,7 +204,7 @@ def _variance(self):
204204
(math_ops.square(self.alpha - 1.) * (self.alpha - 2.)))
205205
if self.allow_nan_stats:
206206
nan = np.array(np.nan, dtype=self.dtype.as_numpy_dtype())
207-
return math_ops.select(
207+
return array_ops.where(
208208
self.alpha > 2., var,
209209
array_ops.fill(self.batch_shape(), nan, name="nan"))
210210
else:

tensorflow/contrib/distributions/python/ops/quantized_distribution.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,11 @@ def _sample_n(self, n, seed=None):
284284
result_so_far = math_ops.ceil(x_samps)
285285

286286
if lower_cutoff is not None:
287-
result_so_far = math_ops.select(result_so_far < lower_cutoff,
287+
result_so_far = array_ops.where(result_so_far < lower_cutoff,
288288
lower_cutoff * ones, result_so_far)
289289

290290
if upper_cutoff is not None:
291-
result_so_far = math_ops.select(result_so_far > upper_cutoff,
291+
result_so_far = array_ops.where(result_so_far > upper_cutoff,
292292
upper_cutoff * ones, result_so_far)
293293

294294
return result_so_far
@@ -327,8 +327,8 @@ def _log_prob_with_logsf_and_logcdf(self, y):
327327
# In either case, we are doing Log[ exp{big} - exp{small} ]
328328
# We want to use the sf items precisely when we are on the right side of the
329329
# median, which occurs when logsf_y < logcdf_y.
330-
big = math_ops.select(logsf_y < logcdf_y, logsf_y_minus_1, logcdf_y)
331-
small = math_ops.select(logsf_y < logcdf_y, logsf_y, logcdf_y_minus_1)
330+
big = array_ops.where(logsf_y < logcdf_y, logsf_y_minus_1, logcdf_y)
331+
small = array_ops.where(logsf_y < logcdf_y, logsf_y, logcdf_y_minus_1)
332332

333333
return _logsum_expbig_minus_expsmall(big, small)
334334

@@ -357,7 +357,7 @@ def _prob_with_sf_and_cdf(self, y):
357357
cdf_y_minus_1 = self.cdf(y - 1)
358358

359359
# sf_prob has greater precision iff we're on the right side of the median.
360-
return math_ops.select(
360+
return array_ops.where(
361361
sf_y < cdf_y, # True iff we're on the right side of the median.
362362
sf_y_minus_1 - sf_y,
363363
cdf_y - cdf_y_minus_1)
@@ -386,9 +386,9 @@ def _log_cdf(self, y):
386386
# Re-define values at the cutoffs.
387387
if lower_cutoff is not None:
388388
neg_inf = -np.inf * array_ops.ones_like(result_so_far)
389-
result_so_far = math_ops.select(j < lower_cutoff, neg_inf, result_so_far)
389+
result_so_far = array_ops.where(j < lower_cutoff, neg_inf, result_so_far)
390390
if upper_cutoff is not None:
391-
result_so_far = math_ops.select(j >= upper_cutoff,
391+
result_so_far = array_ops.where(j >= upper_cutoff,
392392
array_ops.zeros_like(result_so_far),
393393
result_so_far)
394394

@@ -418,11 +418,11 @@ def _cdf(self, y):
418418

419419
# Re-define values at the cutoffs.
420420
if lower_cutoff is not None:
421-
result_so_far = math_ops.select(j < lower_cutoff,
421+
result_so_far = array_ops.where(j < lower_cutoff,
422422
array_ops.zeros_like(result_so_far),
423423
result_so_far)
424424
if upper_cutoff is not None:
425-
result_so_far = math_ops.select(j >= upper_cutoff,
425+
result_so_far = array_ops.where(j >= upper_cutoff,
426426
array_ops.ones_like(result_so_far),
427427
result_so_far)
428428

@@ -452,12 +452,12 @@ def _log_survival_function(self, y):
452452

453453
# Re-define values at the cutoffs.
454454
if lower_cutoff is not None:
455-
result_so_far = math_ops.select(j < lower_cutoff,
455+
result_so_far = array_ops.where(j < lower_cutoff,
456456
array_ops.zeros_like(result_so_far),
457457
result_so_far)
458458
if upper_cutoff is not None:
459459
neg_inf = -np.inf * array_ops.ones_like(result_so_far)
460-
result_so_far = math_ops.select(j >= upper_cutoff, neg_inf, result_so_far)
460+
result_so_far = array_ops.where(j >= upper_cutoff, neg_inf, result_so_far)
461461

462462
return result_so_far
463463

@@ -485,11 +485,11 @@ def _survival_function(self, y):
485485

486486
# Re-define values at the cutoffs.
487487
if lower_cutoff is not None:
488-
result_so_far = math_ops.select(j < lower_cutoff,
488+
result_so_far = array_ops.where(j < lower_cutoff,
489489
array_ops.ones_like(result_so_far),
490490
result_so_far)
491491
if upper_cutoff is not None:
492-
result_so_far = math_ops.select(j >= upper_cutoff,
492+
result_so_far = array_ops.where(j >= upper_cutoff,
493493
array_ops.zeros_like(result_so_far),
494494
result_so_far)
495495

tensorflow/contrib/distributions/python/ops/shape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def undo_make_batch_of_event_sample_matrices(
422422
batch_shape = array_ops.slice(s, (1,), (self.batch_ndims,))
423423
# Since sample_dims=1 and is left-most, we add 1 to the number of
424424
# batch_ndims to get the event start dim.
425-
event_start = math_ops.select(
425+
event_start = array_ops.where(
426426
self._batch_ndims_is_0, 2, 1 + self.batch_ndims)
427427
event_shape = array_ops.slice(s, (event_start,), (self.event_ndims,))
428428
new_shape = array_ops.concat(0, (sample_shape, batch_shape, event_shape))

0 commit comments

Comments
 (0)