Skip to content
This repository was archived by the owner on Aug 17, 2024. It is now read-only.

Commit f0bcd7e

Browse files
committed
Merge branch 'hotfix/moduleupdate' into develop
2 parents 1de263f + ef6dece commit f0bcd7e

File tree

4 files changed

+28
-57
lines changed

4 files changed

+28
-57
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ const df2 = df.withColumn('column4', (row) => row.get('column2') * 2)
233233
df.fakemodule.test(8)
234234
```
235235

236+
If you want to change default modules (modules enabled in each DataFrame instance, such as Matrix and Stat) you can define them by a static method:
237+
238+
```javascript
239+
DataFrame.setDefaultModules(fakeModule, Matrix);
240+
```
241+
236242
If you want to create your own module, take a look at the Statisticical module (integrated by default) `./src/modules/stat.js` as example.
237243

238244
A simple example of a module structure:
@@ -254,8 +260,7 @@ class fakeModule {
254260

255261
* [Matrix](./doc/MODULES_API.md#Matrix)
256262
* [new Matrix(dataframe)](./doc/MODULES_API.md#new_Matrix_new)
257-
* [.hasSameStruct(df)](./doc/MODULES_API.md#Matrix+hasSameStruct) ⇒ <code>Boolean</code>
258-
* [.hasSameTransposedStruct(df)](./doc/MODULES_API.md#Matrix+hasSameTransposedStruct) ⇒ <code>Boolean</code>
263+
* [.isCommutative(dfDim)](./doc/MODULES_API.md#Matrix+isCommutative) ⇒ <code>Boolean</code>
259264
* [.add(df)](./doc/MODULES_API.md#Matrix+add) ⇒ <code>DataFrame</code>
260265
* [.product(number)](./doc/MODULES_API.md#Matrix+product) ⇒ <code>DataFrame</code>
261266
* [.dot(df)](./doc/MODULES_API.md#Matrix+dot) ⇒ <code>DataFrame</code>

doc/MODULES_API.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ Matrix module for DataFrame, providing basic mathematical matrix computations.
1818

1919
* [Matrix](#Matrix)
2020
* [new Matrix(df)](#new_Matrix_new)
21-
* [.hasSameStruct(df)](#Matrix+hasSameStruct) ⇒ <code>Boolean</code>
22-
* [.hasSameTransposedStruct(df)](#Matrix+hasSameTransposedStruct) ⇒ <code>Boolean</code>
21+
* [.isCommutative(dfDim)](#Matrix+isCommutative) ⇒ <code>Boolean</code>
2322
* [.add(df)](#Matrix+add) ⇒ <code>DataFrame</code>
2423
* [.product(number)](#Matrix+product) ⇒ <code>DataFrame</code>
2524
* [.dot(df)](#Matrix+dot) ⇒ <code>DataFrame</code>
@@ -34,34 +33,22 @@ Start the Matrix module.
3433
| --- | --- | --- |
3534
| df | <code>DataFrame</code> | An instance of DataFrame. |
3635

37-
<a name="Matrix+hasSameStruct"></a>
36+
<a name="Matrix+isCommutative"></a>
3837

39-
### matrix.hasSameStruct(df) ⇒ <code>Boolean</code>
38+
### matrix.isCommutative(dfDim) ⇒ <code>Boolean</code>
4039
Check if two DataFrames are commutative, if both have the same dimensions.
4140

4241
**Kind**: instance method of <code>[Matrix](#Matrix)</code>
4342
**Returns**: <code>Boolean</code> - True if they are commutative, else false.
4443

4544
| Param | Type | Description |
4645
| --- | --- | --- |
47-
| df | <code>DataFrame</code> | The second DataFrame to check. |
48-
49-
<a name="Matrix+hasSameTransposedStruct"></a>
50-
51-
### matrix.hasSameTransposedStruct(df) ⇒ <code>Boolean</code>
52-
Check if two DataFrames have the same dimensions while the second is transposed. Required for dot().
53-
54-
**Kind**: instance method of <code>[Matrix](#Matrix)</code>
55-
**Returns**: <code>Boolean</code> - True if they can be multiplied, else false.
56-
57-
| Param | Type | Description |
58-
| --- | --- | --- |
59-
| df | <code>DataFrame</code> | The second DataFrame to check. |
46+
| dfDim | <code>Array</code> | The second DataFrame dim to check. |
6047

6148
<a name="Matrix+add"></a>
6249

6350
### matrix.add(df) ⇒ <code>DataFrame</code>
64-
Provide an elements pairwise addition of two DataFrames having the same dimensions. See .hasSameStruct().
51+
Provide an elements pairwise addition of two DataFrames having the same dimensions.
6552

6653
**Kind**: instance method of <code>[Matrix](#Matrix)</code>
6754
**Returns**: <code>DataFrame</code> - A new DataFrame resulting to the addition two DataFrames.
@@ -85,7 +72,7 @@ Provide a scalar product between a number and a DataFrame.
8572
<a name="Matrix+dot"></a>
8673

8774
### matrix.dot(df) ⇒ <code>DataFrame</code>
88-
Multiply one DataFrame n x p and a second p x n. See .hasSameTransposedStruct().
75+
Multiply one DataFrame n x p and a second p x n.
8976

9077
**Kind**: instance method of <code>[Matrix](#Matrix)</code>
9178
**Returns**: <code>DataFrame</code> - A new n x n DataFrame resulting to the product of two DataFrame.

lib/modules/matrix.js

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,19 @@ var Matrix = function () {
4545

4646
/**
4747
* Check if two DataFrames are commutative, if both have the same dimensions.
48-
* @param {DataFrame} df The second DataFrame to check.
48+
* @param {Array} dfDim The second DataFrame dim to check.
4949
* @returns {Boolean} True if they are commutative, else false.
5050
*/
5151

5252

5353
(0, _createClass3.default)(Matrix, [{
54-
key: 'hasSameStruct',
55-
value: function hasSameStruct(df) {
56-
return (0, _reusables.arrayEqual)(this.df.dim(), df.dim(), true);
54+
key: 'isCommutative',
55+
value: function isCommutative(dfDim) {
56+
return (0, _reusables.arrayEqual)(this.df.dim(), dfDim, true);
5757
}
5858

5959
/**
60-
* Check if two DataFrames have the same dimensions while the second is transposed. Required for dot().
61-
* @param {DataFrame} df The second DataFrame to check.
62-
* @returns {Boolean} True if they can be multiplied, else false.
63-
*/
64-
65-
}, {
66-
key: 'hasSameTransposedStruct',
67-
value: function hasSameTransposedStruct(df) {
68-
return (0, _reusables.arrayEqual)(this.df.dim(), df.dim().reverse(), true);
69-
}
70-
71-
/**
72-
* Provide an elements pairwise addition of two DataFrames having the same dimensions. See .hasSameStruct().
60+
* Provide an elements pairwise addition of two DataFrames having the same dimensions.
7361
* @param {DataFrame} df The second DataFrame to add.
7462
* @returns {DataFrame} A new DataFrame resulting to the addition two DataFrames.
7563
*/
@@ -79,7 +67,7 @@ var Matrix = function () {
7967
value: function add(df) {
8068
var _this = this;
8169

82-
if (!this.hasSameStruct(df)) {
70+
if (!this.isCommutative(df.dim())) {
8371
throw new _errors.WrongMatrixStructureError(this.df.dim(), df.dim());
8472
}
8573
var columns = [].concat((0, _toConsumableArray3.default)(Array(this.df.dim()[1]).keys()));
@@ -109,7 +97,7 @@ var Matrix = function () {
10997
}
11098

11199
/**
112-
* Multiply one DataFrame n x p and a second p x n. See .hasSameTransposedStruct().
100+
* Multiply one DataFrame n x p and a second p x n.
113101
* @param {DataFrame} df The second DataFrame to multiply.
114102
* @returns {DataFrame} A new n x n DataFrame resulting to the product of two DataFrame.
115103
*/
@@ -119,7 +107,7 @@ var Matrix = function () {
119107
value: function dot(df) {
120108
var _this2 = this;
121109

122-
if (!this.hasSameTransposedStruct(df)) {
110+
if (!this.isCommutative(df.dim().reverse())) {
123111
throw new _errors.WrongMatrixStructureError(this.df.dim(), df.dim().reverse());
124112
}
125113
var transposedDF = df.transpose();

src/modules/matrix.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,20 @@ class Matrix {
1616

1717
/**
1818
* Check if two DataFrames are commutative, if both have the same dimensions.
19-
* @param {DataFrame} df The second DataFrame to check.
19+
* @param {Array} dfDim The second DataFrame dim to check.
2020
* @returns {Boolean} True if they are commutative, else false.
2121
*/
22-
hasSameStruct(df) {
23-
return arrayEqual(this.df.dim(), df.dim(), true);
22+
isCommutative(dfDim) {
23+
return arrayEqual(this.df.dim(), dfDim, true);
2424
}
2525

2626
/**
27-
* Check if two DataFrames have the same dimensions while the second is transposed. Required for dot().
28-
* @param {DataFrame} df The second DataFrame to check.
29-
* @returns {Boolean} True if they can be multiplied, else false.
30-
*/
31-
hasSameTransposedStruct(df) {
32-
return arrayEqual(this.df.dim(), df.dim().reverse(), true);
33-
}
34-
35-
/**
36-
* Provide an elements pairwise addition of two DataFrames having the same dimensions. See .hasSameStruct().
27+
* Provide an elements pairwise addition of two DataFrames having the same dimensions.
3728
* @param {DataFrame} df The second DataFrame to add.
3829
* @returns {DataFrame} A new DataFrame resulting to the addition two DataFrames.
3930
*/
4031
add(df) {
41-
if (!this.hasSameStruct(df)) {
32+
if (!this.isCommutative(df.dim())) {
4233
throw new WrongMatrixStructureError(this.df.dim(), df.dim());
4334
}
4435
const columns = [...Array(this.df.dim()[1]).keys()];
@@ -62,12 +53,12 @@ class Matrix {
6253
}
6354

6455
/**
65-
* Multiply one DataFrame n x p and a second p x n. See .hasSameTransposedStruct().
56+
* Multiply one DataFrame n x p and a second p x n.
6657
* @param {DataFrame} df The second DataFrame to multiply.
6758
* @returns {DataFrame} A new n x n DataFrame resulting to the product of two DataFrame.
6859
*/
6960
dot(df) {
70-
if (!this.hasSameTransposedStruct(df)) {
61+
if (!this.isCommutative(df.dim().reverse())) {
7162
throw new WrongMatrixStructureError(this.df.dim(), df.dim().reverse());
7263
}
7364
const transposedDF = df.transpose();

0 commit comments

Comments
 (0)