namaste

Incredible India

What India Dreams
India must master Western science andyet preserve its Culture and Heritage.

City of Pune.
Population: 6 million.
Oxford of the East.

Sameer Deshmukh
github.com/v0dro@v0droDr. Gopal
DeshmukhDr. Hemchandra
DeshmukhDr. Satish
Deshmukh

SameerDesmukhSameerwww.soundcloud.com/catkamikazee

PuneRuby Users
Group@punerb@punerb@deccanrubyconf

www.punerb.org

www.deccanrubyconf.org

RubyScienceFoundation@sciruby@scirubywww.sciruby.com

Scientific
Computing InRuby

iruby notebook

Browser based Ruby REPLfor interactive computing.

Output cell – canInput cell – accepts
render HTML/CSS/JS
Ruby code

Runs in yourbrowsernmatrix

n­dimensional array object.
Interface Ruby withhigh speed C libraries.

require 'nmatrix'
n = NMatrix.new([2,2],[1,2,3,4],dtype: :float32,stype: :dense)
n[0,1] # => 2.0

Data Types:int8:float32:int16:float64:int32:complex64:int64:complex128

Storage types
Dense

Dense matrix.

List

Sparse matrix type storing data as alinked list.

Yale

Sparse type storing data in the 'New
Yale' format.

NMatrix C API

nmatrix

nmatrix­
atlasnmatrix­
lapacke

nmatrix­
fftw

gsl

nyaplotInteractive plotting
tool for Rubyists.

interactive
HTML and JavaScript plotsthat can be displayed in yourbrowser.

Mapnya
Map visualizations with inbuilt country charts.

Nyaplot3DThree Dimensional interactive plots.

BionyaBiology plots for visualizing relationships of genes.

daru(Data Analysis in RUby)

daru
ददार

alcohol(Hindi)==sakelibrary foranalysis, cleaning, manipulation andvisualizationof data.

Data indexing
Read/write many data sources
Works well with 'wild' data
Ephemeral statistics functions

Acts as glue between other
SciRuby libraries.

Daru::Vector
Heterogenous Array that can be indexed on
any Ruby object.
Name
Label(0)Label(1)Label(2)...

Label(n-1)

Daru::DataFrame2D spreadsheet like data structure indexed byrows or columns.
Col0

Col1

Col2

Col(n-1)

Label(0)Label(1)Label(2)...

Label(n-1)....

New Ideas for better Ruby

“Any sufficiently advanced
technology is indistinguishable
from magic.”­ Arthur C. ClarkeWriting C extensions●FFI gem.

●Rice.

●SWIG.

●Writing C bindings manually.

Rubyist!
Write me a C extension!

def factorial nn > 1 ? n*factorial(n-1) : 1end

unsigned long long int
calc_factorial(unsigned long long int n){return (n > 1 ? n*calc_factorial(n-1) : 1);}
static VALUE
cfactorial(VALUE self, VALUE n){return ULL2FIX(calc_factorial(NUM2ULL(n)));}void Init_factorial(){
VALUE cFact = rb_define_class("Fact",
rb_cObject);rb_define_method(cFact, "factorial",cfactorial, 1);}

a = Fact.newa.factorial(8000)

Big Problems
Difficult and irritating to write.
● Time consuming to debug.
● Tough to trace memory leaks.
● Change mindset from high level to lowlevel language.
● Need to care about small things.™*●*Matz – Keynote at Red Dot Ruby Conf 2016, Singapore.

RubexRubex is a Crystal­inspired superset ofRuby that compiles to C.

class Fact
def factorial(unsigned long long int n)
n > 1 ? n*factorial(n-1) : 1endend

# Create a C static array and return a Ruby Arraydef adder(n)a = StaticArray(i32, n)i32 i = 0i32 sum = 0a.each(n) { a[i] = i*5 }for 0 <= i < n dosum += a[i]endsumend

Received theRuby Association Grant 2016
for development of Rubex

https://github.com/v0dro/rubex

Scientific Computing on
JRuby

NMatrix and NArray are a linear
algebra libraries for Ruby similar tonumpy.

NMatrix

Numo::NArray

C/C++ core

C coreCRubyinterpreter

CRuby
interpreterJRuby backend for the NMatrix
Ruby API –Sci. Computing on JVM.

Uses Apache Commons Mathlibrary for storage and operations on
internal Java arrays.

Allows interfacing JRuby libraries
with jBLAS for performance.

https://github.com/prasunanand/
nmatrix/tree/jruby_port

Symbolic Computationin Rubywith symengine.rb

(x – y) * (x ** y / z)require 'symengine'x = SymEngine::Symbol.new("x")
y = SymEngine::Symbol.new("y")
z = SymEngine::Symbol.new("z")
f = (x – y) * (x ** y / z)
f.expand.to_s# x**(1 + y)/z – x**y*y/z
f == - (x**y*y/z) + (x**y*x/z)# truehttps://github.com/symengine/symengine.rb

Ruby in SpaceNASA SPICE
Ruby wrapper spice_rubrequire 'spice_rub'
k_pool = SpiceRub::KernelPool.instancek_pool.load_folder("spec/data/kernels")
epoch = SpiceRub::Time.now
moon = SpiceRub::Body.new(:moon)earth = SpiceRub::Body.now(:earth)earth.position_at(epoch)moon.distance_from(:earth, epoch)# 395791.1464913574 (Km)https://github.com/gau27/spice_rub

Cool SciRuby Stickers

Thank You
Ruby World Conf!

Any questions?