SciRuby / numruby

Fast Numerical Linear Algebra Library for Ruby. NMatrix reimplementation.
BSD 3-Clause "New" or "Revised" License
45 stars 10 forks source link

Fix compiler warnings #21

Closed Uditgulati closed 5 years ago

Uditgulati commented 5 years ago

Fixed compiler warnings for sparse.c. Also, fixed a switch statement typo.

To prevent the nesting of switch(input->sptype) and switch(input->dtype), I passed the input->dtype to get_densefrom* functions.

Will also fix compiler warnings for remaining files.

Uditgulati commented 5 years ago

@prasunanand I've raised SyntaxError if greater or lesser comparison is done on complex numbers as Ruby also does not support this for Complex type. But, numpy supports it (Python complex doesn't) by doing a comparison on real part and then on imaginary. Should I keep it this way or change it to work like numpy? Or I could make comparison based on the magnitude of complex numbers.

Ruby Complex example

[1] pry(main)> a = 2+3i
=> (2+3i)
[2] pry(main)> b = 23i
=> (0+23i)
[3] pry(main)> b = 2+3i
=> (2+3i)
[4] pry(main)> a == b
=> true
[5] pry(main)> b = 2+4i
=> (2+4i)
[6] pry(main)> a < b
NoMethodError: undefined method `<' for (2+3i):Complex
from (pry):6:in `__pry__'

numpy complex128 example

>>> import numpy as np
>>> a = np.array([2+3j, 2+4j])
>>> a[0]
(2+3j)
>>> a[1]
(2+4j)
>>> a[0] == a[1]
False
>>> a[0] < a[1]
True
>>> a[0] = 4+2j
>>> a[0] < a[1]
False
>>> a[1] = 2+100j
>>> a[0] < a[1]
False
prasunanand commented 5 years ago

When in doubt, go the numpy way :)

Uditgulati commented 5 years ago

@prasunanand this PR is complete from my end. Please review it when free.