# How do cross-matching algorithms deal with unequal-sized catalogues?

Let's say I'm using a service like TOPCAT or Vizier's cross-matching service and I'm trying to match the RA and dec of the sources in Catalogue 1, with 100,000 sources, to those in Catalogue 2, with a million sources.

How does the algorithm deal with the difference in size when it gets to the end of the shortest catalogue? Does it loop around? Or am I making an incorrect assumption about how cross-matching works?

This question comes from my attempts at making my own algorithm using astropy's SkyCoord function; it won't let me broadcast together two differently-sized arrays.

• This sounds like a basic database command question. Depending on what you really want to do, the answer could be as simple as a double loop, or a matrix operation on an array of size 1E5 by 1E6 . Commented Sep 20, 2022 at 15:03

Leaving aside the technicalities of different algorithms for speeding up the matches,[*] the basic idea is that you are trying to find e.g. sources in Catalog 2 that are plausible matches to sources in Catalog 1 (e.g., located within $$d$$ arc seconds). The simplest (albeit computationally inefficient) method is to step through every source in Catalog 1, checking (all of) Catalog 2 for possible matches. When you get to the end of Catalog 1, you're done. "Looping around" would mean repeating all of the same calculations and tests you just did, which would be a complete waste of time.
[*] A simplistic example: pre-sort and index Catalog 2 by one of the coordinates (e.g., Right Ascension). Then, for a given source in Catalog 1, you only need to test sources from Catalog 2 that have RA within $$\pm d$$ arc seconds of the Catalog 1 source. (Most of these sources will be too far away in the other coordinate to end up being matches, but you know all the sources with $$\Delta$$RA $$> d$$ can't possibly be matches, so there's no need to waste time testing them.)