Skip to content

Multiple mistakes appeared in the code while I was trying to refactor it and enforce type checking. Can someone just answer those questions? #337

Open
@Sharcoux

Description

@Sharcoux

Ok, here are the list of problems I noticed in the code:

  • Code duplication
  • Dead code
  • Type confusions
  • Logic differences between some of the duplicates
  • Some broken logic
  • @ts-check annotation could have saved lives
  • Generated files are being tracked by git

I'm trying to solve all of that, but I need some help with the following issues I'm not sure about how to solve:

1st problem

y[i] = [y[i]];

y[i] = [y[i]]: this will transform a number[][] array into a number[][][] array. I would be surprised if that was intentional, provided the comment above. My guess is that the intended code was:

const line = y[0]
for (let i = 0; i<y.length; i++) {
  y[i] = [line[i]]
}

2nd problem

var y = sub(z, mult(this.H, X_p)); // This is the measurement error (between what we expect and the actual value)

z is supposed to be of type number[] while the sub method expects a parameter of type number[][]. In another file, I noticed the exact same code with that single difference: there was that extra line before:

    const transposedZ = transpose([z])
    const y = sub(transposedZ, mult(this.H, xP)) // This is the measurement error (between what we expect and the actual value)

I guess that this is the correct version?

3rd problem

m_Coefficients[i] = solution[i];

mCoefficients[i] = solution[i]: mCoefficients is of type number[] but solution is of type number[][]. I have no idea how this is supposed to be solved. Should I just take solution[i][i]?

4th problem

if (m_Coefficients.length*n !== m_Coefficients.length){

if (mCoefficients.length * n !== mCoefficients.length): This can only be true if n === 1. Is it what we want to test instead?

Anyway, the line above that define the value of n is completely stupid: const n = (mCoefficients.length !== 0 ? mCoefficients.length / mCoefficients.length : 0)

This is equivalent to mCoefficients.length ? 1 : 0. In short, those 2 lines could be simplified with if(mCoefficients.length). However, there is absolutely no relation with Array length being a multiple of m...

5th problem

var H = [ [1, 0, 0, 0, 0, 0],

H is being declared twice. Which one is the correct value?

6th problem

x += smoothingVals.get(d).x;

d is of type string. This will lead to really problematic consequences in the get and getTrueIndex methods

7th problem

init(debugVideoLoc);

debugVideoLoc has to be a MediaStream, because we call getTracks() on it. But it is a string, here...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions