halotools.utils.calculate_entry_multiplicity(sorted_repeated_hostids, unique_possible_hostids, testing_mode=False)[source]

Given an array of possible hostids, and a sorted array of (possibly repeated) hostids, return the number of appearances of each hostid.

This function can serve as the kernel, for example, for the calculation of the number of subhalos in each host halo.


Length-num_entries integer array storing a collection of hostids.

The entries of sorted_repeated_hostids may be repeated, but must be in ascending order. Each entry of sorted_repeated_hostids must appear in the unique_possible_hostids.

For halo analysis applications, this would be the halo_hostid column of some set of subhalos.


Length-num_hostids integer array storing the set of all available values for hostid.

All entries must be unique. An entry of unique_possible_hostids need not necessarily appear in sorted_repeated_hostids. The unique_possible_hostids array can be sorted in any order.

For halo analysis applications, this would be the halo_id column of the complete set of host halos.

testing_modebool, optional

Boolean specifying whether input arrays will be tested to see if they satisfy the assumptions required by the algorithm. Setting testing_mode to True is useful for unit-testing purposes, while setting it to False improves performance. Default is False. If this function raises an unexpected exception, try setting testing_mode to True to identify which specific assumption about the inputs is not being met.


Length-num_hostids integer array storing the number of times each entry of unique_possible_hostids appears in sorted_repeated_hostids.


>>> sorted_repeated_hostids = np.array((1, 1, 2, 2, 2, 4, 5, 6, 6))
>>> unique_possible_hostids = np.arange(7)
>>> entry_multiplicity = calculate_entry_multiplicity(sorted_repeated_hostids, unique_possible_hostids)
>>> assert np.all(entry_multiplicity == (0, 2, 3, 0, 1, 1, 2))