Mind Ramblings My Blog

Instantiating a Basic object

Hi there! If you are following the blog, you would know how many errors I faced to setup and start writing the Ruby extensions. I don’t even remember half of the errors that I faced 2 weeks before. Well, that is why we have blog posts :P. We don’t want to miss a single takeaway from this experience.

My PR in the symengine repo, #414 Ruby file structure and Basic class, finally got merged! It was the most significant PR that I had got merged till now. 126 conversations! Ondrej, Isuru and Ivan were the ones who helped me to solve them. If it weren’t for them, it would have taken me 2 more weeks to figure it out for myself. I can’t thank them enough. I would like to keep this post concise, so if you are curious about the errors you would like my previous posts under the tag GSoC-2015.

Setup different from other gems

The gem is different from other practices from other gems in a sense that our focus was to get rid of any dependencies that was not essential. Only the ones without which the extensions can’t be built. Like we got rid of extconf.rb and hence the mkmf module. The Makefile is now generated by cmake. Another one is rake and the Rakefile, tasks will be automated by the help of python in the future. However, we still use rdoc and rspec.

Features supported now

Currently, there is not much the extension supports. You can only instantiate a Basic class. The gem has a module SymEngine(It has a cool easter egg ;) too). The Basic class is a part of the module. To make the object, do

require `symengine`
a = SymEngine::Basic.new

More features like making expressions out of symbols, by addition, subtraction, multiplication and division will be soon be introduced with the PR #480 Support for Symbol in Ruby wrappers. After that, users can do things like

>> require 'symengine'
=> true
>> a = SymEngine::Symbol.new("x")
=> #<SymEngine::Symbol:0x00000002708328>
>> b = SymEngine::Symbol.new("y")
=> #<SymEngine::Symbol:0x00000002700cb8>
>> c = SymEngine::Symbol.new("z")
=> #<SymEngine::Symbol:0x000000026f78e8>
>> e = (a+b+c)*(a+b+c)
=> #<SymEngine::Symbol:0x000000026eaa58>
>> e.to_s
=> "(x + y + z)**2"
>> f = e.expand
=> #<SymEngine::Symbol:0x000000026e2920>
>> f.to_s
=> "2*x*y + 2*x*z + 2*y*z + x**2 + y**2 + z**2"

And not long after the PR is merged, I would have added the support for Integer and Rational classes.

I would love to have your feedback. Please follow the instructions from README to install the gem and give it a try. If you are interested to know about the future options that will be supported, you can go through my project proposal or browse through the current SymEngine codebase. The source code for the gem can be found here

Comments are always welcome :)

comments powered by Disqus