Skip to content

Commit

Permalink
rewrite norm
Browse files Browse the repository at this point in the history
  • Loading branch information
rotu committed Sep 20, 2023
1 parent c0cfbf1 commit 62f6575
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,19 +803,13 @@ export class AbstractMatrix {
}

norm(type) {
if (type === undefined) type = 'frobenius';
let result = 0;
if (type === 'max') {
return this.max();
} else if (type === 'frobenius') {
for (let i = 0; i < this.rows; i++) {
for (let j = 0; j < this.columns; j++) {
result = result + this.get(i, j) * this.get(i, j);
}
}
return Math.sqrt(result);
} else {
throw new RangeError(`unknown norm type: ${type}`);
switch (type ?? 'frobenius') {
case 'max':
return this.max();
case 'frobenius':
return Math.sqrt(this.dot(this));
default:
throw new RangeError(`unknown norm type: ${type}`);

Check warning on line 812 in src/matrix.js

View check run for this annotation

Codecov / codecov/patch

src/matrix.js#L812

Added line #L812 was not covered by tests
}
}

Expand Down

0 comments on commit 62f6575

Please sign in to comment.