# Is \`.chunks\` of \`BitArray\` considered internal API?

**URL:** <https://discourse.julialang.org/t/is-chunks-of-bitarray-considered-internal-api/121416>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [October 17, 2024, 10:14am UTC](https://discourse.julialang.org/t/is-chunks-of-bitarray-considered-internal-api/121416 "2024-10-17T10:14:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 17, 2024, 10:14am UTC](https://discourse.julialang.org/t/is-chunks-of-bitarray-considered-internal-api/121416/1 "2024-10-17T10:14:09Z")

</div>

Currently I have a use case where I essentially need to pack `AbstractVector{Bool}` into the `.chunks` representation (i.e. each bit represent a bool value and “pad” to the smallest # of bytes that can accommodate the bits).

The easiest way is to just `BitVector(my_vec).chunks`, but I suppose this is technically internal. Maybe there’s a function to access the `chunks` of BitVector that is better than directly get that field?

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [October 17, 2024, 11:20am UTC](https://discourse.julialang.org/t/is-chunks-of-bitarray-considered-internal-api/121416/2 "2024-10-17T11:20:25Z")

</div>

I’d say that, yeah, it’s internal.

Tangentially related:

> <https://github.com/JuliaLang/julia/issues/16542>
>
> I'm mainly posting this to get a quick feasibility check on whether this would b…e something useful/possible/easy.
> 
> I recently came across a use-case where I'm actually getting a memory blob from another service that is essentially the \`b.chunks\` part of a BitArray, along with the length. Ideally, I'd be able to leverage something like \`pointer\_to\_bitarray(ptr, len)\` that would just wrap the existing memory.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 17, 2024, 12:10pm UTC](https://discourse.julialang.org/t/is-chunks-of-bitarray-considered-internal-api/121416/3 "2024-10-17T12:10:59Z")

</div>

I feel like chunks are de-facto public since most fast algorithms using bitarray require using them

---

<div class="post-metadata">

**Author:** ![nandoconde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nandoconde/32/19497_2.png) [@nandoconde](https://discourse.julialang.org/u/nandoconde)\
**Post date:** [October 17, 2024, 12:16pm UTC](https://discourse.julialang.org/t/is-chunks-of-bitarray-considered-internal-api/121416/4 "2024-10-17T12:16:29Z")

</div>

Yeah, but maybe again the tooling around `BitArray` should improve to provide fast operations without resorting to implementation details, right?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 17, 2024, 1:06pm UTC](https://discourse.julialang.org/t/is-chunks-of-bitarray-considered-internal-api/121416/5 "2024-10-17T13:06:56Z")

</div>

right, so maybe something public that either extracts `chunks` from `BitArray` or construct `chunks` directly would be separately useful

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [October 17, 2024, 4:05pm UTC](https://discourse.julialang.org/t/is-chunks-of-bitarray-considered-internal-api/121416/6 "2024-10-17T16:05:04Z")

</div>

Would this be a suitable role for a `reinterpret(UInt64, ::BitArray)` method? I’m quite sure that does not work now, but that seems pretty close to the target semantic. The main snag is that it loses the `length` information (padding to the next largest multiple of 64, presumably), whereas normally `reinterpret` is very diligent about ensuring and preserving that.

Another possibility would be `parent(::BitArray)`, but that might be a little too much of a pun since a `BitArray` isn’t (semantically) a wrapped array.

With those issues, these don’t really seem any better than `a.chunks`.

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [October 17, 2024, 7:54pm UTC](https://discourse.julialang.org/t/is-chunks-of-bitarray-considered-internal-api/121416/7 "2024-10-17T19:54:17Z")

</div>

maybe a good fix is to just document the `chunks` property of `BitArray` as public api? That’s what `stat` does. That seems simpler than making an accessor and declaring all existing `.chunks` invocations as non-blessed, and with property overloading there’s still some flexibility.
