-
Notifications
You must be signed in to change notification settings - Fork 6
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi here are my reviews. Let me know if you have any other questions. Thx.
Everything after these changes will look perfect. I think your way is faster than the mathjs way, as you dont have to copy twice and dont have to convert to Mat and back nor make a call to mathjs library. Will merge after these small issues are fixed - thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry i accidentally left these in pending changes
identity.hhs
Outdated
return new Mat([[1]]); | ||
} | ||
|
||
// Now we can start on creating the Id matrix | ||
let result = []; | ||
let result = new Mat().zeros(n, n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let result = new Mat().zeros(n, n); | |
let result = new Mat().zeros(input, input); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n not defined, i assume you meant input for this and the one below (for loops n -> input)
identity.hhs
Outdated
return new Mat([[1]]); | ||
} | ||
|
||
// Now we can start on creating the Id matrix | ||
let result = []; | ||
let result = new Mat().zeros(n, n); | ||
for (let i = 0; i < n; i++){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (let i = 0; i < n; i++){ | |
for (let i = 0; i < input; i++){ |
identity.hhs
Outdated
row[i] = 1; | ||
result += row; | ||
} | ||
result[i][i] = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result[i][i] = 1; | |
result.val[i][i] = 1; |
because we're modifying a Mat
instead of a JS array we can't access the indices directly, but rather have to access them through .val
otherwise we get a 'cannot read 0' error
@@ -16,23 +15,27 @@ function identity(input) { | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ( !(arguments.length === 1) ) { | |
throw new Error('Exception occurred in identity. Only 1 argument allowed, but a different number were entered.'); | |
} |
just a good safety check on the arguments so if the user uses the function incorrectly, they know which function they used incorrectly and why
Good job, I apologize for the late merge, I thought I merged it earlier. |
Identity Function: