ext/numo/narray/math.c in numo-narray-0.9.0.4 vs ext/numo/narray/math.c in numo-narray-0.9.0.5
- old
+ new
@@ -1,31 +1,34 @@
/*
math.c
Numerical Array Extension for Ruby
- (C) Copyright 1999-2016 by Masahiro TANAKA
+ (C) Copyright 1999-2017 by Masahiro TANAKA
*/
#include <ruby.h>
#include "numo/narray.h"
VALUE numo_mNMath;
EXTERN VALUE numo_mDFloatMath, numo_mDComplexMath;
EXTERN VALUE numo_mSFloatMath, numo_mSComplexMath;
static ID id_send;
+static ID id_UPCAST;
+static ID id_DISPATCH;
+static ID id_extract;
VALUE
nary_type_s_upcast(VALUE type1, VALUE type2)
{
VALUE upcast_hash;
VALUE result_type;
if (type1==type2) return type1;
- upcast_hash = rb_const_get(type1, rb_intern("UPCAST"));
+ upcast_hash = rb_const_get(type1, id_UPCAST);
result_type = rb_hash_aref(upcast_hash, type2);
if (NIL_P(result_type)) {
if (TYPE(type2)==T_CLASS) {
if ( RTEST(rb_class_inherited_p(type2,cNArray)) ) {
- upcast_hash = rb_const_get(type2, rb_intern("UPCAST"));
+ upcast_hash = rb_const_get(type2, id_UPCAST);
result_type = rb_hash_aref(upcast_hash, type1);
}
}
}
return result_type;
@@ -83,22 +86,22 @@
{
VALUE type, ans, typemod, hash;
if (argc>1) {
type = nary_mathcast(argc-1,argv+1);
- hash = rb_const_get(mod, rb_intern("DISPATCH"));
+ hash = rb_const_get(mod, id_DISPATCH);
typemod = rb_hash_aref( hash, type );
if (NIL_P(typemod)) {
rb_raise(rb_eTypeError,"%s is unknown for Numo::NMath",
rb_class2name(type));
}
ans = rb_funcall2(typemod,id_send,argc,argv);
if (!RTEST(rb_class_inherited_p(type,cNArray)) &&
IsNArray(ans) ) {
- ans = rb_funcall(ans,rb_intern("extract"),0);
+ ans = rb_funcall(ans,id_extract,0);
}
return ans;
}
rb_raise(rb_eArgError,"argument or method missing");
return Qnil;
@@ -135,7 +138,10 @@
rb_hash_aset(hCast, rb_cBignum, rb_mMath);
#endif
rb_hash_aset(hCast, rb_cFloat, rb_mMath);
rb_hash_aset(hCast, rb_cComplex, numo_mDComplexMath);
- id_send = rb_intern("send");
+ id_send = rb_intern("send");
+ id_UPCAST = rb_intern("UPCAST");
+ id_DISPATCH = rb_intern("DISPATCH");
+ id_extract = rb_intern("extract");
}