Skip to content

Commit e4eb130

Browse files
authored
selectElements in CS
1 parent 5869e5b commit e4eb130

File tree

1 file changed

+47
-58
lines changed

1 file changed

+47
-58
lines changed

libraries/MatrixLib.cs

Lines changed: 47 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ public class MatrixLib
33
{
44

55
public MatrixLib()
6-
{
7-
8-
}
9-
6+
{ }
107

118

129
public override string ToString()
@@ -96,13 +93,13 @@ public static ArrayList shape(object x)
9693
{
9794
ArrayList res = MatrixLib_Aux.collect_10((new ArrayList()));
9895

99-
if ((x is ArrayList))
96+
if (x is ArrayList)
10097
{
10198
ArrayList sq = ((ArrayList)x);
10299

103100
res = SystemTypes.addSet((new ArrayList()), ((int)(sq).Count));
104101
if ((sq).Count > 0)
105-
{ res = SystemTypes.concatenate(res, MatrixLib.shape((sq)[1 - 1])); }
102+
{ res = SystemTypes.concatenate(res, MatrixLib.shape((sq)[0])); }
106103
else { return res; }
107104

108105

@@ -119,33 +116,25 @@ public static ArrayList singleValueMatrix(ArrayList sh, object x)
119116
{
120117
if ((sh).Count == 0)
121118
{ return (new ArrayList()); }
122-
else { { } /* No update form for: skip */ }
123119

124120
if ((sh).Count == 1)
125121
{ return MatrixLib_Aux.collect_11(SystemTypes.integerSubrange(1, ((int)sh[1 - 1])), x); }
126-
else { { } /* No update form for: skip */ }
127122

128123
ArrayList res = (new ArrayList());
129124

130125
res = MatrixLib_Aux.collect_12(SystemTypes.integerSubrange(1, ((int)sh[1 - 1])), sh, x);
131126
return res;
132-
133-
134-
135-
136127
}
137128

138129

139130
public static ArrayList fillMatrixFrom(ArrayList sq, ArrayList sh)
140131
{
141132
if ((sh).Count == 0)
142133
{ return (new ArrayList()); }
143-
else { { } /* No update form for: skip */ }
144-
134+
145135
if ((sh).Count == 1)
146136
{ return SystemTypes.subrange(sq, 1, ((int)sh[1 - 1])); }
147-
else { { } /* No update form for: skip */ }
148-
137+
149138
ArrayList res = (new ArrayList());
150139

151140
int prod = SystemTypes.prdint(SystemTypes.tail(sh));
@@ -160,11 +149,6 @@ public static ArrayList fillMatrixFrom(ArrayList sq, ArrayList sh)
160149

161150
}
162151
return res;
163-
164-
165-
166-
167-
168152
}
169153

170154

@@ -179,39 +163,34 @@ public static ArrayList identityMatrix(int n)
179163

180164
public static ArrayList flattenMatrix(ArrayList m)
181165
{
182-
if ((m).Count == 0)
166+
if (m.Count == 0)
183167
{ return (new ArrayList()); }
184-
else { { } /* No update form for: skip */ }
185168

186-
if (((m)[1 - 1] is ArrayList))
169+
if (m[0] is ArrayList)
187170
{
188-
ArrayList sq = ((ArrayList)(m)[1 - 1]);
171+
ArrayList sq = ((ArrayList) m[0]);
189172

190173
return SystemTypes.union(MatrixLib.flattenMatrix(sq), MatrixLib.flattenMatrix(SystemTypes.tail(m)));
191174

192175
}
193-
else { { } /* No update form for: skip */ }
194176

195177
return m;
196178

197-
198179
}
199180

200181

201182
public static double sumMatrix(ArrayList m)
202183
{
203184
if ((m).Count == 0)
204185
{ return 0.0; }
205-
else { { } /* No update form for: skip */ }
206186

207-
if (((m)[1 - 1] is ArrayList))
187+
if (((m)[0] is ArrayList))
208188
{
209-
ArrayList sq = ((ArrayList)(m)[1 - 1]);
189+
ArrayList sq = ((ArrayList)(m)[0]);
210190

211191
return MatrixLib.sumMatrix(sq) + MatrixLib.sumMatrix(SystemTypes.tail(m));
212192

213193
}
214-
else { { } /* No update form for: skip */ }
215194

216195
ArrayList dmat = SystemTypes.concatenate(SystemTypes.addSet((new ArrayList()), ((double)0.0)), m);
217196

@@ -226,7 +205,6 @@ public static double prdMatrix(ArrayList m)
226205
{
227206
if ((m).Count == 0)
228207
{ return 1.0; }
229-
else { { } /* No update form for: skip */ }
230208

231209
if (((m)[1 - 1] is ArrayList))
232210
{
@@ -235,7 +213,6 @@ public static double prdMatrix(ArrayList m)
235213
return MatrixLib.prdMatrix(sq) * MatrixLib.prdMatrix(SystemTypes.tail(m));
236214

237215
}
238-
else { { } /* No update form for: skip */ }
239216

240217
ArrayList dmat = SystemTypes.concatenate(SystemTypes.addSet((new ArrayList()), ((double)1.0)), m);
241218

@@ -248,11 +225,9 @@ public static ArrayList elementwiseApply(ArrayList m, Func<double, double> f)
248225
{
249226
if ((m).Count == 0)
250227
{ return (new ArrayList()); }
251-
else { { } /* No update form for: skip */ }
252228

253229
if (((m)[1 - 1] is ArrayList))
254230
{ return MatrixLib_Aux.collect_15(m, f); }
255-
else { { } /* No update form for: skip */ }
256231

257232
ArrayList dmat = MatrixLib_Aux.collect_16((new ArrayList()));
258233

@@ -274,11 +249,9 @@ public static ArrayList elementwiseMult(ArrayList m, double x)
274249
{
275250
if ((m).Count == 0)
276251
{ return (new ArrayList()); }
277-
else { { } /* No update form for: skip */ }
278252

279253
if (((m)[1 - 1] is ArrayList))
280254
{ return MatrixLib_Aux.collect_17(m, x); }
281-
else { { } /* No update form for: skip */ }
282255

283256
ArrayList dmat = MatrixLib_Aux.collect_16((new ArrayList()));
284257

@@ -300,11 +273,9 @@ public static ArrayList elementwiseAdd(ArrayList m, double x)
300273
{
301274
if ((m).Count == 0)
302275
{ return (new ArrayList()); }
303-
else { { } /* No update form for: skip */ }
304276

305277
if (((m)[1 - 1] is ArrayList))
306278
{ return MatrixLib_Aux.collect_18(m, x); }
307-
else { { } /* No update form for: skip */ }
308279

309280
ArrayList dmat = MatrixLib_Aux.collect_16((new ArrayList()));
310281

@@ -326,11 +297,9 @@ public static ArrayList elementwiseDivide(ArrayList m, double x)
326297
{
327298
if ((m).Count == 0)
328299
{ return (new ArrayList()); }
329-
else { { } /* No update form for: skip */ }
330300

331301
if (((m)[1 - 1] is ArrayList))
332302
{ return MatrixLib_Aux.collect_19(m, x); }
333-
else { { } /* No update form for: skip */ }
334303

335304
ArrayList dmat = MatrixLib_Aux.collect_16((new ArrayList()));
336305

@@ -352,11 +321,9 @@ public static ArrayList elementwiseLess(ArrayList m, double x)
352321
{
353322
if ((m).Count == 0)
354323
{ return (new ArrayList()); }
355-
else { { } /* No update form for: skip */ }
356324

357325
if (((m)[1 - 1] is ArrayList))
358326
{ return MatrixLib_Aux.collect_20(m, x); }
359-
else { { } /* No update form for: skip */ }
360327

361328
ArrayList dmat = MatrixLib_Aux.collect_21((new ArrayList()));
362329

@@ -377,11 +344,9 @@ public static ArrayList elementwiseGreater(ArrayList m, double x)
377344
{
378345
if ((m).Count == 0)
379346
{ return (new ArrayList()); }
380-
else { { } /* No update form for: skip */ }
381347

382348
if (((m)[1 - 1] is ArrayList))
383349
{ return MatrixLib_Aux.collect_22(m, x); }
384-
else { { } /* No update form for: skip */ }
385350

386351
ArrayList dmat = MatrixLib_Aux.collect_21((new ArrayList()));
387352

@@ -403,11 +368,9 @@ public static ArrayList elementwiseEqual(ArrayList m, double x)
403368
{
404369
if ((m).Count == 0)
405370
{ return (new ArrayList()); }
406-
else { { } /* No update form for: skip */ }
407371

408372
if (((m)[1 - 1] is ArrayList))
409373
{ return MatrixLib_Aux.collect_23(m, x); }
410-
else { { } /* No update form for: skip */ }
411374

412375
ArrayList dmat = MatrixLib_Aux.collect_21((new ArrayList()));
413376

@@ -468,15 +431,12 @@ public static double determinant(ArrayList m)
468431

469432
if (n == 1)
470433
{ return ((double)(m)[1 - 1]); }
471-
else { { } /* No update form for: skip */ }
472434

473435
if (n == 2)
474436
{ return MatrixLib.determinant2(m); }
475-
else { { } /* No update form for: skip */ }
476437

477438
if (n == 3)
478439
{ return MatrixLib.determinant3(m); }
479-
else { { } /* No update form for: skip */ }
480440

481441
double res = 0.0;
482442

@@ -507,7 +467,7 @@ public static ArrayList rowAddition(ArrayList m1, ArrayList m2)
507467
{
508468
ArrayList res = (new ArrayList());
509469

510-
if (((m1)[1 - 1] is ArrayList))
470+
if (((m1)[0] is ArrayList))
511471
{
512472
ArrayList _range23 = SystemTypes.integerSubrange(1, (m1).Count);
513473
for (int _i22 = 0; _i22 < _range23.Count; _i22++)
@@ -523,7 +483,6 @@ public static ArrayList rowAddition(ArrayList m1, ArrayList m2)
523483
}
524484
return res;
525485
}
526-
else { { } /* No update form for: skip */ }
527486

528487
ArrayList _range25 = SystemTypes.integerSubrange(1, (m1).Count);
529488
for (int _i24 = 0; _i24 < _range25.Count; _i24++)
@@ -582,7 +541,6 @@ public static ArrayList rowSubtraction(ArrayList m1, ArrayList m2)
582541
}
583542
return res;
584543
}
585-
else { { } /* No update form for: skip */ }
586544

587545
ArrayList _range31 = SystemTypes.integerSubrange(1, (m1).Count);
588546
for (int _i30 = 0; _i30 < _range31.Count; _i30++)
@@ -679,8 +637,6 @@ public static ArrayList dotProduct(ArrayList m1, ArrayList m2)
679637

680638
}
681639
return res;
682-
683-
684640
}
685641

686642

@@ -873,7 +829,7 @@ public static ArrayList matrixGreater(ArrayList m1, ArrayList m2)
873829
public static ArrayList transpose(ArrayList m)
874830
{
875831
if (((m)[0] is ArrayList))
876-
{ { } /* No update form for: skip */ }
832+
{ }
877833
else { return m; }
878834

879835
ArrayList res = (new ArrayList());
@@ -890,13 +846,32 @@ public static ArrayList transpose(ArrayList m)
890846

891847
}
892848

849+
public static ArrayList selectElements(ArrayList m, Func<Double, Boolean> f)
850+
{
851+
if (m.Count == 0)
852+
{ return new ArrayList(); }
853+
854+
if (m[0] is ArrayList)
855+
{ return MatrixLib_Aux.collect_selectElements(m, f); }
893856

857+
ArrayList dmat = new ArrayList();
894858

859+
ArrayList _range7 = new ArrayList();
860+
_range7.AddRange(m);
861+
for (int _i6 = 0; _i6 < _range7.Count; _i6++)
862+
{
863+
Object x = _range7[_i6];
864+
double y = (double) x;
865+
if (f(y))
866+
{ dmat.Add(y); }
867+
}
868+
return dmat;
869+
}
895870
}
896871

897872

898-
class MatrixLib_Aux
899-
{
873+
class MatrixLib_Aux
874+
{
900875
public static ArrayList select_3(ArrayList _l, ArrayList m)
901876
{ // Implements: s->select(i | 1 <= i & i <= m->size())
902877
ArrayList _results_3 = new ArrayList();
@@ -1072,6 +1047,18 @@ public static ArrayList collect_14(ArrayList _l, int n)
10721047
return _results_14;
10731048
}
10741049

1050+
public static ArrayList collect_selectElements(ArrayList _l, Func<Double, Boolean> f)
1051+
{ // Implements: m->collect( _r | MatrixLib.selectElements(_r->oclAsType(Sequence),f) )
1052+
1053+
ArrayList _results_15 = new ArrayList();
1054+
foreach (Object _i in _l)
1055+
{
1056+
Object _r = (Object)_i;
1057+
_results_15.Add(MatrixLib.selectElements(((ArrayList)_r), f));
1058+
}
1059+
return _results_15;
1060+
}
1061+
10751062
public static ArrayList collect_15(ArrayList _l, Func<double, double> f)
10761063
{ // Implements: m->collect( _r | MatrixLib.elementwiseApply(_r->oclAsType(Sequence),f) )
10771064
ArrayList _results_15 = new ArrayList();
@@ -1171,4 +1158,6 @@ public static ArrayList collect_23(ArrayList _l, double x)
11711158
return _results_23;
11721159
}
11731160

1161+
1162+
11741163
}

0 commit comments

Comments
 (0)