individual icon indicating copy to clipboard operation
individual copied to clipboard

Add bitset_count_and

Open cwhittaker1000 opened this issue 9 months ago • 2 comments

A little while ago, @giovannic kindly helped me out with an issue I was facing and developed bitset_count_and(a, b) for a case in a model we've been developing. That function takes two bitsets and returns the size of the $and. This was motivated by a desire to avoid what we'd previously been doing, which looked like this:

x$copy()$and(y)$size()

The copy was necessary as we needed to not modify x. But it became very computationally expensive as we were having to do this lots of times (lots of copying). This then became:

bitset_count_and(x, y)

which saved us a lot of computational overhead.

I'm conscious individual has moved on several versions since this was done. Would it be possible to think about merging this into main? So we can benefit from the addition of bitset_count_and() and the other updates to individual? Thanks in advance!

cwhittaker1000 avatar Mar 14 '25 15:03 cwhittaker1000

Tagging @giovannic and @plietar for visibility! :)

cwhittaker1000 avatar Mar 14 '25 15:03 cwhittaker1000

This seems reasonable. Based on a quick search there's at least a handful of occurrences of this in malariasimulation. I'll try to spin up a PR there to see if there's any measurable impact.

Not sure I love the name though. The number of set bits is typically called size, not count, so I think we should stick to that. bitset_intersection_size seems more correct to me (but is a little more verbose).

What do you think?

plietar avatar Mar 14 '25 16:03 plietar

Wanted to circle back on this @plietar and @giovannic - we’re beginning to prep the work that uses this branch for publication so would love to merge this if you think that’d be possible!

Naming it bitset_intersection_size makes sense to me Paul! Apologies for not replying before (wasn’t sure whether it was my place to weigh in on names as I’ve not been involved in package dev) - though will defer to you and Giovanni re naming - whatever you think is best is good by me!

Thanks in advance folks!

cwhittaker1000 avatar Jul 03 '25 20:07 cwhittaker1000

Gentle nudge on this - @giovannic, do you think getting this merged might be possible?

cwhittaker1000 avatar Aug 08 '25 22:08 cwhittaker1000

Thanks so much @giovannic, hugely appreciated! :)

cwhittaker1000 avatar Aug 13 '25 01:08 cwhittaker1000