Skip to content

Commit 1732bd5

Browse files
committed
Swap aliases removed in the latest numpy release.
Summary: Numpy removed support for np.object, np.bool, np.float, np.complex, np.str, and np.int with 1.24.0 release. Seems like upstream tensorflow just replaced these with an underscored version of these types, doing the same here. Reviewers: #tensorflow, #framework_ip_review_-_any_oss_or_third-party_code_use_has_been_approved, alfiee Reviewed By: #tensorflow, #framework_ip_review_-_any_oss_or_third-party_code_use_has_been_approved, alfiee Maniphest Tasks: T72490 Differential Revision: https://phabricator.sourcevertex.net/D79431
1 parent 2628014 commit 1732bd5

File tree

73 files changed

+267
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+267
-267
lines changed

tensorflow/compiler/plugin/poplar/tests/conditional_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def my_model(pcond, pa, pb, pc):
4343
return [output]
4444

4545
with ops.device("cpu"):
46-
pcond = array_ops.placeholder(np.bool, [], name="pred")
46+
pcond = array_ops.placeholder(np.bool_, [], name="pred")
4747
pa = array_ops.placeholder(np.float32, [], name="a")
4848
pb = array_ops.placeholder(np.float32, [], name="b")
4949
pc = array_ops.placeholder(np.float32, [], name="c")
@@ -69,7 +69,7 @@ def my_model(pcond, pa, pb, pc):
6969
return [output]
7070

7171
with ops.device("cpu"):
72-
pcond = array_ops.placeholder(np.bool, [], name="pred")
72+
pcond = array_ops.placeholder(np.bool_, [], name="pred")
7373
pa = array_ops.placeholder(np.float32, [], name="a")
7474
pb = array_ops.placeholder(np.float32, [], name="b")
7575
pc = array_ops.placeholder(np.float32, [], name="c")
@@ -101,7 +101,7 @@ def my_model(pcond):
101101
return [o]
102102

103103
with ops.device("cpu"):
104-
pcond = array_ops.placeholder(np.bool, [], name="pred")
104+
pcond = array_ops.placeholder(np.bool_, [], name="pred")
105105

106106
with ops.device("/device:IPU:0"):
107107
r = ipu.ipu_compiler.compile(my_model, inputs=[pcond])
@@ -133,7 +133,7 @@ def my_model(pcond):
133133
return [o, va.read_value()]
134134

135135
with ops.device("cpu"):
136-
pcond = array_ops.placeholder(np.bool, [], name="pred")
136+
pcond = array_ops.placeholder(np.bool_, [], name="pred")
137137

138138
with ops.device("/device:IPU:0"):
139139
r = ipu.ipu_compiler.compile(my_model, inputs=[pcond])

tensorflow/compiler/plugin/poplar/tests/lstm_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ def test_preserve_final_state(self):
864864
kernel = normal((INPUT_SIZE + NUM_CHANNELS, 4 * NUM_CHANNELS))
865865
biases = normal((4, NUM_CHANNELS))
866866
seq_lens = shuffled_range(batch_size) % SEQ_LEN + 1
867-
c_state_mask = np.zeros((batch_size, NUM_CHANNELS), np.bool)
867+
c_state_mask = np.zeros((batch_size, NUM_CHANNELS), np.bool_)
868868
c_state_mask[seq_lens == SEQ_LEN, :] = True
869869

870870
cfg = IPUConfig()

tensorflow/compiler/tests/binary_ops_test.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -772,123 +772,123 @@ def testFloatRemainder(self):
772772
def testLogicalOps(self):
773773
self._testBinary(
774774
math_ops.logical_and,
775-
np.array([[True, False], [False, True]], dtype=np.bool),
776-
np.array([[False, True], [False, True]], dtype=np.bool),
777-
expected=np.array([[False, False], [False, True]], dtype=np.bool))
775+
np.array([[True, False], [False, True]], dtype=np.bool_),
776+
np.array([[False, True], [False, True]], dtype=np.bool_),
777+
expected=np.array([[False, False], [False, True]], dtype=np.bool_))
778778

779779
self._testBinary(
780780
math_ops.logical_or,
781-
np.array([[True, False], [False, True]], dtype=np.bool),
782-
np.array([[False, True], [False, True]], dtype=np.bool),
783-
expected=np.array([[True, True], [False, True]], dtype=np.bool))
781+
np.array([[True, False], [False, True]], dtype=np.bool_),
782+
np.array([[False, True], [False, True]], dtype=np.bool_),
783+
expected=np.array([[True, True], [False, True]], dtype=np.bool_))
784784

785785
def testComparisons(self):
786786
self._testBinary(
787787
math_ops.equal,
788788
np.array([1, 5, 20], dtype=np.float32),
789789
np.array([10, 5, 2], dtype=np.float32),
790-
expected=np.array([False, True, False], dtype=np.bool))
790+
expected=np.array([False, True, False], dtype=np.bool_))
791791
self._testBinary(
792792
math_ops.equal,
793793
np.float32(5),
794794
np.array([1, 5, 20], dtype=np.float32),
795-
expected=np.array([False, True, False], dtype=np.bool))
795+
expected=np.array([False, True, False], dtype=np.bool_))
796796
self._testBinary(
797797
math_ops.equal,
798798
np.array([[10], [7], [2]], dtype=np.float32),
799799
np.float32(7),
800-
expected=np.array([[False], [True], [False]], dtype=np.bool))
800+
expected=np.array([[False], [True], [False]], dtype=np.bool_))
801801

802802
self._testBinary(
803803
math_ops.not_equal,
804804
np.array([1, 5, 20], dtype=np.float32),
805805
np.array([10, 5, 2], dtype=np.float32),
806-
expected=np.array([True, False, True], dtype=np.bool))
806+
expected=np.array([True, False, True], dtype=np.bool_))
807807
self._testBinary(
808808
math_ops.not_equal,
809809
np.float32(5),
810810
np.array([1, 5, 20], dtype=np.float32),
811-
expected=np.array([True, False, True], dtype=np.bool))
811+
expected=np.array([True, False, True], dtype=np.bool_))
812812
self._testBinary(
813813
math_ops.not_equal,
814814
np.array([[10], [7], [2]], dtype=np.float32),
815815
np.float32(7),
816-
expected=np.array([[True], [False], [True]], dtype=np.bool))
816+
expected=np.array([[True], [False], [True]], dtype=np.bool_))
817817

818818
for greater_op in [math_ops.greater, (lambda x, y: x > y)]:
819819
self._testBinary(
820820
greater_op,
821821
np.array([1, 5, 20], dtype=np.float32),
822822
np.array([10, 5, 2], dtype=np.float32),
823-
expected=np.array([False, False, True], dtype=np.bool))
823+
expected=np.array([False, False, True], dtype=np.bool_))
824824
self._testBinary(
825825
greater_op,
826826
np.float32(5),
827827
np.array([1, 5, 20], dtype=np.float32),
828-
expected=np.array([True, False, False], dtype=np.bool))
828+
expected=np.array([True, False, False], dtype=np.bool_))
829829
self._testBinary(
830830
greater_op,
831831
np.array([[10], [7], [2]], dtype=np.float32),
832832
np.float32(7),
833-
expected=np.array([[True], [False], [False]], dtype=np.bool))
833+
expected=np.array([[True], [False], [False]], dtype=np.bool_))
834834

835835
for greater_equal_op in [math_ops.greater_equal, (lambda x, y: x >= y)]:
836836
self._testBinary(
837837
greater_equal_op,
838838
np.array([1, 5, 20], dtype=np.float32),
839839
np.array([10, 5, 2], dtype=np.float32),
840-
expected=np.array([False, True, True], dtype=np.bool))
840+
expected=np.array([False, True, True], dtype=np.bool_))
841841
self._testBinary(
842842
greater_equal_op,
843843
np.float32(5),
844844
np.array([1, 5, 20], dtype=np.float32),
845-
expected=np.array([True, True, False], dtype=np.bool))
845+
expected=np.array([True, True, False], dtype=np.bool_))
846846
self._testBinary(
847847
greater_equal_op,
848848
np.array([[10], [7], [2]], dtype=np.float32),
849849
np.float32(7),
850-
expected=np.array([[True], [True], [False]], dtype=np.bool))
850+
expected=np.array([[True], [True], [False]], dtype=np.bool_))
851851

852852
for less_op in [math_ops.less, (lambda x, y: x < y)]:
853853
self._testBinary(
854854
less_op,
855855
np.array([1, 5, 20], dtype=np.float32),
856856
np.array([10, 5, 2], dtype=np.float32),
857-
expected=np.array([True, False, False], dtype=np.bool))
857+
expected=np.array([True, False, False], dtype=np.bool_))
858858
self._testBinary(
859859
less_op,
860860
np.float32(5),
861861
np.array([1, 5, 20], dtype=np.float32),
862-
expected=np.array([False, False, True], dtype=np.bool))
862+
expected=np.array([False, False, True], dtype=np.bool_))
863863
self._testBinary(
864864
less_op,
865865
np.array([[10], [7], [2]], dtype=np.float32),
866866
np.float32(7),
867-
expected=np.array([[False], [False], [True]], dtype=np.bool))
867+
expected=np.array([[False], [False], [True]], dtype=np.bool_))
868868
if np.int64 in self.numeric_types:
869869
self._testBinary(
870870
less_op,
871871
np.array([[10], [7], [2], [-1]], dtype=np.int64),
872872
np.int64(7),
873873
expected=np.array(
874-
[[False], [False], [True], [True]], dtype=np.bool))
874+
[[False], [False], [True], [True]], dtype=np.bool_))
875875

876876
for less_equal_op in [math_ops.less_equal, (lambda x, y: x <= y)]:
877877
self._testBinary(
878878
less_equal_op,
879879
np.array([1, 5, 20], dtype=np.float32),
880880
np.array([10, 5, 2], dtype=np.float32),
881-
expected=np.array([True, True, False], dtype=np.bool))
881+
expected=np.array([True, True, False], dtype=np.bool_))
882882
self._testBinary(
883883
less_equal_op,
884884
np.float32(5),
885885
np.array([1, 5, 20], dtype=np.float32),
886-
expected=np.array([False, True, True], dtype=np.bool))
886+
expected=np.array([False, True, True], dtype=np.bool_))
887887
self._testBinary(
888888
less_equal_op,
889889
np.array([[10], [7], [2]], dtype=np.float32),
890890
np.float32(7),
891-
expected=np.array([[False], [True], [True]], dtype=np.bool))
891+
expected=np.array([[False], [True], [True]], dtype=np.bool_))
892892

893893
def testS64Comparisons(self):
894894
for op in [(lambda x, y: x < y), (lambda x, y: x <= y),
@@ -961,7 +961,7 @@ def testS64Comparisons(self):
961961
np.int64(-1)
962962
],
963963
dtype=np.int64)
964-
expected = np.array([op(l, r) for l, r in zip(lhs, rhs)], dtype=np.bool)
964+
expected = np.array([op(l, r) for l, r in zip(lhs, rhs)], dtype=np.bool_)
965965
self._testBinary(op, lhs, rhs, expected=expected)
966966

967967
def testBroadcasting(self):

tensorflow/compiler/tests/reduce_ops_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ def _testReduction(self,
9292
NONEMPTY_REAL_DATA = [x for x in REAL_DATA if np.size(x) > 0]
9393
NONEMPTY_COMPLEX_DATA = [x for x in COMPLEX_DATA if np.size(x) > 0]
9494
BOOL_DATA = [
95-
np.array([], dtype=np.bool).reshape(2, 0),
96-
np.array([], dtype=np.bool).reshape(0, 3),
95+
np.array([], dtype=np.bool_).reshape(2, 0),
96+
np.array([], dtype=np.bool_).reshape(0, 3),
9797
np.array([[False, True, False], [True, True, False]]),
9898
]
9999
ONES = [np.ones([34000, 2])]
@@ -165,11 +165,11 @@ def testReduceMeanC64(self, index_dtype):
165165
self.NONEMPTY_COMPLEX_DATA, index_dtype)
166166

167167
def testReduceAll(self, index_dtype):
168-
self._testReduction(math_ops.reduce_all, np.all, np.bool, self.BOOL_DATA,
168+
self._testReduction(math_ops.reduce_all, np.all, np.bool_, self.BOOL_DATA,
169169
index_dtype)
170170

171171
def testReduceAny(self, index_dtype):
172-
self._testReduction(math_ops.reduce_any, np.any, np.bool, self.BOOL_DATA,
172+
self._testReduction(math_ops.reduce_any, np.any, np.bool_, self.BOOL_DATA,
173173
index_dtype)
174174

175175
@test_util.disable_mlir_bridge('Error messages differ')

tensorflow/compiler/tests/ternary_ops_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ def testSelect(self):
102102

103103
self._testTernary(
104104
array_ops.where,
105-
np.array([0, 1, 1, 0], dtype=np.bool),
105+
np.array([0, 1, 1, 0], dtype=np.bool_),
106106
np.array([1, 2, 3, 4], dtype=dtype),
107107
np.array([5, 6, 7, 8], dtype=dtype),
108108
expected=np.array([5, 2, 3, 8], dtype=dtype))
109109

110110
self._testTernary(
111111
array_ops.where,
112-
np.array([0, 1, 0], dtype=np.bool),
112+
np.array([0, 1, 0], dtype=np.bool_),
113113
np.array([[1, 2], [3, 4], [5, 6]], dtype=dtype),
114114
np.array([[7, 8], [9, 10], [11, 12]], dtype=dtype),
115115
expected=np.array([[7, 8], [3, 4], [11, 12]], dtype=dtype))
@@ -139,45 +139,45 @@ def testSelectV2(self):
139139

140140
self._testTernary(
141141
array_ops.where_v2,
142-
np.array([0, 1, 1, 0], dtype=np.bool),
142+
np.array([0, 1, 1, 0], dtype=np.bool_),
143143
np.array([1, 2, 3, 4], dtype=dtype),
144144
np.array([5, 6, 7, 8], dtype=dtype),
145145
expected=np.array([5, 2, 3, 8], dtype=dtype))
146146

147147
# Broadcast the condition
148148
self._testTernary(
149149
array_ops.where_v2,
150-
np.array([0, 1], dtype=np.bool),
150+
np.array([0, 1], dtype=np.bool_),
151151
np.array([[1, 2], [3, 4], [5, 6]], dtype=dtype),
152152
np.array([[7, 8], [9, 10], [11, 12]], dtype=dtype),
153153
expected=np.array([[7, 2], [9, 4], [11, 6]], dtype=dtype))
154154

155155
# Broadcast the then branch to the else
156156
self._testTernary(
157157
array_ops.where_v2,
158-
np.array([[0, 1], [1, 0], [1, 1]], dtype=np.bool),
158+
np.array([[0, 1], [1, 0], [1, 1]], dtype=np.bool_),
159159
np.array([[1, 2]], dtype=dtype),
160160
np.array([[7, 8], [9, 10], [11, 12]], dtype=dtype),
161161
expected=np.array([[7, 2], [1, 10], [1, 2]], dtype=dtype))
162162

163163
# Broadcast the else branch to the then
164164
self._testTernary(
165165
array_ops.where_v2,
166-
np.array([[1, 0], [0, 1], [0, 0]], dtype=np.bool),
166+
np.array([[1, 0], [0, 1], [0, 0]], dtype=np.bool_),
167167
np.array([[7, 8], [9, 10], [11, 12]], dtype=dtype),
168168
np.array([[1, 2]], dtype=dtype),
169169
expected=np.array([[7, 2], [1, 10], [1, 2]], dtype=dtype))
170170

171171
# Broadcast the then/else branches to the condition
172172
self._testTernary(
173173
array_ops.where_v2,
174-
np.array([[1, 0], [0, 1], [1, 1]], dtype=np.bool),
174+
np.array([[1, 0], [0, 1], [1, 1]], dtype=np.bool_),
175175
np.array(7, dtype=dtype),
176176
np.array(8, dtype=dtype),
177177
expected=np.array([[7, 8], [8, 7], [7, 7]], dtype=dtype))
178178
self._testTernary(
179179
array_ops.where_v2,
180-
np.array([[1, 0], [0, 1], [0, 0]], dtype=np.bool),
180+
np.array([[1, 0], [0, 1], [0, 0]], dtype=np.bool_),
181181
np.array(7, dtype=dtype),
182182
np.array([8, 9], dtype=dtype),
183183
expected=np.array([[7, 9], [8, 7], [8, 9]], dtype=dtype))

tensorflow/compiler/tests/unary_ops_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def testFloatOps(self):
263263
math_ops.is_finite,
264264
np.array(
265265
[[np.NINF, -2, -1, 0, 0.5, 1, 2, np.inf, np.nan]], dtype=dtype),
266-
expected=np.array([[0, 1, 1, 1, 1, 1, 1, 0, 0]], dtype=np.bool))
266+
expected=np.array([[0, 1, 1, 1, 1, 1, 1, 0, 0]], dtype=np.bool_))
267267

268268
# Tests for tf.nn ops.
269269
self._assertOpOutputMatchesExpected(
@@ -449,7 +449,7 @@ def testFloatOps(self):
449449
np.array(
450450
[[42, float("inf"), -123], [float("nan"), 0, -0.0]], dtype=dtype),
451451
expected=np.array(
452-
[[True, False, True], [False, True, True]], dtype=np.bool))
452+
[[True, False, True], [False, True, True]], dtype=np.bool_))
453453

454454
self._assertOpOutputMatchesExpected(
455455
math_ops.lgamma,
@@ -855,12 +855,12 @@ def testIsInfAndIsNan(self):
855855
math_ops.is_inf,
856856
np.array(
857857
[[np.NINF, -2, -1, 0, 0.5, 1, 2, np.inf, np.nan]], dtype=dtype),
858-
expected=np.array([[1, 0, 0, 0, 0, 0, 0, 1, 0]], dtype=np.bool))
858+
expected=np.array([[1, 0, 0, 0, 0, 0, 0, 1, 0]], dtype=np.bool_))
859859
self._assertOpOutputMatchesExpected(
860860
math_ops.is_nan,
861861
np.array(
862862
[[np.NINF, -2, -1, 0, 0.5, 1, 2, np.inf, np.nan]], dtype=dtype),
863-
expected=np.array([[0, 0, 0, 0, 0, 0, 0, 0, 1]], dtype=np.bool))
863+
expected=np.array([[0, 0, 0, 0, 0, 0, 0, 0, 1]], dtype=np.bool_))
864864
self._assertOpOutputMatchesExpected(
865865
math_ops.sign,
866866
np.array([[np.nan]], dtype=dtype),
@@ -869,8 +869,8 @@ def testIsInfAndIsNan(self):
869869
def testLogicalOps(self):
870870
self._assertOpOutputMatchesExpected(
871871
math_ops.logical_not,
872-
np.array([[True, False], [False, True]], dtype=np.bool),
873-
expected=np.array([[False, True], [True, False]], dtype=np.bool))
872+
np.array([[True, False], [False, True]], dtype=np.bool_),
873+
expected=np.array([[False, True], [True, False]], dtype=np.bool_))
874874

875875
def testBiasAddGrad(self):
876876
self._assertOpOutputMatchesExpected(

tensorflow/compiler/xla/python/xla_client_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ def NumpyArrayS32(*args, **kwargs):
126126
return np.array(*args, dtype=np.int32, **kwargs)
127127

128128
def NumpyArrayBool(*args, **kwargs):
129-
"""Convenience wrapper to create Numpy arrays with a np.bool dtype."""
130-
return np.array(*args, dtype=np.bool, **kwargs)
129+
"""Convenience wrapper to create Numpy arrays with a np.bool_ dtype."""
130+
return np.array(*args, dtype=np.bool_, **kwargs)
131131

132132
class ComputationPrinting(absltest.TestCase):
133133

@@ -731,7 +731,7 @@ def testConcatenate(self, dtype):
731731
"src_dtype": src_dtype,
732732
"dst_dtype": dst_dtype,
733733
} for src_dtype, dst_dtype in itertools.permutations(
734-
[np.bool, np.int32, np.int64, np.float32, np.float64], 2))
734+
[np.bool_, np.int32, np.int64, np.float32, np.float64], 2))
735735
# pyformat: enable
736736
def testConvertElementType(self, src_dtype, dst_dtype):
737737
if ((src_dtype in [np.int64, np.float64] or

tensorflow/compiler/xla/python_api/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
xla_data_pb2.PRED:
117117
TypeConversionRecord(
118118
primitive_type=xla_data_pb2.PRED,
119-
numpy_dtype=_np.bool,
119+
numpy_dtype=_np.bool_,
120120
literal_field_name='preds',
121121
literal_field_type=bool)
122122
}

tensorflow/lite/experimental/mlir/testing/op_tests/cond.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def build_inputs(parameters, sess, inputs, outputs):
5757
input_values = [
5858
create_tensor_data(parameters["dtype"], (1,)),
5959
create_tensor_data(parameters["dtype"], (1,)),
60-
np.array([parameters["pred"]], dtype=np.bool),
60+
np.array([parameters["pred"]], dtype=np.bool_),
6161
]
6262
return input_values, sess.run(
6363
outputs, feed_dict=dict(zip(inputs, input_values)))

tensorflow/lite/micro/examples/micro_speech/apollo3/compare_1k.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def to_float(x, n):
7272
micro_dft = new_data_to_array('micro_dft.txt', datatype='int32')
7373
cmsis_dft = new_data_to_array('cmsis_dft.txt', datatype='int16')
7474
py_dft = np.fft.rfft(to_float(cmsis_windowed_input, 15), n=512)
75-
py_result = np.empty((2 * py_dft.size), dtype=np.float)
75+
py_result = np.empty((2 * py_dft.size), dtype=np.float_)
7676
py_result[0::2] = np.real(py_dft)
7777
py_result[1::2] = np.imag(py_dft)
7878

0 commit comments

Comments
 (0)