-
Notifications
You must be signed in to change notification settings - Fork 2
/
atom.xml
4760 lines (3735 loc) · 406 KB
/
atom.xml
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
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[SciRuby]]></title>
<link href="http://sciruby.com/atom.xml" rel="self"/>
<link href="http://sciruby.com/"/>
<updated>2021-02-21T12:50:48+05:30</updated>
<id>http://sciruby.com/</id>
<author>
<name><![CDATA[SciRuby]]></name>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[Tensors using NumRuby]]></title>
<link href="http://sciruby.com/blog/2021/02/16/tensors/"/>
<updated>2021-02-16T21:49:00+05:30</updated>
<id>http://sciruby.com/blog/2021/02/16/tensors</id>
<content type="html"><![CDATA[<p>Tensor word can have slightly different meaning depending upon the nature of study, like it’s defined differently in Physics, slightly different in computer science. In computer terms, it is basically a n-dimensional array. A scalar (one value) is a tensor with 0 dimensions, a vector is a tensor with 1 dimension, a matrix is a tensor with 2 dimensions.</p>
<p>It’s possible to define a tensor in Ruby using the <code>Array</code> class of Ruby but it gets tedious when defining multi-dimensional tensors. Also, the <code>Array</code> object is designed to be heterogeneous which means that the elements of the array can be of different type or different classes which would seem as a plus point overall but it has a huge downside. Due to <code>Array</code> being heterogeneous, the memory allocation has to be in such a way that any element of any size can be added or removed from the array, which causes a lot of re-allocations. Also, the indexing and other array functions gets slower due to the heterogeneous nature.</p>
<p>What if there’s a scenario where there is only one type of tensor elements, which means that a homogeneous array would also do, and there are memory and speed constraints? <code>NumRuby</code> is the solution for such requirements.</p>
<h2>Tensors in NumRuby</h2>
<p>A tensor can be defined using the <code>NMatrix</code> object of <code>NumRuby</code>.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">N</span> <span class="o">=</span> <span class="no">NMatrix</span><span class="o">.</span><span class="n">new</span> <span class="o">[</span><span class="n">shape</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="n">elements</span><span class="o">]</span><span class="p">,</span> <span class="ss">:type</span>
</span></code></pre></td></tr></table></div></figure>
<p><code>shape</code> is the number of dimensions and size of each dimension of the tensor. For example, <code>[2, 2, 2]</code> shape tensor is a tensor with 3 dimensions and each dimension of size 2, hence number of elements is 8. A sample value of elements array for this could be <code>[1, 2, 3, 4, 5, 6, 7, 8]</code>. <code>type</code> is the data type of each of the tensor element, it could be any of <code>:nm_bool</code>, <code>:nm_int</code>, <code>:nm_float32</code>, <code>:nm_float64</code>, <code>:nm_complex32</code> or <code>:nm_complex64</code> depending on the requirements.</p>
<p>An example usage is shown below:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="o">[</span><span class="mi">1</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span> <span class="o">=</span> <span class="no">NMatrix</span><span class="o">.</span><span class="n">new</span> <span class="o">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="o">]</span><span class="p">,</span> <span class="ss">:nm_int</span>
</span><span class='line'><span class="o">=></span>
</span><span class='line'><span class="o">[</span>
</span><span class='line'> <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'> <span class="o">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="o">]</span>
</span><span class='line'><span class="o">]</span>
</span><span class='line'><span class="o">[</span><span class="mi">2</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span><span class="o">.</span><span class="n">elements</span>
</span><span class='line'><span class="o">=></span> <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="o">]</span>
</span><span class='line'><span class="o">[</span><span class="mi">3</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span><span class="o">.</span><span class="n">shape</span>
</span><span class='line'><span class="o">=></span> <span class="o">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="o">]</span>
</span><span class='line'><span class="o">[</span><span class="mi">4</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span><span class="o">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="o">]</span>
</span><span class='line'><span class="o">=></span> <span class="mi">1</span>
</span><span class='line'><span class="o">[</span><span class="mi">5</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span><span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="o">]</span>
</span><span class='line'><span class="o">=></span> <span class="mi">3</span>
</span><span class='line'><span class="o">[</span><span class="mi">6</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span><span class="o">.</span><span class="n">dtype</span>
</span><span class='line'><span class="o">=></span> <span class="ss">:nm_int</span>
</span></code></pre></td></tr></table></div></figure>
<h2>Elementwise Operations</h2>
<p>One can also perform elementwise operations using <code>NumRuby</code>. Elementwise operations are broadly of 2 types, Uni-operand and bi-operand.</p>
<h3>Uni-Operand Operations</h3>
<p>Uni-operand operators are those that apply to just one tensor. For example, sine, cos or tan of each of element of the tensor.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="o">[</span><span class="mi">1</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span> <span class="o">=</span> <span class="no">NMatrix</span><span class="o">.</span><span class="n">new</span> <span class="o">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="o">]</span><span class="p">,</span> <span class="ss">:nm_float64</span>
</span><span class='line'><span class="o">=></span>
</span><span class='line'><span class="o">[</span>
</span><span class='line'> <span class="o">[</span><span class="mi">1</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'> <span class="o">[</span><span class="mi">3</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span>
</span><span class='line'><span class="o">]</span>
</span><span class='line'><span class="o">[</span><span class="mi">2</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span><span class="o">.</span><span class="n">sin</span>
</span><span class='line'><span class="o">=></span>
</span><span class='line'><span class="o">[</span>
</span><span class='line'> <span class="o">[</span><span class="mi">0</span><span class="o">.</span><span class="mi">8414709848078965</span><span class="p">,</span> <span class="mi">0</span><span class="o">.</span><span class="mi">9092974268256817</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'> <span class="o">[</span><span class="mi">0</span><span class="o">.</span><span class="mi">1411200080598672</span><span class="p">,</span> <span class="o">-</span><span class="mi">0</span><span class="o">.</span><span class="mi">7568024953079282</span><span class="o">]</span>
</span><span class='line'><span class="o">]</span>
</span><span class='line'><span class="o">[</span><span class="mi">3</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span><span class="o">.</span><span class="n">cos</span>
</span><span class='line'><span class="o">=></span>
</span><span class='line'><span class="o">[</span>
</span><span class='line'> <span class="o">[</span> <span class="mi">0</span><span class="o">.</span><span class="mi">5403023058681398</span><span class="p">,</span> <span class="o">-</span><span class="mi">0</span><span class="o">.</span><span class="mi">4161468365471424</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'> <span class="o">[-</span><span class="mi">0</span><span class="o">.</span><span class="mi">9899924966004454</span><span class="p">,</span> <span class="o">-</span><span class="mi">0</span><span class="o">.</span><span class="mi">6536436208636119</span><span class="o">]</span>
</span><span class='line'><span class="o">]</span>
</span></code></pre></td></tr></table></div></figure>
<h3>Bi-Operand Operations</h3>
<p>Bi-operand operators are those that apply to two tensor. For example, addition, subtraction or multiplication of each of the corresponding elements of the the 2 tensor.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="o">[</span><span class="mi">1</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span> <span class="o">=</span> <span class="no">NMatrix</span><span class="o">.</span><span class="n">new</span> <span class="o">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="o">]</span><span class="p">,</span> <span class="ss">:nm_float64</span>
</span><span class='line'><span class="o">=></span>
</span><span class='line'><span class="o">[</span>
</span><span class='line'> <span class="o">[</span><span class="mi">1</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'> <span class="o">[</span><span class="mi">3</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span>
</span><span class='line'><span class="o">]</span>
</span><span class='line'><span class="o">[</span><span class="mi">2</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">M</span> <span class="o">=</span> <span class="no">NMatrix</span><span class="o">.</span><span class="n">new</span> <span class="o">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="o">]</span><span class="p">,</span> <span class="ss">:nm_float64</span>
</span><span class='line'><span class="o">=></span>
</span><span class='line'><span class="o">[</span>
</span><span class='line'> <span class="o">[</span><span class="mi">2</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'> <span class="o">[</span><span class="mi">3</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span>
</span><span class='line'><span class="o">]</span>
</span><span class='line'><span class="o">[</span><span class="mi">3</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span><span class="o">+</span><span class="n">M</span>
</span><span class='line'><span class="o">=></span>
</span><span class='line'><span class="o">[</span>
</span><span class='line'> <span class="o">[</span><span class="mi">3</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'> <span class="o">[</span><span class="mi">6</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">7</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span>
</span><span class='line'><span class="o">]</span>
</span><span class='line'><span class="o">[</span><span class="mi">4</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span><span class="o">*</span><span class="n">M</span>
</span><span class='line'><span class="o">=></span>
</span><span class='line'><span class="o">[</span>
</span><span class='line'> <span class="o">[</span><span class="mi">2</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'> <span class="o">[</span><span class="mi">9</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">12</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span>
</span><span class='line'><span class="o">]</span>
</span></code></pre></td></tr></table></div></figure>
<h2>Linear Algebra</h2>
<p><code>NumRuby</code> also supports linear algebra capabilities for 2-dimensional tensors. One can easily do operations such as matrix inverse, dot product, matrix decompositions.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="o">[</span><span class="mi">1</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span> <span class="o">=</span> <span class="no">NMatrix</span><span class="o">.</span><span class="n">new</span> <span class="o">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="o">]</span><span class="p">,</span> <span class="ss">:nm_float64</span>
</span><span class='line'><span class="o">=></span>
</span><span class='line'><span class="o">[</span>
</span><span class='line'> <span class="o">[</span><span class="mi">1</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'> <span class="o">[</span><span class="mi">3</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span>
</span><span class='line'><span class="o">]</span>
</span><span class='line'><span class="o">[</span><span class="mi">2</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">M</span> <span class="o">=</span> <span class="no">NMatrix</span><span class="o">.</span><span class="n">new</span> <span class="o">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="o">]</span><span class="p">,</span> <span class="ss">:nm_float64</span>
</span><span class='line'><span class="o">=></span>
</span><span class='line'><span class="o">[</span>
</span><span class='line'> <span class="o">[</span><span class="mi">2</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'> <span class="o">[</span><span class="mi">3</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span>
</span><span class='line'><span class="o">]</span>
</span><span class='line'><span class="o">[</span><span class="mi">3</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">M</span><span class="p">)</span>
</span><span class='line'><span class="o">=></span>
</span><span class='line'><span class="o">[</span>
</span><span class='line'> <span class="o">[</span> <span class="mi">8</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">8</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'> <span class="o">[</span><span class="mi">18</span><span class="o">.</span><span class="mi">0</span><span class="p">,</span> <span class="mi">18</span><span class="o">.</span><span class="mi">0</span><span class="o">]</span>
</span><span class='line'><span class="o">]</span>
</span><span class='line'><span class="o">[</span><span class="mi">4</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span><span class="o">.</span><span class="n">invert</span>
</span><span class='line'><span class="o">=></span>
</span><span class='line'><span class="o">[</span>
</span><span class='line'> <span class="o">[-</span><span class="mi">1</span><span class="o">.</span><span class="mi">9999999999999996</span><span class="p">,</span> <span class="mi">0</span><span class="o">.</span><span class="mi">9999999999999998</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'> <span class="o">[</span> <span class="mi">1</span><span class="o">.</span><span class="mi">4999999999999998</span><span class="p">,</span> <span class="o">-</span><span class="mi">0</span><span class="o">.</span><span class="mi">4999999999999999</span><span class="o">]</span>
</span><span class='line'><span class="o">]</span>
</span><span class='line'><span class="o">[</span><span class="mi">5</span><span class="o">]</span> <span class="n">pry</span><span class="p">(</span><span class="n">main</span><span class="p">)</span><span class="o">></span> <span class="n">N</span><span class="o">.</span><span class="n">det</span>
</span><span class='line'><span class="o">=></span> <span class="o">-</span><span class="mi">2</span><span class="o">.</span><span class="mi">0</span>
</span></code></pre></td></tr></table></div></figure>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[GSoC 2019 : Adding ImageMagick backend, IRuby support and additional functionalities to Rubyplot]]></title>
<link href="http://sciruby.com/blog/2019/08/29/gsoc-2019-rubyplot/"/>
<updated>2019-08-29T02:24:00+05:30</updated>
<id>http://sciruby.com/blog/2019/08/29/gsoc-2019-rubyplot</id>
<content type="html"><![CDATA[<p><strong>Table of Contents</strong>
* TOC
{:toc}</p>
<h1>Introduction</h1>
<p>With GSoC 2019 coming to an end, this is my final blog which mentions all my work for the project Rubyplot.</p>
<h1>What is Rubyplot?</h1>
<p>RubyPlot is a plotting library in Ruby for scientific development inspired by the library Matplotlib for Python. Users can create various types of plots like scatter plot, bar plot, etc. and can also create subplots which combine various of these plots. The long-term goal of the library is to build an efficient, scalable and user-friendly library with a backend-agnostic frontend to support various backends so that the library can be used on any device.</p>
<h2>Examples</h2>
<p>Creating graphs in Rubyplot is very simple and can be done in just a few lines of code, for example:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="nb">require</span> <span class="s1">'rubyplot'</span>
</span><span class='line'>
</span><span class='line'><span class="n">figure</span> <span class="o">=</span> <span class="no">Rubyplot</span><span class="o">::</span><span class="no">Figure</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="ss">width</span><span class="p">:</span> <span class="mi">30</span><span class="p">,</span> <span class="ss">height</span><span class="p">:</span> <span class="mi">30</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="n">axes00</span> <span class="o">=</span> <span class="n">figure</span><span class="o">.</span><span class="n">add_subplot!</span> <span class="mi">0</span><span class="p">,</span><span class="mi">0</span>
</span><span class='line'><span class="n">axes00</span><span class="o">.</span><span class="n">plot!</span> <span class="k">do</span> <span class="o">|</span><span class="nb">p</span><span class="o">|</span>
</span><span class='line'> <span class="n">d</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="o">.</span><span class="n">.</span><span class="mi">360</span><span class="p">)</span><span class="o">.</span><span class="n">step</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span><span class="o">.</span><span class="n">to_a</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">data</span> <span class="n">d</span><span class="p">,</span> <span class="n">d</span><span class="o">.</span><span class="n">map</span> <span class="p">{</span> <span class="o">|</span><span class="n">a</span><span class="o">|</span> <span class="no">Math</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">a</span> <span class="o">*</span> <span class="no">Math</span><span class="o">::</span><span class="no">PI</span> <span class="o">/</span> <span class="mi">180</span><span class="p">)</span> <span class="p">}</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">fmt</span> <span class="o">=</span> <span class="s1">'ok-'</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">marker_fill_color</span> <span class="o">=</span> <span class="ss">:white</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">marker_size</span> <span class="o">=</span> <span class="mi">0</span><span class="o">.</span><span class="mi">5</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">line_width</span> <span class="o">=</span> <span class="mi">2</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="s2">"sine"</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="n">axes00</span><span class="o">.</span><span class="n">title</span> <span class="o">=</span> <span class="s2">"A plot function example"</span>
</span><span class='line'><span class="n">axes00</span><span class="o">.</span><span class="n">square_axes</span> <span class="o">=</span> <span class="kp">false</span>
</span><span class='line'>
</span><span class='line'><span class="n">figure</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'example1.png'</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>
<p>Has the output:<br/>
<img src="https://raw.githubusercontent.com/alishdipani/alishdipani.github.io/master/_posts/Resources/Wrapping_up_GSoC_2019/example1.png" alt="Example1" /></p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="nb">require</span> <span class="s1">'rubyplot'</span>
</span><span class='line'>
</span><span class='line'><span class="n">figure</span> <span class="o">=</span> <span class="no">Rubyplot</span><span class="o">::</span><span class="no">Figure</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="ss">width</span><span class="p">:</span> <span class="mi">30</span><span class="p">,</span> <span class="ss">height</span><span class="p">:</span> <span class="mi">30</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="n">axes00</span> <span class="o">=</span> <span class="n">figure</span><span class="o">.</span><span class="n">add_subplot!</span> <span class="mi">0</span><span class="p">,</span><span class="mi">0</span>
</span><span class='line'><span class="n">axes00</span><span class="o">.</span><span class="n">candle_stick!</span> <span class="k">do</span> <span class="o">|</span><span class="nb">p</span><span class="o">|</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">lows</span> <span class="o">=</span> <span class="o">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">10</span><span class="o">]</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">highs</span> <span class="o">=</span> <span class="o">[</span><span class="mi">40</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="mi">60</span><span class="p">,</span> <span class="mi">70</span><span class="p">,</span> <span class="mi">60</span><span class="p">,</span> <span class="mi">50</span><span class="o">]</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">opens</span> <span class="o">=</span> <span class="o">[</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">20</span><span class="o">]</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">closes</span> <span class="o">=</span> <span class="o">[</span><span class="mi">30</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="mi">60</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="mi">40</span><span class="o">]</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">color</span> <span class="o">=</span> <span class="ss">:yellow</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'><span class="n">axes00</span><span class="o">.</span><span class="n">candle_stick!</span> <span class="k">do</span> <span class="o">|</span><span class="nb">p</span><span class="o">|</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">lows</span> <span class="o">=</span> <span class="o">[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">25</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="o">]</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">highs</span> <span class="o">=</span> <span class="o">[</span><span class="mi">50</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">65</span><span class="p">,</span> <span class="mi">70</span><span class="p">,</span> <span class="mi">80</span><span class="p">,</span> <span class="mi">60</span><span class="o">]</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">opens</span> <span class="o">=</span> <span class="o">[</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">20</span><span class="o">]</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">closes</span> <span class="o">=</span> <span class="o">[</span><span class="mi">35</span><span class="p">,</span> <span class="mi">35</span><span class="p">,</span> <span class="mi">45</span><span class="p">,</span> <span class="mi">60</span><span class="p">,</span> <span class="mi">75</span><span class="p">,</span> <span class="mi">50</span><span class="o">]</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">color</span> <span class="o">=</span> <span class="ss">:blue</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="n">axes00</span><span class="o">.</span><span class="n">title</span> <span class="o">=</span> <span class="s2">"A multi candle-stick plot"</span>
</span><span class='line'><span class="n">axes00</span><span class="o">.</span><span class="n">square_axes</span> <span class="o">=</span> <span class="kp">false</span>
</span><span class='line'>
</span><span class='line'><span class="n">figure</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'example2.png'</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>
<p>Has the output:<br/>
<img src="https://raw.githubusercontent.com/alishdipani/alishdipani.github.io/master/_posts/Resources/Wrapping_up_GSoC_2019/example2.png" alt="Example2" /></p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="nb">require</span> <span class="s1">'rubyplot'</span>
</span><span class='line'>
</span><span class='line'><span class="n">figure</span> <span class="o">=</span> <span class="no">Rubyplot</span><span class="o">::</span><span class="no">Figure</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="ss">width</span><span class="p">:</span> <span class="mi">30</span><span class="p">,</span> <span class="ss">height</span><span class="p">:</span> <span class="mi">30</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="n">axes00</span> <span class="o">=</span> <span class="n">figure</span><span class="o">.</span><span class="n">add_subplot!</span> <span class="mi">0</span><span class="p">,</span><span class="mi">0</span>
</span><span class='line'><span class="n">axes00</span><span class="o">.</span><span class="n">bar!</span> <span class="k">do</span> <span class="o">|</span><span class="nb">p</span><span class="o">|</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">data</span> <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="o">]</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">color</span> <span class="o">=</span> <span class="ss">:lemon</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">spacing_ratio</span> <span class="o">=</span> <span class="mi">0</span><span class="o">.</span><span class="mi">2</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'><span class="n">axes00</span><span class="o">.</span><span class="n">bar!</span> <span class="k">do</span> <span class="o">|</span><span class="nb">p</span><span class="o">|</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">data</span> <span class="o">[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="o">]</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">color</span> <span class="o">=</span> <span class="ss">:blue</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'><span class="n">axes00</span><span class="o">.</span><span class="n">bar!</span> <span class="k">do</span> <span class="o">|</span><span class="nb">p</span><span class="o">|</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">data</span> <span class="o">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">3</span><span class="o">]</span>
</span><span class='line'> <span class="nb">p</span><span class="o">.</span><span class="n">color</span> <span class="o">=</span> <span class="ss">:red</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="n">axes00</span><span class="o">.</span><span class="n">title</span> <span class="o">=</span> <span class="s2">"A multi bar plot"</span>
</span><span class='line'><span class="n">axes00</span><span class="o">.</span><span class="n">square_axes</span> <span class="o">=</span> <span class="kp">false</span>
</span><span class='line'>
</span><span class='line'><span class="n">figure</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'example3.png'</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>
<p>Has the output:<br/>
<img src="https://raw.githubusercontent.com/alishdipani/alishdipani.github.io/master/_posts/Resources/Wrapping_up_GSoC_2019/example3.png" alt="Example3" /></p>
<h1>History of Rubyplot</h1>
<p>Rubyplot started as two GSoC 2018 projects by Pranav Garg<a href="https://github.com/pgtgrly">(@pgtgrly)</a> and Arafat Dad Khan<a href="https://github.com/Arafatk">(@Arafatk)</a> and the mentors from The Ruby Science Foundation<a href="http://sciruby.com/">(SciRuby)</a>, Sameer Deshmukh<a href="https://github.com/v0dro">(@v0dro)</a>, John Woods<a href="https://github.com/mohawkjohn">(@mohawkjohn)</a> and Pjotr Prins<a href="https://github.com/pjotrp">(@pjotrp)</a>. Pranav Garg worked on the GRRuby which had the GR backend and Arafat Dad Khan worked on Ruby Matplotlib which had the ImageMagick backend. The ultimate goal of combining both and creating Rubyplot. After GSoC 2018, Sameer Deshmukh combined both projects and created Rubyplot and he has maintained it ever since. Around May 2019, I started working on Rubyplot as a part of GSoC 2019.</p>
<h1>GSoC 2019</h1>
<p>As a part of GSoC 2019, my project had 3 major deliverables:
1. <strong>ImageMagick support</strong>(Phase 1): Support for ImageMagick back-end will be added in addition to the currently supported back-end GR, the front-end of the library will be back-end agnostic and the current overall integrity of the library will be preserved.<br/>
2. <strong>Plotting and show function</strong>(Phase 2): A new plot function will be added which plots markers (for example circles) to form a scatter plot with the points as inputs (same as plot function in Matplotlib). A new function show will be added which will allow viewing of a plot without saving it. This plot function will be back-end agnostic and hence will support both GR and Magick back-end.<br/>
3. <strong>Integration with iruby notebooks</strong>(Phase 3): Rubyplot will be integrated with iruby notebooks supporting all backends and allowing inline plotting.</p>
<p>As a part of GSoC 2019, I completed all the deliverables I had initially planned along with a tutorial for the library and some other general improvements.<br/>
Details of my work are as follows:</p>
<h2>Phase 1</h2>
<p>During Phase 1, I focused on setting up the ImageMagick backend which involved the basic functionality required for any backend of the library which are X-axis and Y-axis transform functions, <code>within_window</code> function which is responsible for placing the plots in the correct position, function for drawing the X and Y axis, functions for drawing the text and scaling the figure according to the dimensions given by the user. I implemented these functions using internal rmagick functions which were very useful like <code>scale</code>, <code>translate</code>, <code>rotate</code>, etc.<br/>
After this, I worked on the scatter plot, which was the first plot I ever worked on. This plot had a very particular and interesting problem, which was that different types of markers were internally implemented in the GR backend, but for ImageMagick backend, I had to implement everything using basic shapes like circles, lines, polygons and rectangles. To solve this I created a hash of lambdas which had the code to create different types of markers using the basic shapes.<br/>
After this I implemented all the simple plots which Rubyplot supports, these are line plot, area plot, bar plot, histogram, box plot, bubble plot, candle-stick plot and error-bar plot.</p>
<p>So, during Phase 1, I completed the following deliverables -<br/>
1. Set up the ImageMagick backend to have the basic functionality.<br/>
2. Implemented and tested the simple plots in Rubyplot which are scatter plot, line plot, area plot, bar plot, histogram, box plot, bubble plot, candle-stick plot and error-bar plot.</p>
<p>Code for Phase 1 can be found <a href="https://github.com/SciRuby/rubyplot/pull/45/files/01a26777175c83e3e44a33d5ac5d6544b8ff9353..95f24730e04eb13460ed088dcf7569848b66a2ea">here</a>.</p>
<h2>Phase 2</h2>
<p>I started Phase 2 by implementing the multi plots which are multi stack-bar plot, multi-bar plot, multi-box plot and multi candle-stick plot.<br/>
Next, I implemented the <code>plot</code> function which is a combination of scatter plot and line plot, using the plot function the user can easily create a scatter plot or a line plot or a combination of both. The most interesting feature of the <code>plot</code> function is the <code>fmt</code> argument which sets the marker type, line type and the colour of the plot using just characters, so instead of writing the name of the type and setting the variables, the user can simply input a string in <code>fmt</code> argument which has the characters for corresponding marker type, line type and colour.<br/>
Next was to implement the <code>show</code> function which is an alternative to <code>write</code> function. It draws the Figure and shows it on a temporary pop-up window without the need of saving the Figure on the device, this allows the user to test the code quickly and easily. This was done by using internal functions of the backends which are <code>display</code> for ImageMagick and <code>gr_updatews</code> for GR.</p>
<p>So, during Phase 2, I completed the following deliverables -<br/>
1. Implemented and tested the multi plots in Rubyplot which are multi stack-bar plot, multi-bar plot, multi-box plot and multi candle-stick plot.<br/>
2. Implemented and tested the <code>plot</code> function with fmt argument.<br/>
3. Implemented and tested the <code>show</code> function.</p>
<p>Code for Phase 2 can be found <a href="https://github.com/SciRuby/rubyplot/pull/45/files/36497cc3fdb6b9eddaee51777509d1f388a8ba4a..f918e9c9f390cfa96e453f3db610eeaa8f3acbed">here</a> and <a href="https://github.com/SciRuby/rubyplot/pull/52/files/21d2450229ce8508f8a906914fd4bf47e1c62fa3..5947c911d290f34a09effca5ce3e866519b8c5db">here</a>.</p>
<h2>Phase 3</h2>
<p>During Phase 3, I integrated Rubyplot with the IRuby notebooks which allow the user to draw figures inside the notebook just by using the <code>show</code> function, through this integration the user can quickly and easily test the code step by step before running the whole codebase.<br/>
I also implemented ticks for ImageMagick backend.<br/>
Finally, I created a tutorial for the library which also contains template codes for all the plots which a user can easily get familiar with the working of the library and start using it.</p>
<p>So, during Phase 3, I completed the following deliverables -<br/>
1. Integrated Rubyplot with IRuby notebooks with the support for inline plotting.<br/>
2. Implemented and tested ticks for Magick backend.<br/>
3. Created the tutorial for Rubyplot.</p>
<p>Code for Phase 3 can be found <a href="https://github.com/SciRuby/rubyplot/pull/52/files/ca2aa7397581eaf92b64522361e3565f032e6250..3624962d8f96e3611c6bbc55a5c2c8aa1a299e27">here</a>.</p>
<h1>Resources(blogs, code, etc.)</h1>
<h2>Previous Work</h2>
<ul>
<li>GSoC 2018 project GRRuby by Pranav Garg can be found <a href="https://github.com/pgtgrly/GRruby-extension">here</a></li>
<li>GSoC 2018 project Ruby Matplotlib by Arafat Dad Khan can be found <a href="https://github.com/Arafatk/magick-rubyplot">here</a></li>
<li>A talk on Rubyplot by Pranav Garg in RubyConf 2018 can be found <a href="https://youtu.be/7QBkckZ1aNQ">here</a></li>
</ul>
<h2>My work</h2>
<ul>
<li>Daily updates can be found <a href="https://discourse.ruby-data.org/t/gsoc-2019-project-rubyplot-discussion/57">here</a></li>
<li>Proposal can be found <a href="https://github.com/alishdipani/rubyplot/wiki/GSoC-2019-Proposal">here</a></li>
<li>Tutorial notebook can be found <a href="https://github.com/alishdipani/rubyplot/blob/master/tutorial/magick/Rubyplot_Tutorial(Magick">here</a>.ipynb) and can be viewed online(rendered) <a href="https://nbviewer.jupyter.org/github/alishdipani/rubyplot/blob/master/tutorial/magick/Rubyplot_Tutorial%28Magick%29.ipynb">here</a></li>
<li>Rubyplot Github Repository can be found <a href="https://github.com/SciRuby/rubyplot">here</a></li>
<li>All my work can be found in these PRs: <a href="https://github.com/SciRuby/rubyplot/pull/45">PR#45</a> and <a href="https://github.com/SciRuby/rubyplot/pull/52">PR#52</a></li>
<li>Other blogs can be found here:
<ol>
<li><a href="https://alishdipani.github.io/gsoc2019/2019/06/08/GSoC-2019-project-introduction/">GSoC 2019 project introduction</a></li>
<li><a href="https://alishdipani.github.io/gsoc2019/2019/06/09/Rubyplot-installation-guide/">Rubyplot installation guide</a></li>
<li><a href="https://alishdipani.github.io/gsoc2019/2019/06/10/The-Scatter-plot-example/">The Scatter plot example</a></li>
<li><a href="https://alishdipani.github.io/gsoc2019/2019/06/28/Simple-Plots-in-Rubyplot/">Simple Plots in Rubyplot</a></li>
<li><a href="https://alishdipani.github.io/gsoc2019/2019/07/13/Multi-plots-in-Rubyplot/">Multi plots in Rubyplot</a></li>
<li><a href="https://alishdipani.github.io/gsoc2019/2019/07/26/The-show-and-the-plot-functions/">The show and the plot functions</a></li>
<li><a href="https://alishdipani.github.io/gsoc2019/2019/08/22/IRuby-integration-and-ticks/">IRuby integration and ticks</a></li>
</ol>
</li>
</ul>
<h1>Future Work</h1>
<p>I plan to keep contributing to Rubyplot and also start contributing to other projects of SciRuby.<br/>
Future work to be done for Rubyplot is to write documentation, add more tests, add more types of plots, add more backends, make the plots interactive and in future add the feature for plotting 3-Dimensional graphs which would also be interactive.</p>
<h1>EndNote</h1>
<p>With this, we come to an end of GSoC 2019. These 3 months have been very challenging, interesting, exciting and fun. I got to learn a lot of things while working on Rubyplot and while interacting with my mentors. I have experienced an improvement in my Software development skills and programming in general which will help me a lot in future. I would love to keep working with SciRuby on more such interesting projects and maybe even try for GSoC again next year ;)</p>
<h1>Acknowledgements</h1>
<p>I would like to express my gratitude to my mentor Sameer Deshmukh for his guidance and support. He was always available and had solutions to every problem I faced, I got to learn a lot from him and I hope to learn a lot more from him in the future. I could not have asked for a better mentor.</p>
<p>I would also like to thank Pranav Garg who introduced me to Ruby and also to the SciRuby community. During his GSoC 2018 project, he introduced me to the Rubyplot library and helped me get started with it. His suggestions were very helpful during my GSoC 2019 project.</p>
<p>I would also like to thank mentors from SciRuby Prasun Anand and Shekhar Prasad Rajak for mentoring me and organising the occasional meetings and code reviews. I would also like to thank Udit Gulati for his helpful insights during the code reviews.</p>
<p>I am grateful to Google and the Ruby Science Foundation for this golden opportunity.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[GSoC 2019: Adding features to NMatrix core]]></title>
<link href="http://sciruby.com/blog/2019/08/26/gsoc-2019-adding-features-to-nmatrix-core/"/>
<updated>2019-08-26T23:49:00+05:30</updated>
<id>http://sciruby.com/blog/2019/08/26/gsoc-2019-adding-features-to-nmatrix-core</id>
<content type="html"><![CDATA[<p>The GSoC coding period has come to an end. It’s been quite a learning experience for me and has given me an opportunity to come out of my comfort zone and explore new things. I feel quite delighted knowing that I have contributed a significant amount to the project. This post summarizes my work on <a href="https://github.com/sciruby/numruby">NumRuby</a> during the GSoC period.</p>
<p>GSoC 2019 proposal - <a href="https://docs.google.com/document/d/1MR01QZeX_8h7a16nmkOYlyrVt--osB1Yg9Vo0xXYtSw/edit?usp=sharing">https://docs.google.com/document/d/1MR01QZeX_8h7a16nmkOYlyrVt–osB1Yg9Vo0xXYtSw/edit?usp=sharing</a></p>
<h2>Pull requests</h2>
<ul>
<li>Indexing, iterating, slicing - <a href="https://github.com/SciRuby/numruby/pull/19">https://github.com/SciRuby/numruby/pull/19</a></li>
<li>Fix compiler warnings - <a href="https://github.com/SciRuby/numruby/pull/21">https://github.com/SciRuby/numruby/pull/21</a></li>
<li>Dimensional iterators - <a href="https://github.com/SciRuby/numruby/pull/22">https://github.com/SciRuby/numruby/pull/22</a></li>
<li>Broadcasting - <a href="https://github.com/SciRuby/numruby/pull/23">https://github.com/SciRuby/numruby/pull/23</a></li>
<li>Lapack wrappers - <a href="https://github.com/SciRuby/numruby/pull/26">https://github.com/SciRuby/numruby/pull/26</a></li>
<li>NumRuby::Linalg - <a href="https://github.com/SciRuby/numruby/pull/30">https://github.com/SciRuby/numruby/pull/30</a></li>
</ul>
<h2>Blog Posts</h2>
<ul>
<li>GSoC project introduction - <a href="https://uditgulati.github.io/blog/open-source/2019/05/21/gsoc-project-introduction-nmatrix.html">https://uditgulati.github.io/blog/open-source/2019/05/21/gsoc-project-introduction-nmatrix.html</a></li>
<li>GSoC weeks 1, 2 - <a href="https://uditgulati.github.io/blog/open-source/2019/06/10/gsoc-week-1-2.html">https://uditgulati.github.io/blog/open-source/2019/06/10/gsoc-week-1-2.html</a></li>
<li>GSoC weeks 3, 4 - <a href="https://uditgulati.github.io/blog/open-source/2019/06/26/gsoc-week-3-4.html">https://uditgulati.github.io/blog/open-source/2019/06/26/gsoc-week-3-4.html</a></li>
<li>GSoC weeks 5, 6 - <a href="https://uditgulati.github.io/blog/open-source/2019/07/10/gsoc-week-5-6.html">https://uditgulati.github.io/blog/open-source/2019/07/10/gsoc-week-5-6.html</a></li>
<li>GSoC weeks 7, 8 - <a href="https://uditgulati.github.io/blog/open-source/2019/07/25/gsoc-week-7-8.html">https://uditgulati.github.io/blog/open-source/2019/07/25/gsoc-week-7-8.html</a></li>
<li>GSoC weeks 9, 10 - <a href="https://uditgulati.github.io/blog/open-source/2019/08/16/gsoc-week-9-10.html">https://uditgulati.github.io/blog/open-source/2019/08/16/gsoc-week-9-10.html</a></li>
</ul>
<h2>Future work</h2>
<ul>
<li>As these features are core to NMatrix, they need to be tested more tightly and benchmarked. Also, since this is the first implementation of the features, some modifications can make these features more reliable and faster.</li>
<li>More iterators are to be implemented in order to have a richer NMatrix API.</li>
<li>The issue with slicing needs to be fixed soon. Also, need to standardize the formatting used for slice range specification.</li>
<li>Broadcasting needs to be tested and benchmarked. This will let us improve it’s reliability and performance. A few APIs could be exposed which would let a user manually broadcast a matrix to a given shape.</li>
<li>NumRuby::Lapack needs to have proper exception handling for LAPACK routines. This will be done by reading the info value returned by routine and raising exception accordingly.</li>
<li>NumRuby::Linalg can be extended to have even more methods.</li>
</ul>
<h2>Acknowledgements</h2>
<p>I wanna thank Ruby Science Foundation, all mentors and org admins for providing me this wonderful opportunity to enhance my knowledge and work on a project. I would also like to thank Google for organizing such a wonderful program due to which I got introduced to Open-source and Ruby Science Foundation. I especially want to thank my mentor Prasun Anand for guiding me through this period, keeping me motivated and for tolerating my procrastination.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[GSoC 2018: RubyPlot GR - A Scientific Plotting Library for Ruby Built on GR Framework]]></title>
<link href="http://sciruby.com/blog/2019/01/23/gsoc-2018-rubyplot+-gr-+a-scientific-plotting-library-for-ruby-built-on-gr/"/>
<updated>2019-01-23T18:00:00+05:30</updated>
<id>http://sciruby.com/blog/2019/01/23/gsoc-2018-rubyplot -gr- a-scientific-plotting-library-for-ruby-built-on-gr</id>
<content type="html"><![CDATA[<h3>1. About</h3>
<p>For my summer of code Project I decided to create a plotting library.</p>
<p>From scratch.</p>
<p>In Ruby.</p>
<h3>2. Application</h3>
<p>The GSoC 2018 application can be found <a href="https://github.com/pgtgrly/Cairo_Graph/wiki/Google-Summer-of-Code-2018-Application">here</a>.</p>
<h3>3. Code</h3>
<p>The code for the project can be found <a href="https://github.com/pgtgrly/GRruby-extension">here</a>.</p>
<p>RubyPlot is currently being developed <a href="https://github.com/SciRuby/rubyplot">here</a>.</p>
<h3>3. The Plotting Architecture</h3>
<p>The plotting architecture for the library was inspired by Late Dr John Hunter’s Python Plotting Library “Matplotlib”.</p>
<p>The Matplotlib Architecture is be broadly divided into three layers (as shown in the masterpiece of a figure which I made below). The Backend, The Artist and the scripting layer.</p>
<p>The Backend layer can further be divided into three parts : The Figure Canvas, The Renderer and the Event.</p>
<p>Matplotlib architecture is mostly written in Python with some of its backend (the renderer AGG and Figure canvas ) written in C++ ( The original AGG backend and helper scripts, which is quite tightly bound to python). But the recently the backends are also written in Python using the renderers which have Python APIs. The finer details of the Architecture can be found <a href="https://aosabook.org/en/matplotlib.html">here</a>.</p>
<p>In interest of the time I decided to go for a iterative process to develop the Library. I decided to use an existing Artist layer. After a lot of discussion we decided to use GR Framework for the same. The only issue was that GR did not have a Ruby API.</p>
<h3>4. Creating C extensions for GR Framework:</h3>
<p>To create the C extensions I initially decided to use Fiddle followed by FFi. But this lead to certain issues when it came to handling arrays. Hence I decided to go with the old fashioned Ruby C API to create extensions. The code for the same can be found <a href="https://github.com/pgtgrly/GRruby-extension/tree/master/ext/grruby">here</a>.</p>
<h3>5. Creating Scripting Layer</h3>
<p>The Scripting Layer Is meant for high level plotting. The scripting Library created on the GR Framework wrapper has the can plot the following:</p>
<ul>
<li><p>ScatterPlots</p></li>
<li><p>Line graphs</p></li>
<li><p>Bar Plots</p></li>
<li><p>Stacked Bar plot</p></li>
<li><p>Stacked Bar plot (Stacked along z axis)</p></li>
<li><p>Candlestick plots</p>
<p>All the above plots have a lot of customisation options, that can be looked into in the documentation.</p></li>
</ul>
<p>Each Figure can have multiple subplots, each subplot can have multiple plots</p>
<h3>6. Working of the Library</h3>
<p>Here is how the library works.</p>
<p><img src="https://i.imgur.com/sdNg7av.png" alt="Imgur" /></p>
<p>Figure is the class that a user instantiates this is where all the plotting take place. An instance contains the state of the figure. GR framework is used as the artist layer which does all the plotting on the figure. GR is also the backend.</p>
<p>GR artist layer functions are implemented in C language, we wrap the functions to ruby classes which have the call method which executes the GR function when the Object of the ruby class is called.
Each of these ruby classes are called tasks which represents that they perform a task, for example ClearWorkspace performs the task of cleaning the workspace.</p>
<p>Now, the figure is divided into subplots. It is Subplot(1,1,1) by default. So, figure has objects of subplot, each subplot is of type bar plot or line plot etc. These plots are defined in the Plots module which is submodule of Scripting module, the Plots module has a submodule named BasePlots which defines the two bases of plots, LazyBase and RobustBase.
Lazy base is for plots which are dependent on state of the figure, for example a bar graph depends on the location of axes. Every lazy plot has a unique call function rather than inheriting it from LazyBase. In LazyPlots the instances of GR Function Classes are called as soon as they are instantiated. This all is done in the call function.
Robust base is for plots which are which are independent of the state of the Figure. For example: A scatter plot is independent of the location of axes. Plots which are Sub classes of RobustBase append the instances of GR function classes to tasks when initialized. These instances are called via the call method defined in RobustBase.</p>
<p>So, each subplot which is of type bar plot or scatter plots etc. inherits a base. Now, each subplot is just a collection of some tasks, so it has a task list which stores the tasks to be performed i.e. the Task objects, for example Scatter plot has tasks SetMarkerColorIndex which sets the color of the marker, SetMarkerSize which sets the size of the marker, SetMarkerType which sets the type of the marker and Polymarker which marks the marker of defined color, size and style.
Whenever a new Subplot object is initialized, for example subplot(r,c,i), the figure is divided into a matrix with r rows and c columns and the subplot initialized with index i is set as the active subplot ans this active subplot is pushed into the subplot list. Each subplot object has a unique identity (r,c,i) so if the user wants to access a subplot which is already declared, this identity will be used. When the subplot object is called (i.e. to view or save), it first executes some necessary tasks and then pushes the tasks related to bar plot, scatter plot, etc. to the task list.</p>
<p>Figure is a collection of such subplots and so Figure has a subplot list which stores the subplot objects.</p>
<p><img src="https://i.imgur.com/H2vEO1i.png" alt="Imgur" /></p>
<p>These tasks are just stored in the lists and are not performed (i.e. called) until the user asks to view or save the figure i.e. when the user calls view or save (which are tasks themselves) the tasks are performed (i.e. called) and the figure is plotted. This is done by using the Module Plotspace.<br/>
When the figure calls the task view or save, these tasks call the Plotspace Object and the state of figure is copied to the Plotspace Object and this Object starts executing( or performing) i.e. calling tasks from task list of each subplot in subplot list and the figure is plotted and viewed or saved.</p>
<p>Here is the current view of Library:</p>
<p><img src="https://i.imgur.com/0HwzAtG.png" alt="imgur" /></p>
<h3>Future</h3>
<p>The Library is currently being developed by SciRuby community <a href="https://github.com/SciRuby/rubyplot">here</a>. Currently, it is a static library, after further development, it’s Architecture should look like the following:</p>
<p><img src="https://i.imgur.com/AdfPQlT.png" alt="imgur" /></p>
<h3>Acknowledgements</h3>
<p>I would like to thank Sameer Deshmukh and Prasun Anand for guiding me through every step of software design and helping me out through every decision. I would also like to thank Dr John Woods and Dr Pjotr Prins for their valuable feedback. I am glad to be a part of SciRuby community and I hope to further contribute towards it’s goal.</p>
<p>I would also like to thank Arafat Khan, a fellow GSoCer who worked on the library using Rmagick as the backend renderer for our fruitful debates over the architecture of the library</p>
<p>Finally, I would like to thank Google for giving me this opportunity.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[GSoC 2018 : Ruby Matplotlib]]></title>
<link href="http://sciruby.com/blog/2019/01/17/gsoc-2018-Ruby-Matplotlib/"/>
<updated>2019-01-17T05:30:00+05:30</updated>
<id>http://sciruby.com/blog/2019/01/17/gsoc-2018-Ruby-Matplotlib</id>
<content type="html"><![CDATA[<p>This is a wrap of my Gsoc project at Sciruby where I worked on builing Matplotlib for Ruby.</p>
<p>At Sciruby, we came across the ambitious task of designing the next Matplotlib for Ruby and so we examined quite a few different plotting libraries and figured that if we could put together ideas from all of these libraries then we can make something really amazing.Primarily our main source of inspiration was Matplotlib. The Matplotlib Architecture is be broadly divided into three layers. The Backend, The Artist and the scripting layer.</p>
<p>Matplotlib architecture is mostly written in Python with some of its backend (the renderer AGG and Figure canvas ) written in C++ ( The original AGG backend and helper scripts, which is quite tightly bound to python). But recently the backends are also written in Python using the renderers which have Python APIs. The finer details of the Architecture can be found <a href="https://www.aosabook.org/en/matplotlib.html">here</a>.</p>
<p>Based on Matplotlib our initial plans for the library can be described in this visual.</p>
<p><img src="https://raw.githubusercontent.com/Arafatk/hagura/gh-pages/images/Screen%20Shot%202019-01-28%20at%201.27.11%20PM.png" alt="Image" /></p>
<p>We decided to build two different ruby libraries independently but with many parallels in their code. Eventually when the project gets completed we will combine them into a single repository and give users the option to use either of the libraries as a backend for construction of the plots.</p>
<p>For the first one, <a href="https://github.com/pgtgrly/GRruby-extension/">Gr plot</a> is plotting library for ruby that uses the <a href="https://gr-framework.org/">GR framework</a> as a backend.
And for the second one, <a href="https://github.com/Arafatk/magick-rubyplot/">Magick plot</a> is a plotting library that produces quality figures in a variety of hardcopy formats using <a href="https://rmagick.github.io/">RMagick</a> as a backend.</p>
<p> Magickplot is an interesting library with many features similar to GRPlot but the internal implementations of both the libraries are radically different. We believe that depending on the use cases the users can find either of them more useful than the other one.
So our next goal is to merge them together and give users a simple API to switch back ends easily from GR Plot to Magick Plot….</p>
<p>My work in particular dealt with building Magickplot. The library works in similar thought process to painting where you can give it an empty paper called figure canvas and then you draw upon the figure canvas using plotting features. For all drawing and plotting purposes in this library we use RMagick.</p>
<p>So where are our paint brushes and paints for drawing on the plot?</p>
<ul>
<li> draw->rectangle</li>
<li> draw->circle</li>
<li> draw->line</li>
<li> draw->annotate</li>
</ul>
<p>These base features will let you make Bar, Scatter, Dot, Line and Bubble plots with Magickplot with very accurate geometry. A better walk through of the construction of a single plot with this library can be found in this <a href="https://arafatk.github.io/hagura/2018/07/19/bubble-base.html">blog</a>.</p>
<h2>Application</h2>
<p>My GSoC 2018 application for the project can be found <a href="https://docs.google.com/document/d/1t7jJKMaPjFI7pbjfMSG7eh6YmqqIE0qEoXXqsxROlYs/edit?usp=sharing">here</a>.</p>
<h2>Blog Posts</h2>
<p>The entire work for Rubyplot can be summarized in these series of blogposts:</p>
<ul>
<li><a href="https://arafatk.github.io/hagura/2018/06/20/introductions.html">Introductory Blog</a></li>
<li><a href="https://arafatk.github.io/hagura/2018/06/21/ArtistBase-1.html">Artist Base - Part 1</a></li>
<li><a href="https://arafatk.github.io/hagura/2018/06/22/ArtistBase-2.html">Artist Base - Part 3</a></li>
<li><a href="https://arafatk.github.io/hagura/2018/07/11/Plot-Constructions.html">Divisionism</a></li>
<li><a href="https://arafatk.github.io/hagura/2018/07/12/scatter-base.html">Scatter Plots</a></li>
<li><a href="https://arafatk.github.io/hagura/2018/07/19/bubble-base.html">Bubble Plots</a></li>
</ul>
<h2>Future Work</h2>
<p>Our ultimate goal is to make this project similar to a matplotlib equivalent for Ruby with tons of really amazing customization features. I hope you find this interesting and useful.The library is currently being developed by the Sciruby community, feel free to try it out from <a href="https://github.com/SciRuby/rubyplot/">github</a>. Any suggestions and recommendations are welcome.</p>
<h2>FOSS</h2>
<p>I have been an active contributor to a few open source projects and I have started a few
nice ones of my own and I feel really glad to have been introduced to the open
source community. I really appreciate the effort by Google Open Source Committee for conducting GSoC every year. It is the best platform for aspiring programmers to improve their skill and give back to society by developing free and open source software.</p>
<h2>Acknowledgements</h2>
<p>Thanks to all my Mentors from Sciruby namely, Sameer Deshmukh, Pjotr Prins, Prasun Anand and John Woods.
Special thanks to Pranav Garg a fellow GSoCer who is the lead developer of GR-Ruby and a student in Gsoc for Sciruby</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[GSoC 2018 : Implementing advance features in daru-view]]></title>
<link href="http://sciruby.com/blog/2019/01/16/gsoc-2018-advance-features-in-daru-view/"/>
<updated>2019-01-16T17:30:00+05:30</updated>
<id>http://sciruby.com/blog/2019/01/16/gsoc-2018-advance-features-in-daru-view</id>
<content type="html"><![CDATA[<p>This is a wrap of my magnificent adventurous journey of GSoC with SciRuby and I feel proud that I managed to contribute a significant amount to the development and progress of the project <a href="https://github.com/SciRuby/daru-view">daru-view</a>. This post summarizes my work in this period.</p>
<p>Daru-view now presents data in some more visualizations like HighMap and HighStock along with the already implemented HighCharts, GoogleCharts, DataTables and Nyaplot. It provides some more new cool features like formatting Daru::View::Table (GoogleCharts table) with different colors, pattern, etc., exporting charts to different formats, comparing different visualizations in a row and many more. Follow up with these <a href="https://github.com/SciRuby/daru-view/tree/master/spec/dummy_iruby">IRuby examples</a> to know the current features equipped in daru-view.</p>
<p><img src="https://camo.githubusercontent.com/a0a98819e3421378873a96893502e044ceb09e84/68747470733a2f2f33327465657468676c69747465722e66696c65732e776f726470726573732e636f6d2f323031382f30352f68732e706e67" title="Fig. 1: HighStock" alt="HighStock" />
<img src="https://camo.githubusercontent.com/7e99eb68f3901995887d93160f2ef26756b531b5/68747470733a2f2f33327465657468676c69747465722e66696c65732e776f726470726573732e636f6d2f323031382f30352f686d5f696e6469612e706e67" title="Fig. 2: HighMap" alt="HighMap" />
<img src="https://camo.githubusercontent.com/f2d3a7dc5889ec63028cc4d4faeb63c47ba5b270/68747470733a2f2f33327465657468676c69747465722e66696c65732e776f726470726573732e636f6d2f323031382f30352f6373732e706e67" title="Fig. 3: CSS styling in HighCharts" alt="CSS styling" />
<img src="https://camo.githubusercontent.com/c6145397f1bf1756bb2f2921ce35ea0d88b51099/68747470733a2f2f33327465657468676c69747465722e66696c65732e776f726470726573732e636f6d2f323031382f30362f696d706f72745f73707265616473686565742e706e67" title="Fig. 4: Importing Data from Google spreadsheet" alt="Data from spreadsheet" />
<img src="https://camo.githubusercontent.com/5c9e5453dcf25cadceca7f558152bb0f75cdc737/68747470733a2f2f33327465657468676c69747465722e66696c65732e776f726470726573732e636f6d2f323031382f30372f6d756c7469706c655f67635f68632e706e67" title="Fig. 5: Comparing data using different visualizations side by side" alt="Multiple visualizations" /></p>
<p>These figures describes the usage of some of the features implemented in daru-view during GSoC.</p>
<h1>Application</h1>
<p>The GSoC 2018 application can be found <a href="https://docs.google.com/document/d/1id7ZJ4_rAEdXjg2yuBfcwSzV2QIiwpsfgc-gZdOioZ4/edit?usp=sharing">here</a>.</p>
<h1>Code</h1>
<ul>
<li>GSoC 2018 work done summary – <a href="https://github.com/SciRuby/daru-view/wiki/GSoC-2018---Progress-Report">Progress Report</a></li>
<li>GSoC 2018 work presentation – <a href="https://docs.google.com/presentation/d/1lhf3QA5SmqA9YbMAjd6JnSJuZBuAfRKFBYs7JPKPRis/edit?usp=sharing">Advance Features in daru-view</a></li>
<li>Discourse Discussion – <a href="https://discourse.ruby-data.org/t/gsoc-2108-project-advance-features-in-daru-view-discussion/43/50">daru-view discussion</a></li>
</ul>
<p>The work done during this GSoC has been explained in the following eight blog posts:</p>
<ol>
<li><a href="https://32teethglitter.wordpress.com/2018/05/01/gsoc-2018-introduction-advance-features-in-daru-view/">GSoC 2018 Introduction – Goals defined</a></li>
<li><a href="https://32teethglitter.wordpress.com/2018/05/20/gsoc-2018-coding-week-1/">HighCharts and HighMaps</a></li>
<li><a href="https://32teethglitter.wordpress.com/2018/05/27/gsoc-2018-coding-week-2/">Custom Styling CSS in HighCharts</a></li>
<li><a href="https://32teethglitter.wordpress.com/2018/06/08/gsoc-2018-coding-week-3-4/">Exporing HighCharts | ChartWrapper | Importing data from google spreadsheet in Google Charts</a></li>
<li><a href="https://32teethglitter.wordpress.com/2018/06/24/gsoc-2018-coding-week-5-6/">Exporting Google Charts | Charteditor</a></li>
<li><a href="https://32teethglitter.wordpress.com/2018/07/08/gsoc-2018-coding-week-7-8/">Handling events in Google Charts | Multiple Charts in a row</a></li>
<li><a href="https://32teethglitter.wordpress.com/2018/07/24/gsoc-2018-coding-week-9-10/">Formatters in Google Charts | Loading large set of data in DataTables</a></li>
<li><a href="https://32teethglitter.wordpress.com/2018/08/06/gsoc-2018-coding-week-11-12/">Reduce a bunch of lines due to JS files in source HTML in rails | Rake task to add new adapter</a></li>
</ol>
<h1>Future Work</h1>
<p>The future work involves removing the dependency of daru-view on gems <code>google_visualr</code> and <code>lazy_high_charts</code> by creating our own gems. Check out these <a href="https://github.com/SciRuby/daru-view/wiki/Ideas#new-ideas-to-be-reviewed">new ideas</a> that can be implemented in daru-view.</p>
<h1>FOSS</h1>
<p>This has been my first attempt to explore the open source community. The summer was filled with the development of open source software and definitely was a great learning experience.</p>
<p>I really appreciate the effort by Google Open Source Committee for conducting GSoC every year. It is the
best platform for the aspiring programmers to improve their skill and give back to society by developing free
and open source software.</p>
<h1>Acknowledgements</h1>
<p>I would like to express my sincere gratitude to Ruby Science Foundation, all the mentors and org admins for providing me this wonderful opportunity to enhance my knowledge and work independently on a project. I especially want to thank Shekhar for guiding me through the journey, helping and motivating me in every possible way.</p>
<p>I am very thankful to Google for organizing such an awesome program.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[GSoC 2017 : Creating the fastest Math libraries for Ruby by using the GPU through OpenCL, CUDA and ArrayFire.]]></title>
<link href="http://sciruby.com/blog/2017/09/15/gsoc-2017-fastest-ruby-math-libraries/"/>
<updated>2017-09-15T22:46:00+05:30</updated>
<id>http://sciruby.com/blog/2017/09/15/gsoc-2017-fastest-ruby-math-libraries</id>
<content type="html"><![CDATA[<p>GSoC 2017 is about to end. This post summarises my work during the course of summer.</p>
<p>ArrayFire-rb now supports linear algebra on GPU and CPU. Currently only double dtype has been implemented.
It supports dense and sparse matrices. It has multiple backends namely, CUDA, OpenCL and CPU.</p>
<p><img src="https://github.com/prasunanand/gsoc_blog/blob/master/img/sciruby_blog/arrayfire/add.png?raw=true" title="Fig. 1: Matrix Addition" alt="Matrix Addition" />
<img src="https://github.com/prasunanand/gsoc_blog/blob/master/img/sciruby_blog/arrayfire/sub.png?raw=true" title="Fig. 2: Matrix Subtraction" alt="Matrix Subtraction" />
<img src="https://github.com/prasunanand/gsoc_blog/blob/master/img/sciruby_blog/arrayfire/mult.png?raw=true" title="Fig. 3: Matrix Multiplication" alt="Matrix Multiplication" />
<img src="https://github.com/prasunanand/gsoc_blog/blob/master/img/sciruby_blog/arrayfire/det.png?raw=true" title="Fig. 4: Matrix Determinant" alt="Matrix Determinant" />
<img src="https://github.com/prasunanand/gsoc_blog/blob/master/img/sciruby_blog/arrayfire/lu.png?raw=true" title="Fig. 5: LU Decomposition" alt="LU Decomposition" /></p>
<p>(Note: The above benchmarks have been done on an AMD FX 8350 octacore processor and Nvidia GTX 750Ti GPU. CUDA backend of ArrayFire was used with double floating points.)</p>
<p>The figure shows that ArrayFire takes the least computation time of all. For elementwise arithmetic operations, ArrayFire is 2 e 4 times faster than NMatrix for Ruby whereas 2 e 3 times faster than NMatrix for JRuby.</p>
<p>The figure shows that ArrayFire takes the least computation time of all. ArrayFire is 3 e +6 times faster than NMatrix for JRuby and NMatrix for Ruby(not BLAS) whereas 7 e +5 times faster than NMatrix for Ruby(using BLAS).</p>
<p>For LAPACK routines, like calculating determinant and lower-upper factorization, ArrayFire is 100 times faster than NMatrix for JRuby whereas 6 times faster than NMatrix for Ruby(using LAPACKE).</p>
<h1>Application</h1>
<p>The GSoC 2017 application can be found <a href="https://github.com/prasunanand/resume/wiki/GSoC-2017-proposal">here</a>.</p>
<h1>Code</h1>
<p><a href="https://github.com/prasunanand/arrayfire-rb">ArrayFire-rb</a>: The <a href="https://github.com/arrayfire/arrayfire-rb/pull/3">pull request</a> is undergoing a review.</p>
<p>ArrayFire-rb Benchmarks: Codebase can be found <a href="https://github.com/prasunanand/arrayfire-rb-benchmark-suite">here</a>.</p>
<p>Bio::FasterLmmD : Codebase can be found <a href="https://github.com/prasunanand/bio-faster_lmm_d">here</a></p>
<p>The work on creating the bindings have been explained in the following nine blog posts:</p>
<ol>
<li><a href="http://www.prasunanand.com/ruby-c-extensions/2017/06/23/gsoc17-ruby-c-extensions-for-complex-projects.html">Ruby C extensions for complex projects</a></li>
<li><a href="http://www.prasunanand.com/arrayfire/2017/06/23/gsoc17-arrayfire-ruby-bindings-part-1-installation.html">Installation</a></li>
<li><a href="http://www.prasunanand.com/arrayfire/2017/07/04/gsoc17-arrayfire-ruby-bindings-part-2-af_array.html">Af_Array</a>(see performance)</li>
<li><a href="http://www.prasunanand.com/arrayfire/2017/07/22/gsoc17-arrayfire-ruby-bindings-part-3-minitest-algorithm.html">Test-suite and Algorithm class</a></li>
<li><a href="http://www.prasunanand.com/arrayfire/2017/08/16/gsoc17-arrayfire-ruby-bindings-part-4-blas-lapack.html">BLAS and LAPACK routines</a>(see performance)</li>
<li><a href="http://www.prasunanand.com/arrayfire/2017/08/17/gsoc17-arrayfire-ruby-bindings-part-4-statistics-and-random-engine.html">Statistics and Random Engine routines</a></li>
<li><a href="http://www.prasunanand.com/arrayfire/2017/08/22/gsoc17-arrayfire-ruby-bindings-part-6-device.html">Device and Util</a></li>
<li><a href="http://www.prasunanand.com/arrayfire/2017/08/24/gsoc17-arrayfire-ruby-bindings-part-7-backend-cuda-and-opencl.html">Multiple Backends: CUDA, OpenCL and CPU</a></li>
<li><a href="http://www.prasunanand.com/arrayfire/2017/08/24/gsoc17-arrayfire-ruby-bindings-part-8-nmatrix-interface.html">ArrayFire-NMatrix Interface</a></li>
</ol>
<p>I took a side-track working on <code>Bio::FasterLmmD</code> . This work is not complete and still in progress.
It is an effort to <code>call D from Ruby</code>. The work has been explained in a previous <a href="http://sciruby.com/gpu-computing/2017/07/25/gsoc17-calling-d-from-ruby-for-gpu-computing.html">blog post</a>.</p>
<p>The work on ArrayFire-rb - JRuby has been postponed for now as I wanted to concentrate on MRI for
the best results.</p>
<h1>Future Work</h1>
<p>The future work involves improving the ArrayFire-rb code and writing tutorials. ArrayFire is not limited to
linear algebra so I will create bindings for Signal Processing, Computer Vision, etc. I will also add support
for data types other than <code>double</code>.</p>
<p>The work on ArrayFire-rb - JRuby will begin as soon as ArrayFire gem is published.</p>
<h1>FOSS</h1>
<p>This has been my second GSoC with SciRuby. It has been more than an year contibuting extensively to FOSS.</p>
<p>I really appreciate the effort by Google Open Source Committee for conducting GSoC every year. It is the
best platform for the aspiring programmers improve their skill and give back to society by developing free
and open source software.</p>
<p>Last year’s GSoC work helped me to present a talk at FOSDEM 2017 and Ruby Conf India 2017. I got active
in the Indian Ruby Community. Recently, I have been invited as a speaker to Ruby World Conference 2017, Matsue, Japan
and RubyConf 2017, New Orleans, to talk on “GPU computing with Ruby”.</p>
<p>I plan to continue contributing to open source, strive for improving my skills, and help new programmers
contribute to FOSS. I would be glad if I could mentor students for upcoming GSoCs.</p>
<h1>Acknowledgements</h1>
<p>I would like to express my sincere gratitude to my mentor Pjotr Prins, for his guidance, patience and support.
I have learn a lot from him since my last GSoC and still learning. I couldn’t have hoped for a better mentor.</p>
<p>I am grateful to Google and the Ruby Science Foundation for this golden opportunity.</p>
<p>I am very thankful to John Woods, Sameer Deshmukh, Alexej Gossmann, Gaurav Tamba and Pradeep Garigipati
who mentored me through the project.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[GSoC 2017 : Data visualization using daru-view]]></title>
<link href="http://sciruby.com/blog/2017/09/01/gsoc-2017-data-visualization-using-daru-view/"/>
<updated>2017-09-01T22:46:00+05:30</updated>
<id>http://sciruby.com/blog/2017/09/01/gsoc-2017-data-visualization-using-daru-view</id>
<content type="html"><![CDATA[<p>Hello, Rubyist! Are looking for good ruby gem for interactive data
visualization? Then you must try <a href="https://github.com/Shekharrajak/daru-view"><code>daru-view</code></a>, a plugin gem for <a href="https://github.com/SciRuby/daru"><code>daru</code></a>.</p>
<h2>What makes daru-view different ?</h2>
<ul>
<li><p><code>daru-view</code> is designed for interactive plotting of charts and tables.It
provide different plotting tools like Nyaplot, HighCharts, GoogleCharts,
DataTable. So you don’t have to write any JavaScript code from these sites
and no need to shift to other language to get charts.</p></li>
<li><p>It can work with <strong>any ruby web application framework like Rails/Sinatra/Nanoc/Hanami</strong>. If you want to try few examples then please look into the
<a href="https://github.com/Shekharrajak/daru-view/tree/master/spec"><code>daru-view/spec/dummy_*</code></a> examples of Rails, Sinatra, Nanoc web applications.</p></li>
<li><p>Now Ruby developers are using IRuby notebook for interactive programming.
<code>daru-view</code> support IRuby notebook as well. So if you just want to see chart
for some DataFrame or Array of data, you can use <code>daru-view</code>.</p></li>
<li><p><code>daru-view</code> can generate chart images to download and save.</p></li>
<li><p><code>daru-view</code> adapters <code>googlecharts</code>, <code>highcharts</code> are able to geneate 3D charts as well.</p></li>
<li><p><code>Table</code> have some main features like pagination, search and many more to be added.It is
designed to load large data set smoothly.</p></li>
</ul>
<h2>Introduction</h2>
<p>Daru is doing pretty good work as the data analysis & manipulation in IRuby notebook as well as backend part of web application. Ruby web application frameworks like Ruby on Rails, Sinatra, Nanoc are popular frameworks. So if Ruby developers get the gem like daru which can do data analysis
and visualization work in applications, then there is no need of shifting to another language or usage of other gem.</p>
<p>My project for <abbr title="Google Summer of Code 2017"> GSoC 2017</abbr> was to “make Daru more ready for integration with modern Web framework” in terms of visualization.</p>
<p>To improve in terms of viewing data,
<a href="https://github.com/Shekharrajak/daru-view">daru-view</a>, a plugin gem for
<a href="https://github.com/SciRuby/daru">daru</a> is created. <a href="https://github.com/Shekharrajak/daru-view">daru-view</a> is for easy and interactive plotting in web application & IRuby notebook. It can work in frameworks like Rails, Sinatra, Nanoc and hopefully in others too.</p>
<p>To see a quick overview of daru-view’s features, have a look at these examples:</p>
<ul>
<li><p><a href="http://nbviewer.jupyter.org/github/shekharrajak/daru-view/tree/master/spec/dummy_iruby/">IRuby Notebook Examples</a></p></li>
<li><p><a href="https://github.com/Shekharrajak/daru_examples_io_view_rails">daru io and daru-view usage in Rails app</a></p></li>
<li><p><a href="https://github.com/Shekharrajak/daru-view/blob/master/README.md">README of daru-view</a></p></li>
</ul>
<h2>Examples</h2>
<p>This is how we can create a Plot class object:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="no">Daru</span><span class="o">::</span><span class="no">View</span><span class="o">::</span><span class="no">Plot</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">options</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li><p><code>data</code> can be <code>Daru::DataFrame</code>, data array or the format that the adapter support.</p></li>
<li><p><code>options</code> is a hash that contains various options to customize the chart.
If you have chosen a plotting library then you must use the options according
to the options the library providing. Here is the library <code>daru-view</code> uses.
Please check the examples options, they are passing in javascript code:</p>
<ul>
<li><p>GoogleCharts: <a href="https://developers.google.com/chart/interactive/docs/gallery">https://developers.google.com/chart/interactive/docs/gallery</a></p></li>
<li><p>HighCharts: <a href="https://www.highcharts.com/demo">https://www.highcharts.com/demo</a></p></li>
<li><p>Nyaplot: <a href="https://github.com/SciRuby/nyaplot">https://github.com/SciRuby/nyaplot</a> (it works same as <code>daru</code>)</p></li>
</ul>
</li>
</ul>
<p>Note: User must have some knowledge about the plotting tool(that you want to
use) to use it in <code>daru-view</code>. So that you can pass the correct options.</p>
<h3>GoogleCharts:</h3>
<p>Set the plotting library to <code>:googlecharts</code> to use this adapter. This will
load the required js files in your webpage or IRuby notebook.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="nb">require</span> <span class="s1">'daru/view'</span>
</span><span class='line'><span class="no">Daru</span><span class="o">::</span><span class="no">View</span><span class="o">.</span><span class="n">plotting_library</span> <span class="o">=</span> <span class="ss">:googlecharts</span>
</span></code></pre></td></tr></table></div></figure>
<p>Let’s create a DataFrame :</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">idx</span> <span class="o">=</span> <span class="no">Daru</span><span class="o">::</span><span class="no">Index</span><span class="o">.</span><span class="n">new</span> <span class="o">[</span><span class="s1">'Year'</span><span class="p">,</span> <span class="s1">'Sales'</span><span class="o">]</span>
</span><span class='line'><span class="n">data_rows</span> <span class="o">=</span> <span class="o">[</span>
</span><span class='line'> <span class="o">[</span><span class="s1">'2004'</span><span class="p">,</span> <span class="mi">1000</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'> <span class="o">[</span><span class="s1">'2005'</span><span class="p">,</span> <span class="mi">1170</span><span class="o">]</span><span class="p">,</span>