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

GrowExpansion() typo? #3

Open
demic312 opened this issue Dec 11, 2021 · 6 comments
Open

GrowExpansion() typo? #3

demic312 opened this issue Dec 11, 2021 · 6 comments

Comments

@demic312
Copy link

demic312 commented Dec 11, 2021

By

for (eindex = 0; eindex < e.Length; eindex++)

did you mean

for (eindex = 0; eindex < elen; eindex++) ?

I know it's not used further. Doesn't affect anything else. I was just reading through the code to understand it better.

@thinkadd
Copy link

thinkadd commented Dec 11, 2021

You mean in here?

public static int GrowExpansion(int elen, double[] e, double b, double[] h)
{
    double Q;
    int eindex;

    Q = b;
    for (eindex = 0; eindex < e.Length; eindex++)
    {
        TwoSum(Q, e[eindex], out Q, out h[eindex]);
    }
    h[eindex] = Q;
    return eindex + 1;
}

I believe not. e is an array, e.Length is the array length. for (eindex = 0; eindex < e.Length; eindex++) basically means for each element in the array.

update: I took a look at it. Turns out this is only used in the tests, and in the caller, elen is exactly e.Length:
var n = GrowExpansion_Checked(e.Length, e, b, h);

So the two versions are logically equivalent. However, my personal preference is to just use e.Length, saving the effort of looking at the caller to find out what elen is.

@govert
Copy link
Owner

govert commented Dec 11, 2021

I suspect it is a bug.
See this assert in how it is called:

This is long ago for me, but as I remember it, e will be a kind of buffer, and elen is tracking how many elements we're actually using.

Also note the GrowLength is not used other than some tests.

// NOTE: This algorithm is not actually used further, but good for checking the S. paper.

It would be good to confirm with some test or scenario that breaks with the current code.
Also to review for similar mistakes.

However, for me this is not an active project.

@govert
Copy link
Owner

govert commented Dec 11, 2021

I do note that .Length does not appear elsewhere in that file.

@demic312
Copy link
Author

as i understand if input elen and e.Length happen to be equal then it wouldn't matter. But if, say, e was the output of a zero elim expansion then elen wouldn't be the same as e.Length

@demic312
Copy link
Author

i don't think any other methods use .Length

@demic312
Copy link
Author

i think elen is the equivalent of e.Count in a List<>. a lot of zero elim expansion operations seem to return an array that's bigger than the number of components in that expansion because the arrays are initialized before we know how many components are zero (and therefore eliminated)

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

3 participants