1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.createImmutableDenseMatrixClass = void 0;
|
7 |
|
8 | var _is = require("../../utils/is");
|
9 |
|
10 | var _object = require("../../utils/object");
|
11 |
|
12 | var _factory = require("../../utils/factory");
|
13 |
|
14 | var name = 'ImmutableDenseMatrix';
|
15 | var dependencies = ['smaller', 'DenseMatrix'];
|
16 | var createImmutableDenseMatrixClass = (0, _factory.factory)(name, dependencies, function (_ref) {
|
17 | var smaller = _ref.smaller,
|
18 | DenseMatrix = _ref.DenseMatrix;
|
19 |
|
20 | function ImmutableDenseMatrix(data, datatype) {
|
21 | if (!(this instanceof ImmutableDenseMatrix)) {
|
22 | throw new SyntaxError('Constructor must be called with the new operator');
|
23 | }
|
24 |
|
25 | if (datatype && !(0, _is.isString)(datatype)) {
|
26 | throw new Error('Invalid datatype: ' + datatype);
|
27 | }
|
28 |
|
29 | if ((0, _is.isMatrix)(data) || (0, _is.isArray)(data)) {
|
30 |
|
31 | var matrix = new DenseMatrix(data, datatype);
|
32 |
|
33 | this._data = matrix._data;
|
34 | this._size = matrix._size;
|
35 | this._datatype = matrix._datatype;
|
36 | this._min = null;
|
37 | this._max = null;
|
38 | } else if (data && (0, _is.isArray)(data.data) && (0, _is.isArray)(data.size)) {
|
39 |
|
40 | this._data = data.data;
|
41 | this._size = data.size;
|
42 | this._datatype = data.datatype;
|
43 | this._min = typeof data.min !== 'undefined' ? data.min : null;
|
44 | this._max = typeof data.max !== 'undefined' ? data.max : null;
|
45 | } else if (data) {
|
46 |
|
47 | throw new TypeError('Unsupported type of data (' + (0, _is.typeOf)(data) + ')');
|
48 | } else {
|
49 |
|
50 | this._data = [];
|
51 | this._size = [0];
|
52 | this._datatype = datatype;
|
53 | this._min = null;
|
54 | this._max = null;
|
55 | }
|
56 | }
|
57 |
|
58 | ImmutableDenseMatrix.prototype = new DenseMatrix();
|
59 | |
60 |
|
61 |
|
62 |
|
63 | ImmutableDenseMatrix.prototype.type = 'ImmutableDenseMatrix';
|
64 | ImmutableDenseMatrix.prototype.isImmutableDenseMatrix = true;
|
65 | |
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | ImmutableDenseMatrix.prototype.subset = function (index) {
|
80 | switch (arguments.length) {
|
81 | case 1:
|
82 | {
|
83 |
|
84 | var m = DenseMatrix.prototype.subset.call(this, index);
|
85 |
|
86 | if ((0, _is.isMatrix)(m)) {
|
87 |
|
88 | return new ImmutableDenseMatrix({
|
89 | data: m._data,
|
90 | size: m._size,
|
91 | datatype: m._datatype
|
92 | });
|
93 | }
|
94 |
|
95 | return m;
|
96 | }
|
97 |
|
98 |
|
99 | case 2:
|
100 | case 3:
|
101 | throw new Error('Cannot invoke set subset on an Immutable Matrix instance');
|
102 |
|
103 | default:
|
104 | throw new SyntaxError('Wrong number of arguments');
|
105 | }
|
106 | };
|
107 | |
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | ImmutableDenseMatrix.prototype.set = function () {
|
119 | throw new Error('Cannot invoke set on an Immutable Matrix instance');
|
120 | };
|
121 | |
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 | ImmutableDenseMatrix.prototype.resize = function () {
|
136 | throw new Error('Cannot invoke resize on an Immutable Matrix instance');
|
137 | };
|
138 | |
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 | ImmutableDenseMatrix.prototype.reshape = function () {
|
146 | throw new Error('Cannot invoke reshape on an Immutable Matrix instance');
|
147 | };
|
148 | |
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 | ImmutableDenseMatrix.prototype.clone = function () {
|
155 | return new ImmutableDenseMatrix({
|
156 | data: (0, _object.clone)(this._data),
|
157 | size: (0, _object.clone)(this._size),
|
158 | datatype: this._datatype
|
159 | });
|
160 | };
|
161 | |
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 | ImmutableDenseMatrix.prototype.toJSON = function () {
|
168 | return {
|
169 | mathjs: 'ImmutableDenseMatrix',
|
170 | data: this._data,
|
171 | size: this._size,
|
172 | datatype: this._datatype
|
173 | };
|
174 | };
|
175 | |
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 | ImmutableDenseMatrix.fromJSON = function (json) {
|
185 | return new ImmutableDenseMatrix(json);
|
186 | };
|
187 | |
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 | ImmutableDenseMatrix.prototype.swapRows = function () {
|
198 | throw new Error('Cannot invoke swapRows on an Immutable Matrix instance');
|
199 | };
|
200 | |
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 | ImmutableDenseMatrix.prototype.min = function () {
|
207 |
|
208 | if (this._min === null) {
|
209 |
|
210 | var m = null;
|
211 |
|
212 | this.forEach(function (v) {
|
213 | if (m === null || smaller(v, m)) {
|
214 | m = v;
|
215 | }
|
216 | });
|
217 | this._min = m !== null ? m : undefined;
|
218 | }
|
219 |
|
220 | return this._min;
|
221 | };
|
222 | |
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 | ImmutableDenseMatrix.prototype.max = function () {
|
229 |
|
230 | if (this._max === null) {
|
231 |
|
232 | var m = null;
|
233 |
|
234 | this.forEach(function (v) {
|
235 | if (m === null || smaller(m, v)) {
|
236 | m = v;
|
237 | }
|
238 | });
|
239 | this._max = m !== null ? m : undefined;
|
240 | }
|
241 |
|
242 | return this._max;
|
243 | };
|
244 |
|
245 | return ImmutableDenseMatrix;
|
246 | }, {
|
247 | isClass: true
|
248 | });
|
249 | exports.createImmutableDenseMatrixClass = createImmutableDenseMatrixClass; |
\ | No newline at end of file |