1 | <a name="DenseMatrix"></a>
|
2 | ## DenseMatrix
|
3 | Dense Matrix implementation. This type implements an efficient Array format
|
4 | for dense matrices.
|
5 |
|
6 | * _instance_
|
7 | * [.storage()](#DenseMatrix+storage) ⇒ <code>string</code>
|
8 | * [.datatype()](#DenseMatrix+datatype) ⇒ <code>string</code>
|
9 | * [.create(data, [datatype])](#DenseMatrix+create)
|
10 | * [.subset(index, [replacement], [defaultValue])](#DenseMatrix+subset)
|
11 | * [.get(index)](#DenseMatrix+get) ⇒ <code>\*</code>
|
12 | * [.set(index, value, [defaultValue])](#DenseMatrix+set) ⇒ <code>DenseMatrix</code>
|
13 | * [.resize(size, [defaultValue], [copy])](#DenseMatrix+resize) ⇒ <code>Matrix</code>
|
14 | * [.clone()](#DenseMatrix+clone) ⇒ <code>DenseMatrix</code>
|
15 | * [.size()](#DenseMatrix+size) ⇒ <code>Array.<number></code>
|
16 | * [.map(callback)](#DenseMatrix+map) ⇒ <code>DenseMatrix</code>
|
17 | * [.forEach(callback)](#DenseMatrix+forEach)
|
18 | * [.toArray()](#DenseMatrix+toArray) ⇒ <code>Array</code>
|
19 | * [.valueOf()](#DenseMatrix+valueOf) ⇒ <code>Array</code>
|
20 | * [.format([options])](#DenseMatrix+format) ⇒ <code>string</code>
|
21 | * [.toString()](#DenseMatrix+toString) ⇒ <code>string</code>
|
22 | * [.toJSON()](#DenseMatrix+toJSON) ⇒ <code>Object</code>
|
23 | * [.diagonal([k])](#DenseMatrix+diagonal) ⇒ <code>Array</code>
|
24 | * [.swapRows(i, j)](#DenseMatrix+swapRows) ⇒ <code>Matrix</code>
|
25 | * _static_
|
26 | * [.diagonal(size, value, [k], [defaultValue])](#DenseMatrix.diagonal) ⇒ <code>DenseMatrix</code>
|
27 | * [.fromJSON(json)](#DenseMatrix.fromJSON) ⇒ <code>DenseMatrix</code>
|
28 | * [.preprocess(data)](#DenseMatrix.preprocess) ⇒ <code>Array</code>
|
29 |
|
30 | <a name="DenseMatrix+storage"></a>
|
31 | ### denseMatrix.storage() ⇒ <code>string</code>
|
32 | Get the storage format used by the matrix.
|
33 |
|
34 | Usage:
|
35 |
|
36 | ```js
|
37 | const format = matrix.storage() // retrieve storage format
|
38 | ```
|
39 |
|
40 | **Kind**: instance method of <code>DenseMatrix</code>
|
41 | **Returns**: <code>string</code> - The storage format.
|
42 | <a name="DenseMatrix+datatype"></a>
|
43 | ### denseMatrix.datatype() ⇒ <code>string</code>
|
44 | Get the datatype of the data stored in the matrix.
|
45 |
|
46 | Usage:
|
47 |
|
48 | ```js
|
49 | const format = matrix.datatype() // retrieve matrix datatype
|
50 | ```
|
51 |
|
52 | **Kind**: instance method of <code>DenseMatrix</code>
|
53 | **Returns**: <code>string</code> - The datatype.
|
54 | <a name="DenseMatrix+create"></a>
|
55 | ### denseMatrix.create(data, [datatype])
|
56 | Create a new DenseMatrix
|
57 |
|
58 | **Kind**: instance method of <code>DenseMatrix</code>
|
59 |
|
60 | | Param | Type |
|
61 | | --- | --- |
|
62 | | data | <code>Array</code> |
|
63 | | [datatype] | <code>string</code> |
|
64 |
|
65 | <a name="DenseMatrix+subset"></a>
|
66 | ### denseMatrix.subset(index, [replacement], [defaultValue])
|
67 | Get a subset of the matrix, or replace a subset of the matrix.
|
68 |
|
69 | Usage:
|
70 |
|
71 | ```js
|
72 | const subset = matrix.subset(index) // retrieve subset
|
73 | const value = matrix.subset(index, replacement) // replace subset
|
74 | ```
|
75 |
|
76 | **Kind**: instance method of <code>DenseMatrix</code>
|
77 |
|
78 | | Param | Type | Default | Description |
|
79 | | --- | --- | --- | --- |
|
80 | | index | <code>Index</code> | | |
|
81 | | [replacement] | <code>Array</code> | <code>DenseMatrix</code>| <code>\*</code> | | |
|
82 | | [defaultValue] | <code>\*</code> | <code>0</code> | Default value, filled in on new entries when the matrix is resized. If not provided, new matrix elements will be filled with zeros. |
|
83 |
|
84 | <a name="DenseMatrix+get"></a>
|
85 | ### denseMatrix.get(index) ⇒ <code>\*</code>
|
86 | Get a single element from the matrix.
|
87 |
|
88 | **Kind**: instance method of <code>DenseMatrix</code>
|
89 | **Returns**: <code>\*</code> - value
|
90 |
|
91 | | Param | Type | Description |
|
92 | | --- | --- | --- |
|
93 | | index | <code>Array.<number></code> | Zero-based index |
|
94 |
|
95 | <a name="DenseMatrix+set"></a>
|
96 | ### denseMatrix.set(index, value, [defaultValue]) ⇒ <code>DenseMatrix</code>
|
97 | Replace a single element in the matrix.
|
98 |
|
99 | **Kind**: instance method of <code>DenseMatrix</code>
|
100 | **Returns**: <code>DenseMatrix</code>- self
|
101 |
|
102 | | Param | Type | Description |
|
103 | | --- | --- | --- |
|
104 | | index | <code>Array.<number></code> | Zero-based index |
|
105 | | value | <code>\*</code> | |
|
106 | | [defaultValue] | <code>\*</code> | Default value, filled in on new entries when the matrix is resized. If not provided, new matrix elements will be left undefined. |
|
107 |
|
108 | <a name="DenseMatrix+resize"></a>
|
109 | ### denseMatrix.resize(size, [defaultValue], [copy]) ⇒ <code>Matrix</code>
|
110 | Resize the matrix to the given size. Returns a copy of the matrix when
|
111 | `copy=true`, otherwise return the matrix itself (resize in place).
|
112 |
|
113 | **Kind**: instance method of <code>DenseMatrix</code>
|
114 | **Returns**: <code>Matrix</code> - The resized matrix
|
115 |
|
116 | | Param | Type | Default | Description |
|
117 | | --- | --- | --- | --- |
|
118 | | size | <code>Array.<number></code> | | The new size the matrix should have. |
|
119 | | [defaultValue] | <code>\*</code> | <code>0</code> | Default value, filled in on new entries. If not provided, the matrix elements will be filled with zeros. |
|
120 | | [copy] | <code>boolean</code> | | Return a resized copy of the matrix |
|
121 |
|
122 | <a name="DenseMatrix+clone"></a>
|
123 | ### denseMatrix.clone() ⇒ <code>DenseMatrix</code>
|
124 | Create a clone of the matrix
|
125 |
|
126 | **Kind**: instance method of <code>DenseMatrix</code>
|
127 | **Returns**: <code>DenseMatrix</code>- clone
|
128 | <a name="DenseMatrix+size"></a>
|
129 | ### denseMatrix.size() ⇒ <code>Array.<number></code>
|
130 | Retrieve the size of the matrix.
|
131 |
|
132 | **Kind**: instance method of <code>DenseMatrix</code>
|
133 | **Returns**: <code>Array.<number></code> - size
|
134 | <a name="DenseMatrix+map"></a>
|
135 | ### denseMatrix.map(callback) ⇒ <code>DenseMatrix</code>
|
136 | Create a new matrix with the results of the callback function executed on
|
137 | each entry of the matrix.
|
138 |
|
139 | **Kind**: instance method of <code>DenseMatrix</code>
|
140 | **Returns**: <code>DenseMatrix</code>- matrix
|
141 |
|
142 | | Param | Type | Description |
|
143 | | --- | --- | --- |
|
144 | | callback | <code>function</code> | The callback function is invoked with three parameters: the value of the element, the index of the element, and the Matrix being traversed. |
|
145 |
|
146 | <a name="DenseMatrix+forEach"></a>
|
147 | ### denseMatrix.forEach(callback)
|
148 | Execute a callback function on each entry of the matrix.
|
149 |
|
150 | **Kind**: instance method of <code>DenseMatrix</code>
|
151 |
|
152 | | Param | Type | Description |
|
153 | | --- | --- | --- |
|
154 | | callback | <code>function</code> | The callback function is invoked with three parameters: the value of the element, the index of the element, and the Matrix being traversed. |
|
155 |
|
156 | <a name="DenseMatrix+toArray"></a>
|
157 | ### denseMatrix.toArray() ⇒ <code>Array</code>
|
158 | Create an Array with a copy of the data of the DenseMatrix
|
159 |
|
160 | **Kind**: instance method of <code>DenseMatrix</code>
|
161 | **Returns**: <code>Array</code> - array
|
162 | <a name="DenseMatrix+valueOf"></a>
|
163 | ### denseMatrix.valueOf() ⇒ <code>Array</code>
|
164 | Get the primitive value of the DenseMatrix: a multidimensional array
|
165 |
|
166 | **Kind**: instance method of <code>DenseMatrix</code>
|
167 | **Returns**: <code>Array</code> - array
|
168 | <a name="DenseMatrix+format"></a>
|
169 | ### denseMatrix.format([options]) ⇒ <code>string</code>
|
170 | Get a string representation of the matrix, with optional formatting options.
|
171 |
|
172 | **Kind**: instance method of <code>DenseMatrix</code>
|
173 | **Returns**: <code>string</code> - str
|
174 |
|
175 | | Param | Type | Description |
|
176 | | --- | --- | --- |
|
177 | | [options] | <code>Object</code> | <code>number</code> | <code>function</code> | Formatting options. See lib/utils/number:format for a description of the available options. |
|
178 |
|
179 | <a name="DenseMatrix+toString"></a>
|
180 | ### denseMatrix.toString() ⇒ <code>string</code>
|
181 | Get a string representation of the matrix
|
182 |
|
183 | **Kind**: instance method of <code>DenseMatrix</code>
|
184 | **Returns**: <code>string</code> - str
|
185 | <a name="DenseMatrix+toJSON"></a>
|
186 | ### denseMatrix.toJSON() ⇒ <code>Object</code>
|
187 | Get a JSON representation of the matrix
|
188 |
|
189 | **Kind**: instance method of <code>DenseMatrix</code>
|
190 | <a name="DenseMatrix+diagonal"></a>
|
191 | ### denseMatrix.diagonal([k]) ⇒ <code>Array</code>
|
192 | Get the kth Matrix diagonal.
|
193 |
|
194 | **Kind**: instance method of <code>DenseMatrix</code>
|
195 | **Returns**: <code>Array</code> - The array vector with the diagonal values.
|
196 |
|
197 | | Param | Type | Default | Description |
|
198 | | --- | --- | --- | --- |
|
199 | | [k] | <code>number</code> | <code>BigNumber</code> | <code>0</code> | The kth diagonal where the vector will retrieved. |
|
200 |
|
201 | <a name="DenseMatrix+swapRows"></a>
|
202 | ### denseMatrix.swapRows(i, j) ⇒ <code>Matrix</code>
|
203 | Swap rows i and j in Matrix.
|
204 |
|
205 | **Kind**: instance method of <code>DenseMatrix</code>
|
206 | **Returns**: <code>Matrix</code> - The matrix reference
|
207 |
|
208 | | Param | Type | Description |
|
209 | | --- | --- | --- |
|
210 | | i | <code>number</code> | Matrix row index 1 |
|
211 | | j | <code>number</code> | Matrix row index 2 |
|
212 |
|
213 | <a name="DenseMatrix.diagonal"></a>
|
214 | ### DenseMatrix.diagonal(size, value, [k], [defaultValue]) ⇒ <code>DenseMatrix</code>
|
215 | Create a diagonal matrix.
|
216 |
|
217 | **Kind**: static method of <code>DenseMatrix</code>
|
218 |
|
219 | | Param | Type | Default | Description |
|
220 | | --- | --- | --- | --- |
|
221 | | size | <code>Array</code> | | The matrix size. |
|
222 | | value | <code>number</code> | <code>Array</code> | | The values for the diagonal. |
|
223 | | [k] | <code>number</code> | <code>BigNumber</code> | <code>0</code> | The kth diagonal where the vector will be filled in. |
|
224 | | [defaultValue] | <code>number</code> | | The default value for non-diagonal |
|
225 |
|
226 | <a name="DenseMatrix.fromJSON"></a>
|
227 | ### DenseMatrix.fromJSON(json) ⇒ <code>DenseMatrix</code>
|
228 | Generate a matrix from a JSON object
|
229 |
|
230 | **Kind**: static method of <code>DenseMatrix</code>
|
231 |
|
232 | | Param | Type | Description |
|
233 | | --- | --- | --- |
|
234 | | json | <code>Object</code> | An object structured like `{"mathjs": "DenseMatrix", data: [], size: []}`, where mathjs is optional |
|
235 |
|
236 | <a name="DenseMatrix.preprocess"></a>
|
237 | ### DenseMatrix.preprocess(data) ⇒ <code>Array</code>
|
238 | Preprocess data, which can be an Array or DenseMatrix with nested Arrays and
|
239 | Matrices. Replaces all nested Matrices with Arrays
|
240 |
|
241 | **Kind**: static method of <code>DenseMatrix</code>
|
242 | **Returns**: <code>Array</code> - data
|
243 |
|
244 | | Param | Type |
|
245 | | --- | --- |
|
246 | | data | <code>Array</code> |
|
247 |
|