| 1375 | } |
| 1376 | |
| 1377 | bool LiteralBase::Piece::EqualElements(const LiteralBase::Piece& other) const { |
| 1378 | DCHECK(ShapeUtil::Compatible(subshape(), other.subshape())); |
| 1379 | |
| 1380 | if (ShapeUtil::Equal(subshape(), other.subshape()) && |
| 1381 | LayoutUtil::IsDenseArray(subshape())) { |
| 1382 | CHECK_EQ(size_bytes(), other.size_bytes()); |
| 1383 | return memcmp(buffer(), other.buffer(), size_bytes()) == 0; |
| 1384 | } |
| 1385 | |
| 1386 | std::vector<int64> multi_index; |
| 1387 | switch (subshape().element_type()) { |
| 1388 | case PRED: |
| 1389 | return EqualElementsInternal<bool>(other, &multi_index); |
| 1390 | case U8: |
| 1391 | return EqualElementsInternal<uint8>(other, &multi_index); |
| 1392 | case S16: |
| 1393 | return EqualElementsInternal<int16>(other, &multi_index); |
| 1394 | case S32: |
| 1395 | return EqualElementsInternal<int32>(other, &multi_index); |
| 1396 | case S64: |
| 1397 | return EqualElementsInternal<int64>(other, &multi_index); |
| 1398 | case U16: |
| 1399 | return EqualElementsInternal<uint16>(other, &multi_index); |
| 1400 | case U32: |
| 1401 | return EqualElementsInternal<uint32>(other, &multi_index); |
| 1402 | case U64: |
| 1403 | return EqualElementsInternal<uint64>(other, &multi_index); |
| 1404 | case F32: |
| 1405 | return EqualElementsInternal<float>(other, &multi_index); |
| 1406 | case F64: |
| 1407 | return EqualElementsInternal<double>(other, &multi_index); |
| 1408 | case F16: |
| 1409 | return EqualElementsInternal<half>(other, &multi_index); |
| 1410 | case BF16: |
| 1411 | return EqualElementsInternal<bfloat16>(other, &multi_index); |
| 1412 | case C64: |
| 1413 | return EqualElementsInternal<complex64>(other, &multi_index); |
| 1414 | case C128: |
| 1415 | return EqualElementsInternal<complex128>(other, &multi_index); |
| 1416 | default: |
| 1417 | LOG(FATAL) << "Unimplemented: LiteralBase::Piece::EqualElements for type " |
| 1418 | << PrimitiveType_Name(subshape().element_type()); |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | bool LiteralBase::operator==(const LiteralBase& other) const { |
| 1423 | if (!ShapeUtil::Compatible(shape(), other.shape())) { |
no test coverage detected