forked from sloisel/numeric
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdocumentation.html
More file actions
1839 lines (1648 loc) · 62.9 KB
/
Copy pathdocumentation.html
File metadata and controls
1839 lines (1648 loc) · 62.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html>
<head>
<link rel="SHORTCUT ICON" href="favicon.ico">
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="resources/style.css">
<style>
table { font-size:14px; }
td { vertical-align:top; }
@media print
{
table { font-size:12px; }
td.navmain { font-size:26px; }
body { margin: 5mm 5mm 5mm 5mm; }
}
</style>
<title>Numeric Javascript: Documentation</title>
</head>
<body>
<!--#include file="resources/header.html" -->
<!--
This allows regression tests to run predictably:
<pre>
IN> numeric.seedrandom.seedrandom('1'); Math.random = numeric.seedrandom.random; Math.random();
OUT> 0.2694
</pre>
-->
<table cellspacing=5 style="border:5px solid black;">
<tr><td colspan=3 align="center" style="font-size:18px;">
<b>Reference card for the <tt>numeric</tt> module</b>
<tr valign="top"><td valign="top" width="33%">
<table>
<tr><td><b>Function</b><td><b>Description</b>
<tr><td colspan=2><hr>
<tr><td><tt>add</tt><td>Pointwise <tt>x+y</tt>
<tr><td><tt>addeq</tt><td>Pointwise <tt>x+=y</tt>
<tr><td><tt>sub</tt><td>Pointwise <tt>x-y</tt>
<tr><td><tt>subeq</tt><td>Pointwise <tt>x-=y</tt>
<tr><td><tt>mul</tt><td>Pointwise <tt>x*y</tt>
<tr><td><tt>muleq</tt><td>Pointwise <tt>x*=y</tt>
<tr><td><tt>div</tt><td>Pointwise <tt>x/y</tt>
<tr><td><tt>diveq</tt><td>Pointwise <tt>x/=y</tt>
<tr><td><tt>mod</tt><td>Pointwise <tt>x%y</tt>
<tr><td><tt>modeq</tt><td>Pointwise <tt>x%=y</tt>
<tr><td><tt>lshift</tt><td>Pointwise <tt>x<<y</tt>
<tr><td><tt>lshifteq</tt><td>Pointwise <tt>x<<=y</tt>
<tr><td><tt>rshift</tt><td>Pointwise <tt>x>>y</tt>
<tr><td><tt>rshifteq</tt><td>Pointwise <tt>x>>=y</tt>
<tr><td><tt>rrshift</tt><td>Pointwise <tt>x>>>y</tt>
<tr><td><tt>rrshifteq</tt><td>Pointwise <tt>x>>>=y</tt>
<tr><td><tt>pow</tt><td>Pointwise <tt>Math.pow(x,y)</tt>
<tr><td><tt>neg</tt><td>Pointwise <tt>-x</tt>
<tr><td><tt>abs</tt><td>Pointwise <tt>Math.abs(x)</tt>
<tr><td><tt>exp</tt><td>Pointwise <tt>Math.exp(x)</tt>
<tr><td><tt>log</tt><td>Pointwise <tt>Math.log(x)</tt>
<tr><td><tt>round</tt><td>Pointwise <tt>Math.round(x)</tt>
<tr><td><tt>sqrt</tt><td>Pointwise <tt>Math.sqrt(x)</tt>
<tr><td><tt>ceil</tt><td>Pointwise <tt>Math.ceil(x)</tt>
<tr><td><tt>floor</tt><td>Poinwise <tt>Math.floor(x)</tt>
<tr><td><tt>isFinite</tt><td>Pointwise <tt>isFinite(x)</tt>
<tr><td><tt>isNaN</tt><td>Pointwise <tt>isNaN(x)</tt>
<tr><td><tt>sin</tt><td>Pointwise <tt>Math.sin(x)</tt>
<tr><td><tt>cos</tt><td>Pointwise <tt>Math.cos(x)</tt>
<tr><td><tt>tan</tt><td>Pointwise <tt>Math.tan(x)</tt>
<tr><td><tt>asin</tt><td>Pointwise <tt>Math.asin(x)</tt>
<tr><td><tt>acos</tt><td>Pointwise <tt>Math.acos(x)</tt>
<tr><td><tt>atan</tt><td>Pointwise <tt>Math.atan(x)</tt>
<tr><td><tt>atan2</tt><td>Pointwise <tt>Math.atan2(x,y)</tt>
<tr><td><tt>eq</tt><td>Pointwise <tt>x===y</tt>
<tr><td><tt>neq</tt><td>Pointwise <tt>x!==y</tt>
<tr><td><tt>lt</tt><td>Pointwise <tt>x<y</tt>
<tr><td><tt>leq</tt><td>Pointwise <tt>x<=y</tt>
<tr><td><tt>gt</tt><td>Pointwise <tt>x>y</tt>
<tr><td><tt>geq</tt><td>Pointwise <tt>x>=y</tt>
<tr><td><tt>bool</tt><td>Pointwise <tt>!!x</tt>
<tr><td><tt>not</tt><td>Pointwise logical negation <tt>!x</tt>
<tr><td><tt>and</tt><td>Pointwise <tt>x&&y</tt>
<tr><td><tt>andeq</tt><td>Pointwise <tt>x&=y</tt>
<tr><td><tt>or</tt><td>Pointwise logical or <tt>x||y</tt>
<tr><td><tt>oreq</tt><td>Pointwise <tt>x|=y</tt>
<tr><td><tt>xor</tt><td>Pointwise <tt>x^y</tt>
<tr><td><tt>xoreq</tt><td>Pointwise <tt>x^=y</tt>
<tr><td><tt>band</tt><td>Pointwise <tt>x&y</tt>
<tr><td><tt>bnot</tt><td>Pointwise binary negation <tt>~x</tt>
<tr><td><tt>bor</tt><td>Pointwise binary or <tt>x|y</tt>
<tr><td><tt>bxor</tt><td>Pointwise binary xor <tt>x^y</tt>
<tr><td><tt>when</tt><td>Pointwise conditional operator <tt>x?y:z</tt>
<tr><td><tt>clip</tt><td>Pointwise clip to some range
<tr><td><tt>saturate</tt><td>Pointwise clip to the range [0,1]
<tr><td><tt>same</tt><td>Deep comparison of <tt>x</tt> and <tt>y</tt>
<tr><td><tt>clone</tt><td>Deep copy of Array
<tr><td><tt>pointwise</tt><td>Construct a new pointwise function
<tr><td colspan=2><hr>
<tr><td><tt>sum</tt><td>The sum of an Array
<tr><td><tt>prod</tt><td>The product of an Array
<tr><td><tt>inf</tt><td>The smallest value of an Array
<tr><td><tt>sup</tt><td>The largest value of an Array
</table>
<td valign="top" width="33%">
<table>
<tr><td><b>Function</b><td><b>Description</b>
<tr><td colspan=2><hr>
<tr><td><tt>arginf</tt><td>The index of the smallest value of an Array
<tr><td><tt>argsup</tt><td>The index of the largest value of an Array
<tr><td><tt>all</tt><td>When all the components of an Array are true
<tr><td><tt>any</tt><td>When any of the components of an Array are true
<tr><td><tt>mean</tt><td>The mean of an Array
<tr><td><tt>variance</tt><td>The variance of an Array
<tr><td><tt>std</tt><td>The standard deviation of an Array
<tr><td><tt>norm1</tt><td>Sum of the magnitudes of an Array
<tr><td><tt>norm2</tt><td>Square root of the sum of the squares of an Array
<tr><td><tt>norm2Squared</tt><td>Sum of squares of entries of an Array
<tr><td><tt>norminf</tt><td>Largest modulus entry of an Array
<tr><td><tt>mapreduce</tt><td>Construct a new map-reduce function
<tr><td colspan=2><hr>
<tr><td><tt>dim</tt><td>Get Array dimensions
<tr><td><tt>empty</tt><td>Create an empty Array
<tr><td><tt>rep</tt><td>Create an Array by duplicating values
<tr><td><tt>zeros</tt><td>Create an Array of zeros
<tr><td><tt>ones</tt><td>Create an Array of ones
<tr><td><tt>range</tt><td>Create an Array from a range
<tr><td><tt>linspace</tt><td>Generate evenly spaced values
<tr><td><tt>logspace</tt><td>Generate logarithmically spaced values
<tr><td><tt>flatten</tt><td>Flatten Array to a single dimension
<tr><td><tt>reshape</tt><td>Reshape an Array to given dimensions
<tr><td><tt>flip</tt><td>Flip an Array on a given axis
<tr><td><tt>fliplr</tt><td>Flip an Array on the innermost axis
<tr><td><tt>flipud</tt><td>Flip an Array on the second innermost axis
<tr><td><tt>rot90</tt><td>Rotate an Array 90 degrees counter clockwise
<tr><td><tt>roll</tt><td>Roll an Array on a given axis
<tr><td><tt>wrap</tt><td>Wrap an Array on a given axis
<tr><td><tt>concat</tt><td>Join <tt>x</tt> and <tt>y</tt> together on a given axis
<tr><td><tt>stack</tt><td>Join Arrays together on a given axis
<tr><td><tt>hstack</tt><td>Join Arrays on their innermost axis
<tr><td><tt>vstack</tt><td>Join Arrays on their second innermost axis
<tr><td><tt>dstack</tt><td>Join Arrays on their third innermost axis
<tr><td colspan=2><hr>
<tr><td><tt>slice</tt><td>Get a slice of an Array
<tr><td><tt>sliceeq</tt><td>Set the values of a slice of an Array
<tr><td><tt>index</tt><td>Get the values of an Array at a given Array of integer indices
<tr><td><tt>indexeq</tt><td>Set the values of an Array at a given Array of integer indices
<tr><td><tt>mask</tt><td>Get the values in an Array where a boolean Array is true
<tr><td><tt>maskeq</tt><td>Set the values in an Array where a boolean Array is true
<tr><td colspan=2><hr>
<tr><td><tt>dot</tt><td>Matrix-Matrix, Matrix-Vector and Vector-Matrix product
<tr><td><tt>det</tt><td>Determinant
<tr><td><tt>eig</tt><td>Eigenvalues and eigenvectors
<tr><td><tt>inv</tt><td>Matrix inverse
<tr><td><tt>svd</tt><td>Singular value decomposition
<tr><td><tt>diag</tt><td>Create diagonal matrix
<tr><td><tt>identity</tt><td>Identity matrix
<tr><td><tt>transpose</tt><td>Matrix transpose
<tr><td><tt>inner</tt><td>Inner product of two Arrays
<tr><td><tt>outer</tt><td>Outer product of two Arrays
<tr><td><tt>kron</tt><td>Kronecker product of two matrices
<tr><td><tt>tensor</tt><td>Tensor product <tt>z[i][j] = x[i]*y[j]</tt>
<tr><td><tt>solve</tt><td>Solve <tt>Ax=b</tt>
<tr><td><tt>solveLP</tt><td>Solve a linear programming problem
<tr><td><tt>solveQP</tt><td>Solve a quadratic programming problem
<tr><td><tt>LU</tt><td>Dense LU decomposition
<tr><td><tt>LUsolve</tt><td>Dense LU solve
</table>
<td valign="top" width="33%">
<table>
<tr><td><b>Function</b><td><b>Description</b>
<tr><td colspan=2><hr>
<tr><td><tt>getDiag</tt><td>Get the diagonal of a matrix
<tr><td><tt>setDiag</tt><td>Set the diagonal of a matrix
<tr><td><tt>getBlock</tt><td>Get a block from a matrix
<tr><td><tt>setBlock</tt><td>Set a block of a matrix
<tr><td colspan=2><hr>
<tr><td><tt>parseFloat</tt><td>Pointwise <tt>parseFloat(x)</tt>
<tr><td><tt>parseDate</tt><td>Pointwise <tt>parseDate(x)</tt>
<tr><td><tt>parseCSV</tt><td>Parse a CSV file into an Array
<tr><td><tt>toCSV</tt><td>Make a CSV file
<tr><td><tt>imageURL</tt><td>Encode a matrix as an image URL
<tr><td colspan=2><hr>
<tr><td><tt>random</tt><td>Create an Array of random numbers
<tr><td><tt>seedrandom</tt><td>The seedrandom module
<tr><td colspan=2><hr>
<tr><td><tt>ccsSparse</tt><td>Convert from full to sparse
<tr><td><tt>ccsFull</tt><td>Convert sparse to full
<tr><td><tt>ccsDim</tt><td>Dimensions of sparse matrix
<tr><td><tt>ccsDot</tt><td>Sparse matrix-matrix product
<tr><td><tt>ccsGather</tt><td>Gather entries of sparse matrix
<tr><td><tt>ccsScatter</tt><td>Scatter entries of sparse matrix
<tr><td><tt>ccsLUP</tt><td>Compute LUP decomposition of sparse matrix
<tr><td><tt>ccsLUPSolve</tt><td>Solve <tt>Ax=b</tt> using LUP decomp
<tr><td><tt>ccsTSolve</tt><td>Solve upper/lower triangular system
<tr><td><tt>ccsGetBlock</tt><td>Get rows/columns of sparse matrix
<tr><td><tt>ccs<op></tt><td>Supported ops include: add/div/mul/geq/etc...
<tr><td colspan=2><hr>
<tr><td><tt>cdotMV</tt><td>Coordinate matrix-vector product
<tr><td><tt>cLU</tt><td>Coordinate matrix LU decomposition
<tr><td><tt>cLUsolve</tt><td>Coordinate matrix LU solve
<tr><td><tt>cgrid</tt><td>Coordinate grid for cdelsq
<tr><td><tt>cdelsq</tt><td>Coordinate matrix Laplacian
<tr><td colspan=2><hr>
<tr><td><tt>dopri</tt><td>Numerical integration of ODE using Dormand-Prince RK method. Returns an object Dopri.
<tr><td><tt>Dopri.at</tt><td>Evaluate the ODE solution at a point
<tr><td colspan=2><hr>
<tr><td><tt>uncmin</tt><td>Unconstrained optimization
<tr><td colspan=2><hr>
<tr><td><tt>spline</tt><td>Create a Spline object
<tr><td><tt>Spline.at</tt><td>Evaluate the Spline at a point
<tr><td><tt>Spline.diff</tt><td>Differentiate the Spline
<tr><td><tt>Spline.roots</tt><td>Find all the roots of the Spline
<tr><td colspan=2><hr>
<tr><td><tt>t</tt><td>Create a tensor type T (may be complex-valued)
<tr><td><tt>T.<numericfun></tt><td>Supported <numericfun> are: abs, add, cos, diag, div, dot, exp, getBlock, getDiag, inv, log, mul, neg, norm2, setBlock, sin, sub, transpose
<tr><td><tt>T.conj</tt><td>Pointwise complex conjugate
<tr><td><tt>T.fft</tt><td>Fast Fourier transform
<tr><td><tt>T.get</tt><td>Read an entry
<tr><td><tt>T.getRow</tt><td>Get a row
<tr><td><tt>T.getRows</tt><td>Get a range of rows
<tr><td><tt>T.ifft</tt><td>Inverse FFT
<tr><td><tt>T.reciprocal</tt><td>Pointwise 1/z
<tr><td><tt>T.set</tt><td>Set an entry
<tr><td><tt>T.setRow</tt><td>Set a row
<tr><td><tt>T.setRows</tt><td>Set a range of rows
<tr><td><tt>T.transjugate</tt><td>The conjugate-transpose of a matrix
<tr><td colspan=2><hr>
<tr><td><tt>version</tt><td>Version string for the numeric library
<tr><td><tt>bench</tt><td>Benchmarking routine
<tr><td><tt>epsilon</tt><td>2.220446049250313e-16
<tr><td><tt>pi</tt><td>3.14159265358979...
<tr><td><tt>e</tt><td>2.71828182845904...
<tr><td><tt>prettyPrint</tt><td>Pretty-prints x
<tr><td><tt>precision</tt><td>Number of digits to prettyPrint
<tr><td><tt>largeArray</tt><td>Don't prettyPrint Arrays larger than this
</table></table>
<br>
<h1>Numerical analysis in Javascript</h1>
<a href="http://www.numericjs.com/">Numeric Javascript</a> is
library that provides many useful functions for numerical
calculations, particularly for linear algebra (vectors and matrices).
You can create vectors and matrices and multiply them:
<pre>
IN> A = [[1,2,3],[4,5,6]];
OUT> [[1,2,3],
[4,5,6]]
IN> x = [7,8,9]
OUT> [7,8,9]
IN> numeric.dot(A,x);
OUT> [50,122]
</pre>
The example shown above can be executed in the
<a href="http://www.numericjs.com/workshop.php">Javascript Workshop</a> or at any
Javascript prompt. The Workshop provides plotting capabilities:<br>
<img src="resources/workshop.png"><br>
The function <tt>workshop.plot()</tt> is essentially the <a href="http://code.google.com/p/flot/">flot</a>
plotting command.<br><br>
The <tt>numeric</tt> library provides functions that implement most of the usual Javascript
operators for vectors and matrices:
<pre>
IN> x = [7,8,9];
y = [10,1,2];
numeric['+'](x,y)
OUT> [17,9,11]
IN> numeric['>'](x,y)
OUT> [false,true,true]
</pre>
These operators can also be called with plain Javascript function names:
<pre>
IN> numeric.add([7,8,9],[10,1,2])
OUT> [17,9,11]
</pre>
You can also use these operators with three or more parameters:
<pre>
IN> numeric.add([1,2],[3,4],[5,6],[7,8])
OUT> [16,20]
</pre>
The function <tt>numeric.inv()</tt> can be used to compute the inverse of an invertible matrix:
<pre>
IN> A = [[1,2,3],[4,5,6],[7,1,9]]
OUT> [[1,2,3],
[4,5,6],
[7,1,9]]
IN> Ainv = numeric.inv(A);
OUT> [[-0.9286,0.3571,0.07143],
[-0.1429,0.2857,-0.1429],
[0.7381,-0.3095,0.07143]]
</pre>
The function <tt>numeric.prettyPrint()</tt> is used to print most of the examples in this documentation.
It formats objects, arrays and numbers so that they can be understood easily. All output is automatically
formatted using <tt>numeric.prettyPrint()</tt> when in the
<a href="http://www.numericjs.com/workshop.php">Workshop</a>. In order to present the information clearly and
succintly, the function <tt>numeric.prettyPrint()</tt> lays out matrices so that all the numbers align.
Furthermore, numbers are given approximately using the <tt>numeric.precision</tt> variable:
<pre>
IN> numeric.precision = 10; x = 3.141592653589793
OUT> 3.141592654
IN> numeric.precision = 4; x
OUT> 3.142
</pre>
The default precision is 4 digits. In addition to printing approximate numbers,
the function <tt>numeric.prettyPrint()</tt> will replace large arrays with the string <tt>...Large Array...</tt>:
<pre>
IN> numeric.identity(100)
OUT> ...Large Array...
</pre>
By default, this happens with the Array's length is more than 50. This can be controlled by setting the
variable <tt>numeric.largeArray</tt> to an appropriate value:
<pre>
IN> numeric.largeArray = 2; A = numeric.identity(4)
OUT> ...Large Array...
IN> numeric.largeArray = 50; A
OUT> [[1,0,0,0],
[0,1,0,0],
[0,0,1,0],
[0,0,0,1]]
</pre>
In particular, if you want to print all Arrays regardless of size, set <tt>numeric.largeArray = Infinity</tt>.
<br><br>
<h1>Math Object functions</h1>
The <tt>Math</tt> object functions have also been adapted to work on Arrays as follows:
<pre>
IN> numeric.exp([1,2]);
OUT> [2.718,7.389]
IN> numeric.exp([[1,2],[3,4]])
OUT> [[2.718, 7.389],
[20.09, 54.6]]
IN> numeric.abs([-2,3])
OUT> [2,3]
IN> numeric.acos([0.1,0.2])
OUT> [1.471,1.369]
IN> numeric.asin([0.1,0.2])
OUT> [0.1002,0.2014]
IN> numeric.atan([1,2])
OUT> [0.7854,1.107]
IN> numeric.atan2([1,2],[3,4])
OUT> [0.3218,0.4636]
IN> numeric.ceil([-2.2,3.3])
OUT> [-2,4]
IN> numeric.floor([-2.2,3.3])
OUT> [-3,3]
IN> numeric.log([1,2])
OUT> [0,0.6931]
IN> numeric.pow([2,3],[0.25,7.1])
OUT> [1.189,2441]
IN> numeric.round([-2.2,3.3])
OUT> [-2,3]
IN> numeric.sin([1,2])
OUT> [0.8415,0.9093]
IN> numeric.sqrt([1,2])
OUT> [1,1.414]
IN> numeric.tan([1,2])
OUT> [1.557,-2.185]
IN> numeric.bool([1,4,0,-2])
OUT> [true,true,false,true]
</pre>
You can use the conditional ternary operator <tt><cond> ? <then> : <else></tt> with the <tt>numeric.when()</tt> function.
<pre>
IN> a = [5,2,3]; b = [1,7,3];
c = [1,1,1]; d = [2,2,2];
numeric.when(numeric.lt(a,b),c,d);
OUT> [2,1,2]
</pre>
<h1>Utility functions</h1>
The function <tt>numeric.dim()</tt> allows you to compute the dimensions of an Array.
<pre>
IN> numeric.dim([1,2])
OUT> [2]
IN> numeric.dim([[1,2,3],[4,5,6]])
OUT> [2,3]
</pre>
You can perform a deep comparison of Arrays using <tt>numeric.same()</tt>:
<pre>
IN> numeric.same([1,2],[1,2])
OUT> true
IN> numeric.same([1,2],[1,2,3])
OUT> false
IN> numeric.same([1,2],[[1],[2]])
OUT> false
IN> numeric.same([[1,2],[3,4]],[[1,2],[3,4]])
OUT> true
IN> numeric.same([[1,2],[3,4]],[[1,2],[3,5]])
OUT> false
IN> numeric.same([[1,2],[2,4]],[[1,2],[3,4]])
OUT> false
</pre>
You can create a multidimensional Array from a given value using <tt>numeric.rep()</tt>,
or you create Arrays of zeros or ones using the functions <tt>numeric.zeros()</tt> and
<tt>numeric.ones()</tt>, and empty Arrays using <tt>numeric.empty()</tt>.
<pre>
IN> numeric.rep([3],5)
OUT> [5,5,5]
IN> numeric.rep([2,3],0)
OUT> [[0,0,0],
[0,0,0]]
IN> numeric.zeros([2,2])
OUT> [[0,0],
[0,0]]
IN> numeric.ones([5,1])
OUT> [[1],[1],[1],[1],[1]]
IN> numeric.empty([2,3])
OUT> [[,,],[,,]]
</pre>
The functions <tt>numeric.any()</tt> and <tt>numeric.all()</tt> allow you to check whether any or all entries
of an Array are boolean true values.
<pre>
IN> numeric.any([false,true])
OUT> true
IN> numeric.any([[0,0,3.14],[0,false,0]])
OUT> true
IN> numeric.any([0,0,false])
OUT> false
IN> numeric.all([false,true])
OUT> false
IN> numeric.all([[1,4,3.14],["no",true,-1]])
OUT> true
IN> numeric.all([0,0,false])
OUT> false
</pre>
The functions <tt>numeric.inf()</tt> and <tt>numeric.sup()</tt> allow you to get the smallest and largest values
in an Array. You can also use the <tt>numeric.argsup()</tt> and <tt>numeric.arginf()</tt> functions to get the
indices of these values.
<pre>
IN> numeric.inf([5.2,6.1,2.8,1.3])
OUT> 1.3
IN> numeric.sup([5.2,6.1,2.8,1.3])
OUT> 6.1
IN> numeric.argsup([5.2,6.1,2.8,1.3])
OUT> 1
IN> numeric.arginf([5.2,6.1,2.8,1.3])
OUT> 3
</pre>
These functions can all be given an optional argument specifying the axis upon which to do the operation.
If a negative index is given it will be used as an offset from the innermost axis. When no axis is given
the operation is performed on a flattened version of the Array.
<pre>
IN> numeric.sum([[1,2],[3,4],[5,6]], 0)
OUT> [9,12]
IN> numeric.sum([[1,2],[3,4],[5,6]], 1)
OUT> [3,7,11]
IN> numeric.sum(
[[[1,2],[3,4]],
[[5,6],[7,8]]], -1)
OUT> [[ 3, 7],
[11,15]]
</pre>
You can loop over Arrays as you normally would. However, in order to generate optimized
code, the <tt>numeric</tt> library provides a few efficient loop-generation mechanisms. For
example, the <tt>numeric.mapreduce()</tt> function can be used to make a function that
computes the sum of all the entries of an Array.
It must be provided with two strings. The first is the code to be peformed on each iteration.
It has access to the variables <tt>i</tt> and <tt>x</tt> representing the index and Array.
The second string is code to be performed as setup. It is used to construct the base case.
To correctly construct the base case, the <tt>s</tt> variable contains the dimensions of each
element in <tt>x</tt>.
<pre>
IN> sum = numeric.mapreduce('z = numeric.add(z, x[i])','var z = numeric.zeros(s);'); sum([1,2,3])
OUT> 6
IN> sum([[1,2,3],[4,5,6]])
OUT> 21
IN> sum([[1,2,3],[4,5,6]],0)
OUT> [5,7,9]
</pre>
The best way to create new pointwise functions is to compose the existing ones, but if for any reason this
wont work you can use <tt>numeric.pointwise</tt> to generate efficient functions that act like the built-ins.
This ensures they will be fast, and allows them to be combined, composed, and broadcast in the same way.
To do this you must specify some code acting on the variables <tt>x</tt>, <tt>y</tt>, <tt>z</tt>,
and the corresponding indices <tt>i</tt>, <tt>j</tt>, <tt>k</tt>. Where <tt>x</tt> and <tt>y</tt> are
the inputs, and <tt>z</tt> is the output. For in-place functions <tt>x</tt> should be assigned to rather than <tt>z</tt>.
Code for a <em>setup</em> function can also be given, and will be performed before looping.
The final argument is the type of the pointwise function to generate. This can be either <tt>'binary'</tt>,
<tt>'binary-inplace'</tt>, <tt>'unary'</tt>, or <tt>'unary-inplace'</tt>.
<pre>
IN> adddouble = numeric.pointwise('z[k] = 2 * (x[i] + y[j])','','binary'); adddouble([1,2,3],[4,5,6])
OUT> [10,14,18]
IN> adddouble(5, [10,11,12])
OUT> [30,32,34]
IN> justdouble = numeric.pointwise('x[i] = 2 * x[i]','','unary-inplace'); v = [1,2,3]; justdouble(v); v;
OUT> [2,4,6]
</pre>
You can create a diagonal matrix using <tt>numeric.diag()</tt>
<pre>
IN> numeric.diag([1,2,3])
OUT> [[1,0,0],
[0,2,0],
[0,0,3]]
</pre>
The function <tt>numeric.identity()</tt> returns the identity matrix.
<pre>
IN> numeric.identity(3)
OUT> [[1,0,0],
[0,1,0],
[0,0,1]]
</pre>
Random Arrays can also be created:
<pre>
IN> numeric.random([2,3])
OUT> [[0.748,0.5187,0.5475],
[0.2482,0.8741,0.4344]]
</pre>
You can generate a vector of evenly or logarithmically spaced values:
<pre>
IN> numeric.linspace(1,5);
OUT> [1,2,3,4,5]
IN> numeric.linspace(1,3,5);
OUT> [1,1.5,2,2.5,3]
IN> numeric.logspace(1,3,5);
OUT> [10,31.62,1e2,316.2,1e3]
</pre>
Or via some range specifier:
<pre>
IN> numeric.range(7);
OUT> [0,1,2,3,4,5,6]
IN> numeric.range(0, 5);
OUT> [0,1,2,3,4]
IN> numeric.range(1, 3);
OUT> [1,2]
IN> numeric.range(-1, 6, 2);
OUT> [-1, 1, 3, 5]
</pre>
<!--
<pre>
IN> numeric.blockMatrix([[[[1,2],[3,4]],[[5,6],[7,8]]],
[[[11,12],[13,14]],[[15,16],[17,18]]]])
OUT> [[ 1, 2, 5, 6],
[ 3, 4, 7, 8],
[11,12,15,16],
[13,14,17,18]]
</pre>
-->
<h1>Arithmetic operations</h1>
The standard arithmetic operations have been vectorized and are polymorphic:
<pre>
IN> numeric.add([1,2],[3,4])
OUT> [4,6]
IN> numeric.add([1,2],3)
OUT> [4,5]
IN> numeric.add(1,[2,3])
OUT> [3,4]
IN> numeric.add([1,2,3],[4,5,6])
OUT> [5,7,9]
</pre>
The other arithmetic operations are available:
<pre>
IN> numeric.sub([1,2],[3,4])
OUT> [-2,-2]
IN> numeric.mul([1,2],[3,4])
OUT> [3,8]
IN> numeric.div([1,2],[3,4])
OUT> [0.3333,0.5]
</pre>
The in-place operators (such as +=) are also available, but a word of warning -
these will not work correctly on scalar values as the standard arithmetic operatiors
do because they cannot edit the value of a scalar in-place.
<pre>
IN> v = [1,2,3,4]; numeric.addeq(v,3); v
OUT> [4,5,6,7]
IN> v = [1,2,3]; numeric.subeq(v,[5,3,1]); v
OUT> [-4,-1,2]
</pre>
Unary operators and their in-place versions are also provided.
<pre>
IN> numeric.neg([1,-2,3])
OUT> [-1,2,-3]
IN> v = [4,5,6]; numeric.negeq(v); v
OUT> [-4,-5,-6]
IN> numeric.isFinite([10,NaN,Infinity])
OUT> [true,false,false]
IN> numeric.isNaN([10,NaN,Infinity])
OUT> [false,true,false]
</pre>
<!--
<pre>
IN> n = 41; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMsmall(numeric.inv(A),A),numeric.identity(n)))<1e-11
OUT> true
IN> n = 42; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMsmall(numeric.inv(A),A),numeric.identity(n)))<1e-11
OUT> true
IN> n = 43; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMsmall(numeric.inv(A),A),numeric.identity(n)))<1e-11
OUT> true
IN> n = 44; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMbig(numeric.inv(A),A),numeric.identity(n)))<1e-11
OUT> true
IN> n = 45; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMbig(numeric.inv(A),A),numeric.identity(n)))<1e-11
OUT> true
IN> n = 46; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMbig(numeric.inv(A),A),numeric.identity(n)))<1e-11
OUT> true
</pre>
-->
<h1>Slicing</h1>
The <tt>slice</tt> command allows for accessing parts of numeric Arrays in more advanced ways.
It can be passed an Array of indices for each dimension.
<pre>
IN> numeric.slice([[1,2],[3,4],[5,6]], [2,0])
OUT> 5
IN> numeric.slice([[1,2],[3,4],[5,6]], [1])
OUT> [3,4]
</pre>
But inside this Array you can also pass in it a <em>slice</em>. This is
a string consisting of three numbers separated by colons <tt>start:stop:step</tt>
which tell the command to access the Array starting at some index, stopping
at some index, and performing some step size.
<pre>
IN> numeric.slice([0,1,2,3,4,5,6,7,8,9], [1+':'+7+':'+2])
OUT> [1,3,5]
IN> numeric.slice([1,5,1,7,26], [0+':'+5+':'+2])
OUT> [1,1,26]
</pre>
The string is flexible. You can leave out the <tt>step</tt> section, or
omit the starting and stopping values. In this case the slice starts at the
first element of the Array, and stops at the last. Therefore the string <tt>':'</tt>
can be used to specify that every element on some axis be used.
<pre>
IN> numeric.slice([1,5,1,7,26], [1+':'+3])
OUT> [5,1]
IN> numeric.slice([1,5,1,7,26], [':'+3])
OUT> [1,5,1]
IN> numeric.slice([1,5,1,7,26], [3+':'])
OUT> [7,26]
IN> numeric.slice([1,5,1,7,26], [':'])
OUT> [1,5,1,7,26]
IN> numeric.slice([[1,2],[3,4],[5,6]], [':',1])
OUT> [2,4,6]
</pre>
Negative numbers can also be used. These are assumed to be offsets from
the final element in the Array. So <tt>-1</tt> can be used to mean the final element,
<tt>-2</tt> the second to last, and so on.
<pre>
IN> numeric.slice([0,1,2,3,4,5,6,7,8,9], [-1])
OUT> 9
IN> numeric.slice([0,1,2,3,4,5,6,7,8,9], [-2+':'+10])
OUT> [8,9]
IN> numeric.slice([0,1,2,3,4,5,6,7,8,9], [-3+':'+3+':'+-1])
OUT> [7,6,5,4]
</pre>
The string <tt>'|'</tt> can be used to insert a new axis of a single element into
an Array. This is particularly useful when used in conjunction with <em>broadcasting</em>
(see below).
<pre>
IN> numeric.slice([0,1,2,3,4,5,6,7,8,9], ['|'])
OUT> [[0,1,2,3,4,5,6,7,8,9]]
IN> numeric.slice([0,1,2,3,4,5,6,7,8,9], [':','|'])
OUT> [[0],[1],[2],[3],[4],[5],[6],[7],[8],[9]]
IN> numeric.dim([0,1,2,3,4,5,6,7,8,9])
OUT> [10]
IN> numeric.dim(numeric.slice([0,1,2,3,4,5,6,7,8,9], ['|',':']))
OUT> [1,10]
IN> numeric.dim(numeric.slice([0,1,2,3,4,5,6,7,8,9], [':','|']))
OUT> [10,1]
</pre>
The string <tt>'...'</tt> can be used in the position of the first axis to specify
an access pattern from the right hand side. It corresponds to using <tt>':'</tt>
for all axes up until those specified.
<pre>
IN> numeric.slice([[0,1,2],[3,4,5],[6,7,8]], ['...',1])
OUT> [1,4,7]
IN> numeric.slice([[[0,1],[2,3],[4,5],[6,7],[8,9]]], ['...',1])
OUT> [[1,3,5,7,9]]
IN> numeric.slice([[[0,1,2],[3,4,5],[6,7,8]]], ['...',1+':'])
OUT> [[[1,2],[4,5],[7,8]]]
</pre>
As well as getting data you can also set data using the <tt>sliceeq</tt> function. It takes
as input an Array, a slice Array, and the new values to set. It then sets the values of the
Array in-place.
If you have previously extracted some data using a slice this can be useful for inserting
it back into an Array.
<pre>
IN> v = [1,2,3,4]; numeric.sliceeq(v,[':'+2],[0,0]); v
OUT> [0,0,3,4]
IN> v = [[1,2],[3,4]]; numeric.sliceeq(v,[':',1],10); v
OUT> [[1,10],[3,10]]
</pre>
<h1>Broadcasting</h1>
When performing pointwise operations between Arrays it is sometimes possible
to calculate a result when the dimensions don't exactly match. This behaviour is
called <em>broadcast</em>. First each Array is wrapped in single element Arrays
until both have the same number of dimensions. Then when performing the operation,
on any dimension with just a single element, the single element in this dimension
will be used as the operand for all calculations along that axis. You can think of
this value as being <em>stretched</em> or <em>repeated</em>, such that it is matched
against every element in the other Array.
<pre>
IN> numeric.mul([[1,2],[3,4],[5,6]], [10,11])
OUT> [[10,22],[30,44],[50,66]]
IN> numeric.mul([[1,2],[3,4],[5,6]], [[10],[11],[22]])
OUT> [[10,20],[33,44],[110,132]]
IN> numeric.add(numeric.identity(3), [1,1,1])
OUT> [[2,1,1],
[1,2,1],
[1,1,2]]
IN> numeric.add(numeric.rep([3,5], 0), [1,2,3,4,5])
OUT> [[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5]]
IN> numeric.add(numeric.rep([2,2,2], 0), [[1],[2]])
OUT> [[[1,1],[2,2]],
[[1,1],[2,2]]]
</pre>
This can be very useful when used with the new axis <tt>'|'</tt> slice
string. For example here we can efficiently compute a pairwise multiplication
between two vectors by inserting new single element axis.
<pre>
IN> numeric.mul(numeric.slice([1,2,3],[':','|']), numeric.slice([4,5,6],['|',':']))
OUT> [[4, 5, 6],
[8, 10,12],
[12,15,18]]
</pre>
For more information about broadcasting see <a href="http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html">Numpy's
broadcasting mechanics</a> which <tt>numeric</tt> attempts to emulate.
<h1>Joining & Reshaping</h1>
Arrays can be joined together using the <tt>numeric.concat()</tt> function. This
takes as input the two arrays to concatenate and the axis upon which to concatenate them.
<pre>
IN> numeric.concat([1,2],[3,4], 0)
OUT> [1,2,3,4]
IN> numeric.concat([[1,2],[3,4]], [[5,6],[7,8]], 0)
OUT> [[1,2],[3,4],[5,6],[7,8]]
IN> numeric.concat([[1,2],[3,4]], [[5,6],[7,8]], 1)
OUT> [[1,2,5,6],[3,4,7,8]]
</pre>
If you want to concatenate multiple Arrays you can use the <tt>numeric.stack()</tt> function which
takes as input an Array of Arrays.
Concatenating on the innermost, second innermost, and third innermost axes, is a very common operation,
so functions for these are provided as <tt>numeric.hstack()</tt>, <tt>numeric.vstack()</tt> and
<tt>numeric.dstack()</tt>.
<pre>
IN> numeric.stack([[1,2],[3,4],[5,6]], 0)
OUT> [1,2,3,4,5,6]
IN> a = [[1,2],[3,4]];
b = [[5,6],[7,8]];
numeric.hstack([a,b])
OUT> [[1,2,5,6],
[3,4,7,8]]
IN> a = [[1,2],[3,4]];
b = [[5,6],[7,8]];
numeric.vstack([a,b])
OUT> [[1,2],
[3,4],
[5,6],
[7,8]]
</pre>
Arrays can be reshaped to different dimensions using the <tt>numeric.reshape()</tt> function,
and can be flattened into a single dimension Array using the <tt>numeric.flatten()</tt> function.
<pre>
IN> numeric.flatten([[1,2],[3,4],[5,6]])
OUT> [1,2,3,4,5,6]
IN> numeric.reshape([1,2,3,4],[2,2])
OUT> [[1,2],[3,4]]
IN> numeric.dim([[1,2],[3,4],[5,6]])
OUT> [3,2]
IN> numeric.reshape([[1,2],[3,4],[5,6]],[2,3])
OUT> [[1,2,3],[4,5,6]]
IN> numeric.dim([[1,2,3],[4,5,6]])
OUT> [2,3]
</pre>
Arrays can be reversed using <tt>numeric.flip()</tt>, rotated using <tt>numeric.rot90()</tt>, and rolled using <tt>numeric.roll()</tt>.
<pre>
IN> numeric.flip([1,2,3,4])
OUT> [4,3,2,1]
IN> numeric.flip([[1,2],[3,4]], 0)
OUT> [[3,4],[1,2]]
IN> numeric.flip([[1,2],[3,4]], 1)
OUT> [[2,1],[4,3]]
IN> numeric.rot90([[1,2],[3,4]])
OUT> [[2,4],[1,3]]
IN> numeric.roll([1,2,3,4], 2)
OUT> [3,4,1,2]
IN> numeric.roll([[1,2],[3,4],[5,6]], 1, 0)
OUT> [[5,6],[1,2],[3,4]]
</pre>
Elements in an Array can be wrapped with a new Array using the <tt>numeric.wrap()</tt> function.
An optional axis argument can be given to say upon which axis to do the wrapping.
<pre>
IN> numeric.wrap([1,2,3,4])
OUT> [[1],[2],[3],[4]]
IN> numeric.wrap([[1,2],[3,4],[5,6]])
OUT> [[[1],[2]],[[3],[4]],[[5],[6]]]
IN> numeric.wrap([1,2,3,4], 0)
OUT> [[1,2,3,4]]
IN> numeric.wrap([[1,2],[3,4],[5,6]], 1)
OUT> [[[1,2]],[[3,4]],[[5,6]]]
</pre>
<h1>Masking & Indexing</h1>
Boolean Arrays can be used to <em>mask</em> off certain values in an Array. This is done with the
<tt>numeric.mask()</tt> function. The first Array is matched against the second boolean Array and those
elements which are true in the boolean Array are returned. Because masking doesn't ensure the dimensions
of the Array will remain valid, the values are returned flattened.
<pre>
IN> a = [[1,5,3,4],[5,9,2,3]];
numeric.mask(a, numeric.lt(a,5));
OUT> [1,3,4,2,3]
IN> a = [[1,5,3,4],[5,9,2,3]];
numeric.mask(a, numeric.gt(a,4));
OUT> [5,5,9]
</pre>
You can set the values in an Array with a mask using <tt>numeric.maskeq()</tt>.
This is useful in conjunction with <tt>numeric.mask()</tt> function because it allows
different operations to be performed on different parts of an Array given some
condition. For example we can use it to multiply by 10 only when the numbers in the
Array are less than 5.
<pre>
IN> a = [[1,5,3,4],[5,9,2,3]];
m = numeric.lt(a,5);
b = numeric.mask(a, m);
numeric.maskeq(a,m,numeric.mul(b,10)); a;
OUT> [[10,5,30,40],[5,9,20,30]]
</pre>
Arrays can also be used as indices to other Arrays. This is similar to specifying
multiple indices at once. It allows you to get specific elements from an Array at once.
To do this the <tt>numeric.index()</tt> function is used.
<pre>
IN> numeric.index([[1,2],[3,4],[5,6]],[0,2])
OUT> [[1,2],[5,6]]
IN> numeric.index([[1,2],[3,4],[5,6]],[[0],[1],[1]])
OUT> [[[1,2]],[[3,4]],[[3,4]]]
</pre>
To set values at specific indices you can use the <tt>numeric.indexeq()</tt> function.
This takes as input an Array, an Array of indices, an Array of values, and sets
the contents of the Array in-place.
<pre>
IN> x = [[1,2],[3,4],[5,6]]; numeric.indexeq(x, [0,2], [[0,0],[2,2]]); x;
OUT> [[0,0],[3,4],[2,2]]
</pre>
<h1>Linear algebra</h1>
Matrix products are implemented in the functions
<tt>numeric.dotVV()</tt>
<tt>numeric.dotVM()</tt>
<tt>numeric.dotMV()</tt>
<tt>numeric.dotMM()</tt>:
<pre>
IN> numeric.dotVV([1,2],[3,4])
OUT> 11
IN> numeric.dotVM([1,2],[[3,4],[5,6]])
OUT> [13,16]
IN> numeric.dotMV([[1,2],[3,4]],[5,6])
OUT> [17,39]
IN> numeric.dotMMbig([[1,2],[3,4]],[[5,6],[7,8]])
OUT> [[19,22],
[43,50]]
IN> numeric.dotMMsmall([[1,2],[3,4]],[[5,6],[7,8]])
OUT> [[19,22],
[43,50]]
IN> numeric.dot([1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,9])
OUT> 285
</pre>
The function <tt>numeric.dot()</tt> is "polymorphic" and selects the appropriate Matrix product:
<pre>
IN> numeric.dot([1,2,3],[4,5,6])
OUT> 32
IN> numeric.dot([[1,2,3],[4,5,6]],[7,8,9])
OUT> [50,122]
</pre>
Solving the linear problem Ax=b (<a href="https://github.com/yuzeh">Dan Huang</a>):
<pre>
IN> numeric.solve([[1,2],[3,4]],[17,39])
OUT> [5,6]
</pre>
The algorithm is based on the LU decomposition:
<pre>
IN> LU = numeric.LU([[1,2],[3,4]])
OUT> {LU:[[3 ,4 ],
[0.3333,0.6667]],
P:[1,1]}
IN> numeric.LUsolve(LU,[17,39])
OUT> [5,6]
</pre>
<!--
Stress testing
<pre>
IN> ns = [5,6,10,16,25,40,41];
for(j=0;j<ns.length;j++) {
n = ns[j];
for(k=0;k<10;++k) {
A = numeric.random([n,n]);
x = numeric.random([n]);
b = numeric.dot(A,x);
y = numeric.solve(A,b);
if(!(numeric.norminf(numeric.sub(x,y))<1e-10)) throw new Error(
"numeric.solve Stress Test:"+numeric.prettyPrint({j:j,k:k,A:A,x:x,b:b,y:y}));
}
}
"numeric.solve Stress Test OK";
OUT> "numeric.solve Stress Test OK"