MCPcopy Create free account
hub / github.com/apache/tvm-ffi / CompareTensor

Method CompareTensor

src/ffi/extra/structural_equal.cc:390–408  ·  view source on GitHub ↗

NOLINTNEXTLINE(performance-unnecessary-value-param)

Source from the content-addressed store, hash-verified

388
389 // NOLINTNEXTLINE(performance-unnecessary-value-param)
390 bool CompareTensor(Tensor lhs, Tensor rhs) {
391 if (lhs.same_as(rhs)) return true;
392 if (lhs.ndim() != rhs.ndim()) return false;
393 for (int i = 0; i < lhs.ndim(); ++i) {
394 if (lhs.size(i) != rhs.size(i)) return false;
395 }
396
397 if (lhs.dtype() != rhs.dtype()) return false;
398 if (!skip_tensor_content_) {
399 TVM_FFI_ICHECK_EQ(lhs.device().device_type, kDLCPU) << "can only compare CPU tensor";
400 TVM_FFI_ICHECK_EQ(rhs.device().device_type, kDLCPU) << "can only compare CPU tensor";
401 TVM_FFI_ICHECK(lhs.IsContiguous()) << "Can only compare contiguous tensor";
402 TVM_FFI_ICHECK(rhs.IsContiguous()) << "Can only compare contiguous tensor";
403 size_t data_size = GetDataSize(lhs);
404 return std::memcmp(lhs.data_ptr(), rhs.data_ptr(), data_size) == 0;
405 } else {
406 return true;
407 }
408 }
409
410 Any MapLhsToRhs(Any lhs) const {
411 if (lhs.type_index() < TypeIndex::kTVMFFIStaticObjectBegin) {

Callers

nothing calls this directly

Calls 8

GetDataSizeFunction · 0.85
same_asMethod · 0.45
ndimMethod · 0.45
sizeMethod · 0.45
dtypeMethod · 0.45
deviceMethod · 0.45
IsContiguousMethod · 0.45
data_ptrMethod · 0.45

Tested by

no test coverage detected