Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create bit integers in a loop? How to avoid additional allocations? #45

Open
lampretl opened this issue Jun 16, 2024 · 1 comment

Comments

@lampretl
Copy link

lampretl commented Jun 16, 2024

I'd like to create all BitIntegers of byte length up to 1024. I don't want to write 1024 lines of code for that, so I'm trying to use a loop. Running the following code gives an error:

for k=8:8:1024  k∈(8,16,32,64,128) && continue;  
    @eval BitIntegers.@define_integers $k Int$k UInt$k end

ERROR: syntax: invalid type signature around /home/user/.julia/packages/BitIntegers/VJRl1/src/BitIntegers.jl:62
Stacktrace:
 [1] top-level scope
   @ none:1
 [2] eval(m::Module, e::Any)
   @ Core ./boot.jl:370
 [3] top-level scope
   @ REPL[11]:2

Running the code below works but does not create my UInt's in the global scope:

for k=8:8:1024  k∈(8,16,32,64,128) && continue; 
    eval("BitIntegers.@define_integers $k Int$k UInt$k;") end

julia> UInt24
ERROR: UndefVarError: `UInt24` not defined

Is there a workaround for doing this?

Also, an unrelated question: If I create Matrix{Int128} and do row and column operations on it (like Smith normal form), that will cause no additional allocations. However, on Matrix{Int1024} there are many additional allocations. Is there a way to avoid this? Are your BitIntegers still converting internally to BigInts? If so, then what is the purpose of BitIntegers, what advantage do they offer compared to just using BigInts from the start?

Theoretically, would it be possible to refactor this package in a way that BitIntegers would behave more like Int64 and Int128 with regard to allocations? Or is the inherent nature of CPUs and RAMs such that this is impossible? (I noticed there are no integers of custom byte sizes in rust, go, ..., so I was wondering...)

@lampretl
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant