nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: josdejong/mathjs
Pull request #1084 (2018-04-15 19:03:27)

Fixed decade/year, added decades, added test
Fixed problem where decades were displayed as years. Also changed problem with watt changing to W.

Added the decades alias.

Added a test to verify units' names match the keys.


Patch:
diff --git a/lib/type/unit/Unit.js b/lib/type/unit/Unit.js
index fb039ea62..ca1c851a1 100644
--- a/lib/type/unit/Unit.js
+++ b/lib/type/unit/Unit.js
@@ -2180,7 +2180,7 @@ function factory (type, config, load, typed, math) {
       offset: 0
     },
     decade: {
-      name: 'year',
+      name: 'decade',
       base: BASE_UNITS.TIME,
       prefixes: PREFIXES.NONE,
       value: 315576000, //Julian decade
@@ -2513,7 +2513,7 @@ function factory (type, config, load, typed, math) {
       offset: 0
     },
     watt: {
-      name: 'W',
+      name: 'watt',
       base: BASE_UNITS.POWER,
       prefixes: PREFIXES.LONG,
       value: 1,


Test patch:
diff --git a/test/type/unit/Unit.test.js b/test/type/unit/Unit.test.js
index fa275e965..36a6356f8 100644
--- a/test/type/unit/Unit.test.js
+++ b/test/type/unit/Unit.test.js
@@ -1096,6 +1096,12 @@ describe('Unit', function() {
       assert.equal(new Unit(1, 'ohm^-1').equals(new Unit(1, 'S'))  , true);
       assert.equal(new Unit(1, 'eV')    .equals(new Unit(1.602176565e-19, 'J')), true);
     });
+
+    it("For each built-in unit, 'name' should match key", function() {
+      for(var key in Unit.UNITS) {
+        assert.equal(key, Unit.UNITS[key].name);
+      }
+    });
   });
 
   describe('angles', function () {
Repository: josdejong/mathjs
Pull request #1098 (2018-05-02 15:03:46)

Bugix for Frobenius norm of complex matrices.
As mentioned in #1094 

The code on line 195 of `lib/function/arithmetic/norm.js` is comment with `sqrt(sum(diag(x'x)))` but this is only true for the conjugate transpose. The general formula is `sqrt(sum(sum(pow(abs(a[i,j]),2),i=1..m),j=1..n))`, the square root of the sum of the absolute values squared of the entries.

This commit makes mathjs agree with matlab, and improves the efficiency by directly summing a[i,j]' * a[i,j]. The old method was cubic (for square matrices); this method is quadratic. I also added a short test.

In mathjs 5.2.1:
```js
math.eval('norm([[3+4i]],"fro")')
{ re: 3, im: 4 }
```

In matlab:
```matlab
norm([[3+4i]],'fro')
ans =  5
```

After this commit, mathjs outputs 5.


Patch:
diff --git a/lib/function/arithmetic/norm.js b/lib/function/arithmetic/norm.js
index 227eb0fb5..b64035bbf 100644
--- a/lib/function/arithmetic/norm.js
+++ b/lib/function/arithmetic/norm.js
@@ -5,6 +5,7 @@ function factory (type, config, load, typed) {
   var abs         = load(require('../arithmetic/abs'));
   var add         = load(require('../arithmetic/add'));
   var pow         = load(require('../arithmetic/pow'));
+  var conj        = load(require('../complex/conj'));
   var sqrt        = load(require('../arithmetic/sqrt'));
   var multiply    = load(require('../arithmetic/multiply'));
   var equalScalar = load(require('../relational/equalScalar'));
@@ -192,7 +193,12 @@ function factory (type, config, load, typed) {
       }
       if (p === 'fro') {
         // norm(x) = sqrt(sum(diag(x'x)))
-        return sqrt(trace(multiply(transpose(x), x)));
+        var fro = 0;
+        x.forEach(
+          function (value, index) {
+            fro = add( fro, multiply( value, conj(value) ) );
+          });
+        return sqrt(fro);
       }
       if (p === 2) {
         // not implemented


Test patch:
diff --git a/test/function/arithmetic/norm.test.js b/test/function/arithmetic/norm.test.js
index ae8636439..1c8d5a8e9 100644
--- a/test/function/arithmetic/norm.test.js
+++ b/test/function/arithmetic/norm.test.js
@@ -29,6 +29,7 @@ describe('norm', function () {
     assert.equal(math.norm(math.complex(3, -4)), 5);
     assert.equal(math.norm(math.complex(1e200, -4e200)), 4.12310562561766e+200);
     assert.equal(math.norm(math.complex(-4e200, 1e200)), 4.12310562561766e+200);
+    assert.equal(math.norm(math.matrix([[math.complex(3, -4)]]),'fro'), 5);
   });
 
   it('should return the norm of a vector', function () {