MCPcopy Create free account
hub / github.com/apache/arrow / StridedFloatTensorContentEquals

Function StridedFloatTensorContentEquals

cpp/src/arrow/compare.cc:1248–1292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1246
1247template <typename DataType>
1248bool StridedFloatTensorContentEquals(const int dim_index, int64_t left_offset,
1249 int64_t right_offset, const Tensor& left,
1250 const Tensor& right, const EqualOptions& opts) {
1251 using c_type = typename DataType::c_type;
1252 static_assert(std::is_floating_point<c_type>::value,
1253 "DataType must be a floating point type");
1254
1255 const auto n = left.shape()[dim_index];
1256 const auto left_stride = left.strides()[dim_index];
1257 const auto right_stride = right.strides()[dim_index];
1258 if (dim_index == left.ndim() - 1) {
1259 // Leaf dimension, compare values
1260 auto left_data = left.raw_data();
1261 auto right_data = right.raw_data();
1262 bool result = true;
1263
1264 auto visitor = [&](auto&& compare_func) {
1265 for (int64_t i = 0; i < n; ++i) {
1266 c_type left_value =
1267 *reinterpret_cast<const c_type*>(left_data + left_offset + i * left_stride);
1268 c_type right_value = *reinterpret_cast<const c_type*>(right_data + right_offset +
1269 i * right_stride);
1270 if (!compare_func(left_value, right_value)) {
1271 result = false;
1272 return;
1273 }
1274 }
1275 };
1276
1277 VisitFloatingEquality<c_type>(opts, /*floating_approximate=*/false,
1278 std::move(visitor));
1279 return result;
1280 }
1281
1282 // Outer dimension, recurse into inner
1283 for (int64_t i = 0; i < n; ++i) {
1284 if (!StridedFloatTensorContentEquals<DataType>(dim_index + 1, left_offset,
1285 right_offset, left, right, opts)) {
1286 return false;
1287 }
1288 left_offset += left_stride;
1289 right_offset += right_stride;
1290 }
1291 return true;
1292}
1293
1294template <typename DataType>
1295bool FloatTensorEquals(const Tensor& left, const Tensor& right,

Callers

nothing calls this directly

Calls 3

stridesMethod · 0.80
raw_dataMethod · 0.80
shapeMethod · 0.45

Tested by

no test coverage detected