Module: NMath
- Defined in:
- lib/narray_ext.rb
Constant Summary collapse
- PI =
Math::PI
- E =
Math::E
Class Method Summary collapse
- .acot(x) ⇒ Object
- .acoth(x) ⇒ Object
- .acsc(x) ⇒ Object
- .acsch(x) ⇒ Object
- .asec(x) ⇒ Object
- .asech(x) ⇒ Object
-
.atan2(y, x) ⇒ Object
method: atan2(y,x).
- .cot(x) ⇒ Object
- .coth(x) ⇒ Object
-
.covariance(x, y, *ranks) ⇒ Object
Statistics.
-
.csc(x) ⇒ Object
Trigonometric function.
- .csch(x) ⇒ Object
- .recip(x) ⇒ Object
- .sec(x) ⇒ Object
- .sech(x) ⇒ Object
Class Method Details
.acot(x) ⇒ Object
326 327 328 |
# File 'lib/narray_ext.rb', line 326 def acot x atan(1/x.to_f) end |
.acoth(x) ⇒ Object
329 330 331 |
# File 'lib/narray_ext.rb', line 329 def acoth x atanh(1/x.to_f) end |
.acsc(x) ⇒ Object
300 301 302 |
# File 'lib/narray_ext.rb', line 300 def acsc x asin(1/x.to_f) end |
.acsch(x) ⇒ Object
303 304 305 |
# File 'lib/narray_ext.rb', line 303 def acsch x asinh(1/x.to_f) end |
.asec(x) ⇒ Object
313 314 315 |
# File 'lib/narray_ext.rb', line 313 def asec x acos(1/x.to_f) end |
.asech(x) ⇒ Object
316 317 318 |
# File 'lib/narray_ext.rb', line 316 def asech x acosh(1/x.to_f) end |
.atan2(y, x) ⇒ Object
method: atan2(y,x)
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 |
# File 'ext/narray/na_func.c', line 743
static VALUE na_math_atan2(VALUE module, volatile VALUE y, volatile VALUE x)
{
VALUE ans;
struct NARRAY *ya, *xa, *aa;
if (TYPE(y) == T_ARRAY) {
y = na_ary_to_nary(y,cNArray);
} else
if (!IsNArray(y)) {
y = na_make_scalar(y,na_object_type(y));
}
if (TYPE(x) == T_ARRAY) {
x = na_ary_to_nary(x,cNArray);
} else
if (!IsNArray(x)) {
x = na_make_scalar(x,na_object_type(x));
}
GetNArray(y,ya);
GetNArray(x,xa);
if (NA_IsINTEGER(ya) && NA_IsINTEGER(xa)) {
y = na_upcast_type(y,NA_DFLOAT);
x = na_upcast_type(x,NA_DFLOAT);
}
ans = na_bifunc( y, x, Qnil, atan2Funcs );
GetNArray(ans,aa);
if (CLASS_OF(y) == cNArrayScalar && CLASS_OF(x) == cNArrayScalar)
SetFuncs[NA_ROBJ][aa->type](1,&ans,0,aa->ptr,0);
return ans;
}
|
.cot(x) ⇒ Object
320 321 322 |
# File 'lib/narray_ext.rb', line 320 def cot x 1/tan(x) end |
.coth(x) ⇒ Object
323 324 325 |
# File 'lib/narray_ext.rb', line 323 def coth x 1/tanh(x) end |
.covariance(x, y, *ranks) ⇒ Object
Statistics
334 335 336 337 338 339 340 341 342 343 |
# File 'lib/narray_ext.rb', line 334 def covariance(x,y,*ranks) x = NArray.to_na(x) unless x.kind_of?(NArray) x = x.to_type(NArray::DFLOAT) if x.integer? y = NArray.to_na(y) unless y.kind_of?(NArray) y = y.to_type(NArray::DFLOAT) if y.integer? n = x.rank_total(*ranks) xm = x.accum(*ranks).div!(n) ym = y.accum(*ranks).div!(n) ((x-xm)*(y-ym)).sum(*ranks) / (n-1) end |
.csc(x) ⇒ Object
Trigonometric function
294 295 296 |
# File 'lib/narray_ext.rb', line 294 def csc x 1/sin(x) end |
.csch(x) ⇒ Object
297 298 299 |
# File 'lib/narray_ext.rb', line 297 def csch x 1/sinh(x) end |
.recip(x) ⇒ Object
289 290 291 |
# File 'lib/narray_ext.rb', line 289 def recip x 1/x.to_f end |
.sec(x) ⇒ Object
307 308 309 |
# File 'lib/narray_ext.rb', line 307 def sec x 1/cos(x) end |
.sech(x) ⇒ Object
310 311 312 |
# File 'lib/narray_ext.rb', line 310 def sech x 1/cosh(x) end |