From 9f4b27ed33842087ea1c2fe46e9797c88fedc144 Mon Sep 17 00:00:00 2001 From: pppp606 Date: Mon, 4 Sep 2023 14:57:55 +0900 Subject: [PATCH 1/4] Fix argument types --- src/lib/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/index.ts b/src/lib/index.ts index 4dd6004..8b5e72e 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -62,7 +62,7 @@ export function add( * Multiply arguments, element-wise. */ export function multiply( - a: ArbDimNumArray | NdArray, + a: ArbDimNumArray | NdArray | number, b: ArbDimNumArray | NdArray | number ): NdArray { return NdArray.new(a).multiply(b); @@ -72,7 +72,7 @@ export function multiply( * Divide `a` by `b`, element-wise. */ export function divide( - a: ArbDimNumArray | NdArray, + a: ArbDimNumArray | NdArray | number, b: ArbDimNumArray | NdArray | number ) { return NdArray.new(a).divide(b); From 84e7e48471051d6e2bbdfecfa993a0ba009dce85 Mon Sep 17 00:00:00 2001 From: pppp606 Date: Mon, 4 Sep 2023 14:58:26 +0900 Subject: [PATCH 2/4] Update argument types spec --- test/mocha/divide.spec.ts | 35 ++++++++++++++++++---------------- test/mocha/multiply.spec.ts | 38 ++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/test/mocha/divide.spec.ts b/test/mocha/divide.spec.ts index 747c8bd..a98b960 100644 --- a/test/mocha/divide.spec.ts +++ b/test/mocha/divide.spec.ts @@ -1,42 +1,45 @@ /* eslint-env mocha */ -'use strict'; +"use strict"; -import { expect } from 'chai'; +import { expect } from "chai"; import nj from "../../src"; -describe('divide', function () { - it('can divide a vector with a scalar and create a new copy', function () { +describe("divide", function () { + it("can divide a vector with a scalar and create a new copy", function () { const x = nj.arange(3); const scalar = 2; const newX = x.divide(scalar); expect(newX).not.to.equal(x); - expect(newX.tolist()) - .to.eql([0, 0.5, 1]); + expect(newX.tolist()).to.eql([0, 0.5, 1]); }); - it('can divide a vector with a scalar without creating a copy', function () { + it("can divide a vector with a scalar without creating a copy", function () { const x = nj.arange(3); const scalar = 2; const newX = x.divide(scalar, false); expect(newX).to.equal(x); - expect(newX.tolist()) - .to.eql([0, 0.5, 1]); + expect(newX.tolist()).to.eql([0, 0.5, 1]); }); - it('can divide two vectors', function () { + it("can divide two vectors", function () { const v = nj.ones([3]); - expect(v.divide(v).tolist()) - .to.eql(v.tolist()); + expect(v.divide(v).tolist()).to.eql(v.tolist()); }); - it('can divide two matrix with the same shape', function () { + it("can divide two matrix with the same shape", function () { const m = nj.ones(6).reshape([3, 2]); - expect(m.divide(m).tolist()) - .to.eql(m.tolist()); + expect(m.divide(m).tolist()).to.eql(m.tolist()); }); - it('should throw an error when dividing an array with a vector', function () { + it("should throw an error when dividing an array with a vector", function () { expect(function () { const x1 = nj.arange(9).reshape(3, 3); const x2 = nj.arange(3); nj.divide(x1, x2); }).to.throw(); }); + it("can set a number to the argument", function () { + const a = 2; + const b = 3; + const numberResult = nj.divide(a, b); + const arrayResult = nj.divide(nj.array([a]), nj.array([b])); + expect(numberResult).to.eql(arrayResult); + }); }); diff --git a/test/mocha/multiply.spec.ts b/test/mocha/multiply.spec.ts index a7c9a4c..634625f 100644 --- a/test/mocha/multiply.spec.ts +++ b/test/mocha/multiply.spec.ts @@ -1,47 +1,51 @@ /* eslint-env mocha */ -'use strict'; +"use strict"; -import { expect } from 'chai'; +import { expect } from "chai"; import nj from "../../src"; -describe('multiply', function () { - it('can multiply a vector with a scalar and create a new copy', function () { +describe("multiply", function () { + it("can multiply a vector with a scalar and create a new copy", function () { const x = nj.arange(3); const scalar = 2; const expected = [0, 2, 4]; const newX = x.multiply(scalar); expect(newX).not.to.equal(x); - expect(newX.tolist()) - .to.eql(expected); + expect(newX.tolist()).to.eql(expected); }); - it('can multiply a vector with a scalar without creating a copy', function () { + it("can multiply a vector with a scalar without creating a copy", function () { const x = nj.arange(3); const scalar = 2; const expected = [0, 2, 4]; const newX = x.multiply(scalar, false); expect(newX).to.equal(x); - expect(newX.tolist()) - .to.eql(expected); + expect(newX.tolist()).to.eql(expected); }); - it('can multiply two vectors', function () { + it("can multiply two vectors", function () { const v = nj.arange(3); - expect(v.multiply(v).tolist()) - .to.eql([0, 1, 4]); + expect(v.multiply(v).tolist()).to.eql([0, 1, 4]); }); - it('can multiply two matrix with the same shape', function () { + it("can multiply two matrix with the same shape", function () { const m = nj.arange(6).reshape([3, 2]); - expect(m.multiply(m).tolist()) - .to.eql([ + expect(m.multiply(m).tolist()).to.eql([ [0, 1], [4, 9], - [16, 25]]); + [16, 25], + ]); }); - it('should throw an error when multiplying an array with a vector', function () { + it("should throw an error when multiplying an array with a vector", function () { expect(function () { const x1 = nj.arange(9).reshape(3, 3); const x2 = nj.arange(3); nj.multiply(x1, x2); }).to.throw(); }); + it("can set a number to the argument", function () { + const a = 2; + const b = 3; + const numberResult = nj.multiply(a, b); + const arrayResult = nj.multiply(nj.array([a]), nj.array([b])); + expect(numberResult).to.eql(arrayResult); + }); }); From e6b1b7f87b400d913ddbde186842a46d06a0e78f Mon Sep 17 00:00:00 2001 From: pppp606 Date: Mon, 4 Sep 2023 15:17:43 +0900 Subject: [PATCH 3/4] Revert "Update argument types spec" This reverts commit 84e7e48471051d6e2bbdfecfa993a0ba009dce85. --- test/mocha/divide.spec.ts | 35 ++++++++++++++++------------------ test/mocha/multiply.spec.ts | 38 +++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/test/mocha/divide.spec.ts b/test/mocha/divide.spec.ts index a98b960..747c8bd 100644 --- a/test/mocha/divide.spec.ts +++ b/test/mocha/divide.spec.ts @@ -1,45 +1,42 @@ /* eslint-env mocha */ -"use strict"; +'use strict'; -import { expect } from "chai"; +import { expect } from 'chai'; import nj from "../../src"; -describe("divide", function () { - it("can divide a vector with a scalar and create a new copy", function () { +describe('divide', function () { + it('can divide a vector with a scalar and create a new copy', function () { const x = nj.arange(3); const scalar = 2; const newX = x.divide(scalar); expect(newX).not.to.equal(x); - expect(newX.tolist()).to.eql([0, 0.5, 1]); + expect(newX.tolist()) + .to.eql([0, 0.5, 1]); }); - it("can divide a vector with a scalar without creating a copy", function () { + it('can divide a vector with a scalar without creating a copy', function () { const x = nj.arange(3); const scalar = 2; const newX = x.divide(scalar, false); expect(newX).to.equal(x); - expect(newX.tolist()).to.eql([0, 0.5, 1]); + expect(newX.tolist()) + .to.eql([0, 0.5, 1]); }); - it("can divide two vectors", function () { + it('can divide two vectors', function () { const v = nj.ones([3]); - expect(v.divide(v).tolist()).to.eql(v.tolist()); + expect(v.divide(v).tolist()) + .to.eql(v.tolist()); }); - it("can divide two matrix with the same shape", function () { + it('can divide two matrix with the same shape', function () { const m = nj.ones(6).reshape([3, 2]); - expect(m.divide(m).tolist()).to.eql(m.tolist()); + expect(m.divide(m).tolist()) + .to.eql(m.tolist()); }); - it("should throw an error when dividing an array with a vector", function () { + it('should throw an error when dividing an array with a vector', function () { expect(function () { const x1 = nj.arange(9).reshape(3, 3); const x2 = nj.arange(3); nj.divide(x1, x2); }).to.throw(); }); - it("can set a number to the argument", function () { - const a = 2; - const b = 3; - const numberResult = nj.divide(a, b); - const arrayResult = nj.divide(nj.array([a]), nj.array([b])); - expect(numberResult).to.eql(arrayResult); - }); }); diff --git a/test/mocha/multiply.spec.ts b/test/mocha/multiply.spec.ts index 634625f..a7c9a4c 100644 --- a/test/mocha/multiply.spec.ts +++ b/test/mocha/multiply.spec.ts @@ -1,51 +1,47 @@ /* eslint-env mocha */ -"use strict"; +'use strict'; -import { expect } from "chai"; +import { expect } from 'chai'; import nj from "../../src"; -describe("multiply", function () { - it("can multiply a vector with a scalar and create a new copy", function () { +describe('multiply', function () { + it('can multiply a vector with a scalar and create a new copy', function () { const x = nj.arange(3); const scalar = 2; const expected = [0, 2, 4]; const newX = x.multiply(scalar); expect(newX).not.to.equal(x); - expect(newX.tolist()).to.eql(expected); + expect(newX.tolist()) + .to.eql(expected); }); - it("can multiply a vector with a scalar without creating a copy", function () { + it('can multiply a vector with a scalar without creating a copy', function () { const x = nj.arange(3); const scalar = 2; const expected = [0, 2, 4]; const newX = x.multiply(scalar, false); expect(newX).to.equal(x); - expect(newX.tolist()).to.eql(expected); + expect(newX.tolist()) + .to.eql(expected); }); - it("can multiply two vectors", function () { + it('can multiply two vectors', function () { const v = nj.arange(3); - expect(v.multiply(v).tolist()).to.eql([0, 1, 4]); + expect(v.multiply(v).tolist()) + .to.eql([0, 1, 4]); }); - it("can multiply two matrix with the same shape", function () { + it('can multiply two matrix with the same shape', function () { const m = nj.arange(6).reshape([3, 2]); - expect(m.multiply(m).tolist()).to.eql([ + expect(m.multiply(m).tolist()) + .to.eql([ [0, 1], [4, 9], - [16, 25], - ]); + [16, 25]]); }); - it("should throw an error when multiplying an array with a vector", function () { + it('should throw an error when multiplying an array with a vector', function () { expect(function () { const x1 = nj.arange(9).reshape(3, 3); const x2 = nj.arange(3); nj.multiply(x1, x2); }).to.throw(); }); - it("can set a number to the argument", function () { - const a = 2; - const b = 3; - const numberResult = nj.multiply(a, b); - const arrayResult = nj.multiply(nj.array([a]), nj.array([b])); - expect(numberResult).to.eql(arrayResult); - }); }); From ea97133484d1b7cd2fa56fe737694f06bebf599d Mon Sep 17 00:00:00 2001 From: pppp606 Date: Mon, 4 Sep 2023 15:21:47 +0900 Subject: [PATCH 4/4] Update Delete unnecessary differences --- test/mocha/divide.spec.ts | 7 +++++++ test/mocha/multiply.spec.ts | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/test/mocha/divide.spec.ts b/test/mocha/divide.spec.ts index 747c8bd..f5774f0 100644 --- a/test/mocha/divide.spec.ts +++ b/test/mocha/divide.spec.ts @@ -39,4 +39,11 @@ describe('divide', function () { nj.divide(x1, x2); }).to.throw(); }); + it('can set a number to the argument', function () { + const a = 2; + const b = 3; + const numberResult = nj.divide(a, b); + const arrayResult = nj.divide(nj.array([a]), nj.array([b])); + expect(numberResult).to.eql(arrayResult); + }); }); diff --git a/test/mocha/multiply.spec.ts b/test/mocha/multiply.spec.ts index a7c9a4c..d590697 100644 --- a/test/mocha/multiply.spec.ts +++ b/test/mocha/multiply.spec.ts @@ -44,4 +44,11 @@ describe('multiply', function () { nj.multiply(x1, x2); }).to.throw(); }); + it('can set a number to the argument', function () { + const a = 2; + const b = 3; + const numberResult = nj.multiply(a, b); + const arrayResult = nj.multiply(nj.array([a]), nj.array([b])); + expect(numberResult).to.eql(arrayResult); + }); });