MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / compare_value

Method compare_value

imperative/python/src/tensor.cpp:1233–1249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1231 std::unordered_map<size_t, size_t> outmark_to_id;
1232
1233 bool compare_value(ValueRef lhs, ValueRef rhs) {
1234 auto lvalue = lhs.cast_ref<HostValue>();
1235 auto rvalue = rhs.cast_ref<HostValue>();
1236 if (lvalue->shape() != rvalue->shape()) {
1237 return false;
1238 }
1239 if (lvalue->shape().total_nr_elems() == 1) {
1240 return lvalue->item() == rvalue->item();
1241 }
1242 HostTensorND lnd = lvalue->as_nd(true);
1243 HostTensorND rnd = rvalue->as_nd(true);
1244 auto larr = py::reinterpret_steal<py::array>(
1245 npy::ndarray_from_tensor(lnd, npy::ShareType::TRY_SHARE));
1246 auto rarr = py::reinterpret_steal<py::array>(
1247 npy::ndarray_from_tensor(rnd, npy::ShareType::TRY_SHARE));
1248 return array_comparator(larr, rarr);
1249 }
1250
1251 void mark_input(size_t mark, size_t id) {
1252 trace_result->vars[id].inp_marker.insert(mark);

Callers

nothing calls this directly

Calls 6

ndarray_from_tensorFunction · 0.85
array_comparatorFunction · 0.85
as_ndMethod · 0.80
shapeMethod · 0.45
total_nr_elemsMethod · 0.45
itemMethod · 0.45

Tested by

no test coverage detected