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

Dev igd #9

Open
wants to merge 88 commits into
base: dev
Choose a base branch
from
Open

Dev igd #9

wants to merge 88 commits into from

Conversation

donaldcampbelljr
Copy link
Member

This is a draft to aid in discussing work done to convert our IGD tool from C to Rust:

https://github.com/databio/IGD
https://doi.org/10.1093/bioinformatics/btaa1062

Copy link
Member

@nleroy917 nleroy917 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrote down some thoughts, but this is awesome!

use crate::vocab::consts;


pub const maxCount: i64 = 268435456; //16* = 4GB memory // original code had this as i32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about a u32? RAM can never be negative, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we should be able to just use u32 instead.

genimtools/src/igd/create.rs Outdated Show resolved Hide resolved
genimtools/src/igd/create.rs Outdated Show resolved Hide resolved
genimtools/src/igd/create.rs Outdated Show resolved Hide resolved
genimtools/src/igd/create.rs Outdated Show resolved Hide resolved
genimtools/src/igd/create.rs Outdated Show resolved Hide resolved
genimtools/src/igd/create.rs Outdated Show resolved Hide resolved
genimtools/src/igd/create.rs Outdated Show resolved Hide resolved
// og C code:
// int32_t *nr = calloc(n_files, sizeof(int32_t));
// double *avg = calloc(n_files, sizeof(double));
let mut avg: Vec<i32> = Vec::with_capacity(n_files);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious - whats the difference between a Vec::with_capacity and array? Is an array only useful when you know the size at compile time?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually discussed this (partially) yesterday! I ended up having to use the vec! macro in some instances because Vec::with_capacity was not creating vectors of desired lengths. It was simply allocating memory for how large the vector is expected to be come at run time:

The capacity of a vector is the amount of space allocated for any future elements that will be added onto the vector. This is not to be confused with the length of a vector, which specifies the number of actual elements within the vector. If a vector's length exceeds its capacity, its capacity will automatically be increased, but its elements will have to be reallocated.

For example, a vector with capacity 10 and length 0 would be an empty vector with space for 10 more elements. Pushing 10 or fewer elements onto the vector will not change its capacity or cause reallocation to occur. However, if the vector's length is increased to 11, it will have to reallocate, which can be slow. For this reason, it is recommended to use Vec::with_capacity whenever possible to specify how big the vector is expected to get.

link to info

genimtools/src/igd/create.rs Outdated Show resolved Hide resolved
@donaldcampbelljr donaldcampbelljr marked this pull request as ready for review March 15, 2024 13:32
@donaldcampbelljr
Copy link
Member Author

Works toward: #28

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

Successfully merging this pull request may close these issues.

2 participants