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