Skip to content

Commit

Permalink
[CODEMOD][caffe2] replace uses of np.float with np.float64 (pytorch#1…
Browse files Browse the repository at this point in the history
…12675)

Differential Revision: D50752096

Pull Request resolved: pytorch#112675
Approved by: https://github.com/Skylion007
  • Loading branch information
Igor Sugak authored and pytorchmergebot committed Nov 3, 2023
1 parent 8665a51 commit 4a17693
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 71 deletions.
12 changes: 6 additions & 6 deletions caffe2/python/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,33 +255,33 @@ class TestExternalInputs(test_util.TestCase):
def testAddExternalInputShouldRaiseIfDuplicate(self):
net = core.Net("test")
net.AddExternalInput(
schema.Struct(("x", schema.Scalar(np.float))),
schema.Struct(("x", schema.Scalar(np.float64))),
)
with self.assertRaises(AssertionError):
net.AddExternalInput(
schema.Struct(("x", schema.Scalar(np.float))),
schema.Struct(("x", schema.Scalar(np.float64))),
)

def testAddExternalInputShouldRaiseIfDuplicateInSameCall(self):
net = core.Net("test")
with self.assertRaises(AssertionError):
net.AddExternalInput(
schema.Struct(("x", schema.Scalar(np.float))),
schema.Struct(("x", schema.Scalar(np.float))),
schema.Struct(("x", schema.Scalar(np.float64))),
schema.Struct(("x", schema.Scalar(np.float64))),
)

def testSetInputRecordWithBlobs(self):
net = core.Net("test")
record = schema.NewRecord(net, schema.Struct(
("x", schema.Scalar(np.float)),
("x", schema.Scalar(np.float64)),
))
input_record = net.set_input_record(record)
self.assertTrue(net.BlobIsDefined(input_record.x()))
self.assertIn(input_record.x(), net.external_inputs)

def testSetInputRecordWithoutBlobs(self):
net = core.Net("test")
record = schema.Struct(("x", schema.Scalar(np.float)))
record = schema.Struct(("x", schema.Scalar(np.float64)))
input_record = net.set_input_record(record)
self.assertTrue(net.BlobIsDefined(input_record.x()))
self.assertIn(input_record.x(), net.external_inputs)
Expand Down
2 changes: 1 addition & 1 deletion caffe2/python/layer_model_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def add_ad_hoc_plot_blob(self, blob, dtype=None):
assert isinstance(
blob, (str, core.BlobReference)
), "expect type str or BlobReference, but got {}".format(type(blob))
dtype = dtype or (np.float, (1, ))
dtype = dtype or (np.float64, (1, ))
self.add_metric_field(str(blob), schema.Scalar(dtype, blob))
self.ad_hoc_plot_blobs.append(blob)

Expand Down
2 changes: 1 addition & 1 deletion caffe2/python/modeling/compute_norm_for_blobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def modify_net(self, net, init_net=None, grad_map=None, blob_to_device=None,

if modify_output_record:
output_field_name = str(blob) + self._field_name_suffix
output_scalar = schema.Scalar((np.float, (1,)), norm)
output_scalar = schema.Scalar((np.float64, (1,)), norm)

if net.output_record() is None:
net.set_output_record(
Expand Down
2 changes: 1 addition & 1 deletion caffe2/python/modeling/compute_statistics_for_blobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def modify_net(self, net, init_net=None, grad_map=None, blob_to_device=None,

if modify_output_record:
output_field_name = str(blob) + self._field_name_suffix
output_scalar = schema.Scalar((np.float, (1,)), stats)
output_scalar = schema.Scalar((np.float64, (1,)), stats)

if net.output_record() is None:
net.set_output_record(
Expand Down
2 changes: 1 addition & 1 deletion caffe2/python/modeling/get_entry_from_blobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def modify_net(self, net, init_net=None, grad_map=None, blob_to_device=None,

if modify_output_record:
output_field_name = str(blob) + self._field_name_suffix
output_scalar = schema.Scalar((np.float), blob_i1_i2)
output_scalar = schema.Scalar((np.float64), blob_i1_i2)

if net.output_record() is None:
net.set_output_record(
Expand Down
2 changes: 1 addition & 1 deletion caffe2/python/operator_test/concat_op_cost_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _test_columnwise_concat_for_type(dtype):

[
_test_columnwise_concat_for_type(t)
for t in [np.int64, np.float, np.half, np.int8]
for t in [np.int64, np.float64, np.half, np.int8]
]

def test_split_then_concat(self):
Expand Down
2 changes: 1 addition & 1 deletion caffe2/python/operator_test/dropout_op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_dropout_ratio1(self, X, in_place, output_mask, engine, gc, dc):
self.assertGradientChecks(gc, op, [X], 0, [0])

def reference_dropout_ratio1(x):
return (x,) if is_test else (np.zeros(x.shape, dtype=np.float), np.zeros(x.shape, dtype=bool))
return (x,) if is_test else (np.zeros(x.shape, dtype=np.float64), np.zeros(x.shape, dtype=bool))
self.assertReferenceChecks(
gc, op, [X], reference_dropout_ratio1,
# Don't check the mask with cuDNN because it's packed data
Expand Down
66 changes: 33 additions & 33 deletions caffe2/python/operator_test/feature_maps_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_merge_dense_feature_tensors(self):
# Input 1.
workspace.FeedBlob(
"in1",
np.array([[11.1, 12.1, 13.1, 14.1], [11.2, 12.2, 13.2, 14.2]], dtype=np.float)
np.array([[11.1, 12.1, 13.1, 14.1], [11.2, 12.2, 13.2, 14.2]], dtype=np.float64)
)
workspace.FeedBlob(
"in1_presence",
Expand All @@ -42,7 +42,7 @@ def test_merge_dense_feature_tensors(self):
)
np.testing.assert_array_equal(
workspace.FetchBlob("out_values"),
np.array([11.1, 14.1, 12.2, 13.2], dtype=np.float)
np.array([11.1, 14.1, 12.2, 13.2], dtype=np.float64)
)


Expand All @@ -62,7 +62,7 @@ def test_merge_single_scalar_feature_tensors(self):
# Input 1.
workspace.FeedBlob(
"in1",
np.array([11.1, 0.0], dtype=np.float)
np.array([11.1, 0.0], dtype=np.float64)
)
workspace.FeedBlob(
"in1_presence",
Expand All @@ -71,7 +71,7 @@ def test_merge_single_scalar_feature_tensors(self):
# Input 2.
workspace.FeedBlob(
"in2",
np.array([12.1, 12.2], dtype=np.float)
np.array([12.1, 12.2], dtype=np.float64)
)
workspace.FeedBlob(
"in2_presence",
Expand All @@ -90,7 +90,7 @@ def test_merge_single_scalar_feature_tensors(self):
)
np.testing.assert_array_equal(
workspace.FetchBlob("out_values"),
np.array([11.1, 12.1, 12.2], dtype=np.float)
np.array([11.1, 12.1, 12.2], dtype=np.float64)
)

def test_merge_single_scalar_feature_tensors_gradient(self):
Expand Down Expand Up @@ -123,22 +123,22 @@ def test_merge_single_scalar_feature_tensors_gradient(self):
# Input 4.
workspace.FeedBlob(
"out_values_grad",
np.array([0.1, 1.1, 1.2, 2.3], dtype=np.float)
np.array([0.1, 1.1, 1.2, 2.3], dtype=np.float64)
)

workspace.RunOperatorOnce(op)

np.testing.assert_array_equal(
workspace.FetchBlob("in1_grad"),
np.array([0.1, 0], dtype=np.float)
np.array([0.1, 0], dtype=np.float64)
)
np.testing.assert_array_equal(
workspace.FetchBlob("in2_grad"),
np.array([1.1, 1.2], dtype=np.float)
np.array([1.1, 1.2], dtype=np.float64)
)
np.testing.assert_array_equal(
workspace.FetchBlob("in3_grad"),
np.array([0, 2.3], dtype=np.float)
np.array([0, 2.3], dtype=np.float64)
)

def test_merge_single_scalar_feature_tensors_gradient_with_strings(self):
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_merge_single_list_feature_tensors(self):
)
workspace.FeedBlob(
"in1_values",
np.array([11.1, 11.2], dtype=np.float)
np.array([11.1, 11.2], dtype=np.float64)
)
workspace.FeedBlob(
"in1_presence",
Expand All @@ -223,7 +223,7 @@ def test_merge_single_list_feature_tensors(self):
)
workspace.FeedBlob(
"in2_values",
np.array([12.1, 12.2, 12.3, 12.4], dtype=np.float)
np.array([12.1, 12.2, 12.3, 12.4], dtype=np.float64)
)
workspace.FeedBlob(
"in2_presence",
Expand All @@ -246,7 +246,7 @@ def test_merge_single_list_feature_tensors(self):
)
np.testing.assert_array_equal(
workspace.FetchBlob("out_values_values"),
np.array([11.1, 11.2, 12.1, 12.2, 12.3, 12.4], dtype=np.float)
np.array([11.1, 11.2, 12.1, 12.2, 12.3, 12.4], dtype=np.float64)
)

def test_merge_single_list_feature_tensors_gradient(self):
Expand Down Expand Up @@ -293,18 +293,18 @@ def _test_merge_single_list_or_map_feature_tensors_gradient(self, op_name):
)
workspace.FeedBlob(
"out_values_values_grad",
np.array([11.1, 11.2, 12.1, 12.2, 12.3, 12.4], dtype=np.float)
np.array([11.1, 11.2, 12.1, 12.2, 12.3, 12.4], dtype=np.float64)
)

workspace.RunOperatorOnce(op)

np.testing.assert_array_equal(
workspace.FetchBlob("in1_values_grad"),
np.array([11.1, 11.2], dtype=np.float)
np.array([11.1, 11.2], dtype=np.float64)
)
np.testing.assert_array_equal(
workspace.FetchBlob("in2_values_grad"),
np.array([12.1, 12.2, 12.3, 12.4], dtype=np.float)
np.array([12.1, 12.2, 12.3, 12.4], dtype=np.float64)
)

def test_merge_single_map_feature_tensors(self):
Expand Down Expand Up @@ -332,7 +332,7 @@ def test_merge_single_map_feature_tensors(self):
)
workspace.FeedBlob(
"in1_values",
np.array([11.1, 11.2], dtype=np.float)
np.array([11.1, 11.2], dtype=np.float64)
)
workspace.FeedBlob(
"in1_presence",
Expand All @@ -349,7 +349,7 @@ def test_merge_single_map_feature_tensors(self):
)
workspace.FeedBlob(
"in2_values",
np.array([12.1, 12.2, 12.3, 12.4], dtype=np.float)
np.array([12.1, 12.2, 12.3, 12.4], dtype=np.float64)
)
workspace.FeedBlob(
"in2_presence",
Expand All @@ -376,7 +376,7 @@ def test_merge_single_map_feature_tensors(self):
)
np.testing.assert_array_equal(
workspace.FetchBlob("out_values_values"),
np.array([11.1, 11.2, 12.1, 12.2, 12.3, 12.4], dtype=np.float)
np.array([11.1, 11.2, 12.1, 12.2, 12.3, 12.4], dtype=np.float64)
)

def test_merge_multi_scalar_feature_tensors(self):
Expand All @@ -402,7 +402,7 @@ def test_merge_multi_scalar_feature_tensors(self):
)
workspace.FeedBlob(
"in1_values",
np.array([11.0, 12.0, 13.0], dtype=np.float)
np.array([11.0, 12.0, 13.0], dtype=np.float64)
)
# Input 2.
workspace.FeedBlob(
Expand All @@ -415,7 +415,7 @@ def test_merge_multi_scalar_feature_tensors(self):
)
workspace.FeedBlob(
"in2_values",
np.array([14.0, 15.0, 16.0], dtype=np.float)
np.array([14.0, 15.0, 16.0], dtype=np.float64)
)

workspace.RunOperatorOnce(op)
Expand All @@ -430,7 +430,7 @@ def test_merge_multi_scalar_feature_tensors(self):
)
np.testing.assert_array_equal(
workspace.FetchBlob("out_values"),
np.array([11.0, 14.0, 15.0, 12.0, 13.0, 16.0], dtype=np.float)
np.array([11.0, 14.0, 15.0, 12.0, 13.0, 16.0], dtype=np.float64)
)

def test_merge_multi_scalar_feature_tensors_gradient(self):
Expand Down Expand Up @@ -460,18 +460,18 @@ def test_merge_multi_scalar_feature_tensors_gradient(self):
# Grad input.
workspace.FeedBlob(
"out_values_grad",
np.array([11.0, 14.0, 15.0, 12.0, 13.0, 16.0, 17.0], dtype=np.float)
np.array([11.0, 14.0, 15.0, 12.0, 13.0, 16.0, 17.0], dtype=np.float64)
)

workspace.RunOperatorOnce(op)

np.testing.assert_array_equal(
workspace.FetchBlob("in1_values_grad"),
np.array([11.0, 12.0, 13.0], dtype=np.float)
np.array([11.0, 12.0, 13.0], dtype=np.float64)
)
np.testing.assert_array_equal(
workspace.FetchBlob("in2_values_grad"),
np.array([14.0, 15.0, 16.0, 17.0], dtype=np.float)
np.array([14.0, 15.0, 16.0, 17.0], dtype=np.float64)
)

def test_merge_multi_list_feature_tensors(self):
Expand Down Expand Up @@ -504,7 +504,7 @@ def test_merge_multi_list_feature_tensors(self):
)
workspace.FeedBlob(
"in1_values_values",
np.array([11.1, 11.2, 12.1, 12.2, 13.1, 13.2], dtype=np.float)
np.array([11.1, 11.2, 12.1, 12.2, 13.1, 13.2], dtype=np.float64)
)
# Input 2.
workspace.FeedBlob(
Expand All @@ -521,7 +521,7 @@ def test_merge_multi_list_feature_tensors(self):
)
workspace.FeedBlob(
"in2_values_values",
np.array([14.1, 14.2, 15.1, 15.2, 16.1, 16.2], dtype=np.float)
np.array([14.1, 14.2, 15.1, 15.2, 16.1, 16.2], dtype=np.float64)
)

workspace.RunOperatorOnce(op)
Expand All @@ -545,7 +545,7 @@ def test_merge_multi_list_feature_tensors(self):
11.1, 11.2, 14.1, 14.2, 15.1, 15.2, 12.1, 12.2, 13.1, 13.2,
16.1, 16.2
],
dtype=np.float
dtype=np.float64
)
)

Expand Down Expand Up @@ -583,7 +583,7 @@ def test_merge_multi_map_feature_tensors(self):
)
workspace.FeedBlob(
"in1_values_values",
np.array([11.1, 11.2, 12.1, 12.2, 13.1, 13.2], dtype=np.float)
np.array([11.1, 11.2, 12.1, 12.2, 13.1, 13.2], dtype=np.float64)
)
# Input 2.
workspace.FeedBlob(
Expand All @@ -604,7 +604,7 @@ def test_merge_multi_map_feature_tensors(self):
)
workspace.FeedBlob(
"in2_values_values",
np.array([14.1, 14.2, 15.1, 15.2, 16.1, 16.2], dtype=np.float)
np.array([14.1, 14.2, 15.1, 15.2, 16.1, 16.2], dtype=np.float64)
)

workspace.RunOperatorOnce(op)
Expand Down Expand Up @@ -635,7 +635,7 @@ def test_merge_multi_map_feature_tensors(self):
11.1, 11.2, 14.1, 14.2, 15.1, 15.2, 12.1, 12.2, 13.1, 13.2,
16.1, 16.2
],
dtype=np.float
dtype=np.float64
)
)

Expand Down Expand Up @@ -689,17 +689,17 @@ def _test_merge_multi_list_or_map_feature_tensors_gradient(self, op_name):
11.1, 11.2, 14.1, 14.2, 15.1, 15.2, 12.1, 12.2, 13.1, 13.2,
16.1, 16.2
],
dtype=np.float
dtype=np.float64
)
)

workspace.RunOperatorOnce(op)

np.testing.assert_array_equal(
workspace.FetchBlob("in1_values_values_grad"),
np.array([11.1, 11.2, 12.1, 12.2, 13.1, 13.2], dtype=np.float)
np.array([11.1, 11.2, 12.1, 12.2, 13.1, 13.2], dtype=np.float64)
)
np.testing.assert_array_equal(
workspace.FetchBlob("in2_values_values_grad"),
np.array([14.1, 14.2, 15.1, 15.2, 16.1, 16.2], dtype=np.float)
np.array([14.1, 14.2, 15.1, 15.2, 16.1, 16.2], dtype=np.float64)
)
2 changes: 1 addition & 1 deletion caffe2/python/operator_test/self_binning_histogram_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_histogram_bin_to_two(self):
def test_histogram_min_max_equal(self):
"""This test uses exact value match, so is only relevant for float type."""
X = np.array([0., 0., 0., 0., 0.], dtype='f')
logspacing_start = np.float(1e-24)
logspacing_start = np.float64(1e-24)
self._run_single_op_net([X], 3, logspacing_start)
if self.bin_spacing == "linear":
self._check_histogram(
Expand Down
Loading

0 comments on commit 4a17693

Please sign in to comment.