@@ -543,4 +543,203 @@ auto count_intersections(
543543 }
544544}
545545
546+ bool are_equal (
547+ const FeatureVectorArray& a,
548+ const FeatureVectorArray& b,
549+ double epsilon = 0.0 ) {
550+ if (a.feature_type () != b.feature_type ()) {
551+ std::cout << " [feature_vector_array@are_equal] Feature types do not match: "
552+ << a.feature_type_string () << " vs " << b.feature_type_string ()
553+ << std::endl;
554+ return false ;
555+ }
556+ if (a.feature_size () != b.feature_size ()) {
557+ std::cout << " [feature_vector_array@are_equal] Feature sizes do not match: "
558+ << a.feature_size () << " vs " << b.feature_size () << std::endl;
559+ return false ;
560+ }
561+ if (a.num_vectors () != b.num_vectors ()) {
562+ std::cout
563+ << " [feature_vector_array@are_equal] Number of vectors do not match: "
564+ << a.num_vectors () << " vs " << b.num_vectors () << std::endl;
565+ return false ;
566+ }
567+ if (a.dimensions () != b.dimensions ()) {
568+ std::cout << " [feature_vector_array@are_equal] Number of dimensions do not "
569+ " match: "
570+ << a.dimensions () << " vs " << b.dimensions () << std::endl;
571+ return false ;
572+ }
573+
574+ if (a.ids_type () != b.ids_type ()) {
575+ std::cout << " [feature_vector_array@are_equal] IDs types do not match: "
576+ << a.ids_type_string () << " vs " << b.ids_type_string ()
577+ << std::endl;
578+ return false ;
579+ }
580+ if (a.ids_size () != b.ids_size ()) {
581+ std::cout << " [feature_vector_array@are_equal] IDs sizes do not match: "
582+ << a.ids_size () << " vs " << b.ids_size () << std::endl;
583+ return false ;
584+ }
585+ if (a.num_ids () != b.num_ids ()) {
586+ std::cout << " [feature_vector_array@are_equal] Number of IDs do not match: "
587+ << a.num_ids () << " vs " << b.num_ids () << std::endl;
588+ return false ;
589+ }
590+
591+ if (a.extents () != b.extents ()) {
592+ std::cout << " [feature_vector_array@are_equal] Extents do not match: "
593+ << " A: {" << a.extents ()[0 ] << " , " << a.dimensions () << " }, "
594+ << " B: {" << b.extents ()[0 ] << " , " << b.dimensions () << " }"
595+ << std::endl;
596+ return false ;
597+ }
598+
599+ // Compare the data of the feature vectors with optional epsilon
600+ auto compare_data = [&epsilon](
601+ const auto * data_a, const auto * data_b, size_t size) {
602+ if (epsilon > 0.0 ) {
603+ for (size_t i = 0 ; i < size; ++i) {
604+ if (std::abs (
605+ static_cast <double >(data_a[i]) -
606+ static_cast <double >(data_b[i])) > epsilon) {
607+ std::cout
608+ << " [feature_vector_array@are_equal] Data mismatch at index " << i
609+ << " : " << data_a[i] << " vs " << data_b[i]
610+ << " (epsilon: " << epsilon << " )" << std::endl;
611+ return false ;
612+ }
613+ }
614+ } else {
615+ for (size_t i = 0 ; i < size; ++i) {
616+ if (data_a[i] != data_b[i]) {
617+ std::cout
618+ << " [feature_vector_array@are_equal] Data mismatch at index " << i
619+ << " : " << data_a[i] << " vs " << data_b[i] << std::endl;
620+ return false ;
621+ }
622+ }
623+ }
624+ return true ;
625+ };
626+
627+ switch (a.feature_type ()) {
628+ case TILEDB_FLOAT32: {
629+ const auto * data_a = static_cast <const float *>(a.data ());
630+ const auto * data_b = static_cast <const float *>(b.data ());
631+ if (!compare_data (data_a, data_b, a.num_vectors () * a.dimensions ())) {
632+ std::cout << " [feature_vector_array@are_equal] Feature vector data "
633+ " comparison failed for type FLOAT32"
634+ << std::endl;
635+ return false ;
636+ }
637+ break ;
638+ }
639+ case TILEDB_INT8: {
640+ const auto * data_a = static_cast <const int8_t *>(a.data ());
641+ const auto * data_b = static_cast <const int8_t *>(b.data ());
642+ if (!compare_data (data_a, data_b, a.num_vectors () * a.dimensions ())) {
643+ std::cout << " [feature_vector_array@are_equal] Feature vector data "
644+ " comparison failed for type INT8"
645+ << std::endl;
646+ return false ;
647+ }
648+ break ;
649+ }
650+ case TILEDB_UINT8: {
651+ const auto * data_a = static_cast <const uint8_t *>(a.data ());
652+ const auto * data_b = static_cast <const uint8_t *>(b.data ());
653+ if (!compare_data (data_a, data_b, a.num_vectors () * a.dimensions ())) {
654+ std::cout << " [feature_vector_array@are_equal] Feature vector data "
655+ " comparison failed for type UINT8"
656+ << std::endl;
657+ return false ;
658+ }
659+ break ;
660+ }
661+ case TILEDB_INT32: {
662+ const auto * data_a = static_cast <const int32_t *>(a.data ());
663+ const auto * data_b = static_cast <const int32_t *>(b.data ());
664+ if (!compare_data (data_a, data_b, a.num_vectors () * a.dimensions ())) {
665+ std::cout << " [feature_vector_array@are_equal] Feature vector data "
666+ " comparison failed for type INT32"
667+ << std::endl;
668+ return false ;
669+ }
670+ break ;
671+ }
672+ case TILEDB_UINT32: {
673+ const auto * data_a = static_cast <const uint32_t *>(a.data ());
674+ const auto * data_b = static_cast <const uint32_t *>(b.data ());
675+ if (!compare_data (data_a, data_b, a.num_vectors () * a.dimensions ())) {
676+ std::cout << " [feature_vector_array@are_equal] Feature vector data "
677+ " comparison failed for type UINT32"
678+ << std::endl;
679+ return false ;
680+ }
681+ break ;
682+ }
683+ case TILEDB_INT64: {
684+ const auto * data_a = static_cast <const int64_t *>(a.data ());
685+ const auto * data_b = static_cast <const int64_t *>(b.data ());
686+ if (!compare_data (data_a, data_b, a.num_vectors () * a.dimensions ())) {
687+ std::cout << " [feature_vector_array@are_equal] Feature vector data "
688+ " comparison failed for type INT64"
689+ << std::endl;
690+ return false ;
691+ }
692+ break ;
693+ }
694+ case TILEDB_UINT64: {
695+ const auto * data_a = static_cast <const uint64_t *>(a.data ());
696+ const auto * data_b = static_cast <const uint64_t *>(b.data ());
697+ if (!compare_data (data_a, data_b, a.num_vectors () * a.dimensions ())) {
698+ std::cout << " [feature_vector_array@are_equal] Feature vector data "
699+ " comparison failed for type UINT64"
700+ << std::endl;
701+ return false ;
702+ }
703+ break ;
704+ }
705+ default :
706+ std::cout << " [feature_vector_array@are_equal] Unsupported feature "
707+ " vector attribute type"
708+ << std::endl;
709+ throw std::runtime_error (" Unsupported attribute type" );
710+ }
711+
712+ // If the arrays have IDs, compare the IDs as well
713+ if (a.ids_type () != TILEDB_ANY && b.ids_type () != TILEDB_ANY) {
714+ switch (a.ids_type ()) {
715+ case TILEDB_UINT32: {
716+ const auto * ids_a = static_cast <const uint32_t *>(a.ids ());
717+ const auto * ids_b = static_cast <const uint32_t *>(b.ids ());
718+ if (!compare_data (ids_a, ids_b, a.num_ids ())) {
719+ std::cout << " [feature_vector_array@are_equal] ID comparison failed "
720+ " for type UINT32"
721+ << std::endl;
722+ return false ;
723+ }
724+ break ;
725+ }
726+ case TILEDB_UINT64: {
727+ const auto * ids_a = static_cast <const uint64_t *>(a.ids ());
728+ const auto * ids_b = static_cast <const uint64_t *>(b.ids ());
729+ if (!compare_data (ids_a, ids_b, a.num_ids ())) {
730+ std::cout << " [feature_vector_array@are_equal] ID comparison failed "
731+ " for type UINT64"
732+ << std::endl;
733+ return false ;
734+ }
735+ break ;
736+ }
737+ default :
738+ throw std::runtime_error (" Unsupported ID type" );
739+ }
740+ }
741+
742+ return true ;
743+ }
744+
546745#endif // TILEDB_API_FEATURE_VECTOR_ARRAY_H
0 commit comments