Skip to content

Commit e8a5670

Browse files
committed
FunctionSymbol class and its methods
1 parent f23599d commit e8a5670

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

ext/symengine/ruby_function.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,31 @@ IMPLEMENT_ONE_ARG_FUNC(gamma);
3737

3838
#undef IMPLEMENT_ONE_ARG_FUNC
3939

40+
VALUE cfunction_functionsymbol_init(VALUE self, VALUE args)
41+
{
42+
int argc = NUM2INT(rb_funcall(args, rb_intern("length"), 0, NULL));
43+
printf("%d\n", argc);
44+
VALUE first = rb_ary_shift(args);
45+
if( TYPE(first) != T_STRING ){
46+
rb_raise(rb_eTypeError, "String expected as first argument");
47+
}
48+
char *name = StringValueCStr( first );
49+
50+
basic_struct *cargs[argc];
51+
int i;
52+
for(i = 0; i < argc; i++){
53+
cargs[i] = basic_new_heap();
54+
sympify(rb_ary_shift(args), cargs[i]);
55+
}
56+
57+
basic_struct *this;
58+
Data_Get_Struct(self, basic_struct, this);
59+
60+
function_symbol_set(this, name, cargs);
61+
62+
for(i = 0; i < argc; i++){
63+
basic_free_heap(cargs[i]);
64+
}
65+
return self;
66+
}
67+

ext/symengine/ruby_function.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ VALUE cfunction_dirichlet_eta(VALUE self, VALUE operand1);
3737
VALUE cfunction_zeta(VALUE self, VALUE operand1);
3838
VALUE cfunction_gamma(VALUE self, VALUE operand1);
3939

40+
VALUE cfunction_functionsymbol_init(VALUE self, VALUE args);
41+
4042
#endif //RUBY_FUNCTION_H_

ext/symengine/symengine.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ void Init_symengine() {
113113
c_dirichlet_eta = rb_define_class_under(m_symengine, "Dirichlet_eta", c_function);
114114
c_zeta = rb_define_class_under(m_symengine, "Zeta", c_function);
115115
c_gamma = rb_define_class_under(m_symengine, "Gamma", c_function);
116-
117-
//Abs Class
118116
c_abs = rb_define_class_under(m_symengine, "Abs", c_function);
119117

118+
//FunctionSymbol Class
119+
c_function_symbol = rb_define_class_under(m_symengine, "FunctionSymbol", c_function);
120+
rb_define_method(c_function_symbol, "initialize", cfunction_functionsymbol_init, -2);
121+
120122
//TrigFunction SubClasses
121123
c_sin = rb_define_class_under(m_symengine, "Sin", c_trig_function);
122124
c_cos = rb_define_class_under(m_symengine, "Cos", c_trig_function);

ext/symengine/symengine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ VALUE c_add;
1919
VALUE c_mul;
2020
VALUE c_pow;
2121
VALUE c_function;
22+
VALUE c_function_symbol;
2223
VALUE c_trig_function;
2324
VALUE c_hyperbolic_function;
2425
VALUE c_lambertw;

ext/symengine/symengine_utils.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ VALUE Klass_of_Basic(const basic_struct *basic_ptr) {
101101
return c_mul;
102102
case SYMENGINE_POW:
103103
return c_pow;
104+
case SYMENGINE_FUNCTIONSYMBOL:
105+
return c_function_symbol;
104106
case SYMENGINE_ABS:
105107
return c_abs;
106108
case SYMENGINE_SIN:

0 commit comments

Comments
 (0)