Skip to content

Commit 7c5f114

Browse files
Merge pull request #23 from rajithv/functions
Wrapping Functions
2 parents d26f519 + c9ad9a4 commit 7c5f114

File tree

9 files changed

+726
-3
lines changed

9 files changed

+726
-3
lines changed

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ environment:
1919
install:
2020

2121
- SET PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
22-
- if [%PLATFORM%] == [x64] set DEVKIT=C:\Ruby21-x64\DevKit
23-
- if [%PLATFORM%] == [Win32] set DEVKIT=C:\Ruby21\DevKit
22+
- if [%PLATFORM%] == [x64] set DEVKIT=C:\Ruby23-x64\DevKit
23+
- if [%PLATFORM%] == [Win32] set DEVKIT=C:\Ruby23\DevKit
2424
- "%DEVKIT%\\devkitvars.bat"
2525
- gem install bundler --no-rdoc --no-ri
2626
- bundler env

ext/symengine/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(RUBY_WRAPPER_SRC
44
ruby_integer.c
55
ruby_rational.c
66
ruby_constant.c
7+
ruby_function.c
78
symengine_macros.c
89
symengine.c
910
)

ext/symengine/ruby_function.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "ruby_function.h"
2+
3+
4+
VALUE cfunction_onearg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VALUE operand1) {
5+
basic_struct *cresult;
6+
VALUE result;
7+
8+
basic cbasic_operand1;
9+
basic_new_stack(cbasic_operand1);
10+
sympify(operand1, cbasic_operand1);
11+
12+
cresult = basic_new_heap();
13+
cwfunc_ptr(cresult, cbasic_operand1);
14+
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult);
15+
basic_free_stack(cbasic_operand1);
16+
17+
return result;
18+
}
19+
20+
#define IMPLEMENT_ONE_ARG_FUNC(func) \
21+
VALUE cfunction_ ## func(VALUE self, VALUE operand1) { \
22+
return cfunction_onearg(basic_ ## func, operand1); \
23+
}
24+
25+
IMPLEMENT_ONE_ARG_FUNC(abs);
26+
IMPLEMENT_ONE_ARG_FUNC(sin);
27+
IMPLEMENT_ONE_ARG_FUNC(cos);
28+
IMPLEMENT_ONE_ARG_FUNC(tan);
29+
IMPLEMENT_ONE_ARG_FUNC(csc);
30+
IMPLEMENT_ONE_ARG_FUNC(sec);
31+
IMPLEMENT_ONE_ARG_FUNC(cot);
32+
IMPLEMENT_ONE_ARG_FUNC(asin);
33+
IMPLEMENT_ONE_ARG_FUNC(acos);
34+
IMPLEMENT_ONE_ARG_FUNC(asec);
35+
IMPLEMENT_ONE_ARG_FUNC(acsc);
36+
IMPLEMENT_ONE_ARG_FUNC(atan);
37+
IMPLEMENT_ONE_ARG_FUNC(acot);
38+
IMPLEMENT_ONE_ARG_FUNC(sinh);
39+
IMPLEMENT_ONE_ARG_FUNC(cosh);
40+
IMPLEMENT_ONE_ARG_FUNC(tanh);
41+
IMPLEMENT_ONE_ARG_FUNC(csch);
42+
IMPLEMENT_ONE_ARG_FUNC(sech);
43+
IMPLEMENT_ONE_ARG_FUNC(coth);
44+
IMPLEMENT_ONE_ARG_FUNC(asinh);
45+
IMPLEMENT_ONE_ARG_FUNC(acosh);
46+
IMPLEMENT_ONE_ARG_FUNC(asech);
47+
IMPLEMENT_ONE_ARG_FUNC(acsch);
48+
IMPLEMENT_ONE_ARG_FUNC(atanh);
49+
IMPLEMENT_ONE_ARG_FUNC(acoth);
50+
IMPLEMENT_ONE_ARG_FUNC(lambertw);
51+
IMPLEMENT_ONE_ARG_FUNC(dirichlet_eta);
52+
IMPLEMENT_ONE_ARG_FUNC(zeta);
53+
IMPLEMENT_ONE_ARG_FUNC(gamma);
54+
55+
#undef IMPLEMENT_ONE_ARG_FUNC
56+

ext/symengine/ruby_function.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef RUBY_FUNCTION_H_
2+
#define RUBY_FUNCTION_H_
3+
4+
#include <ruby.h>
5+
#include <symengine/cwrapper.h>
6+
7+
#include "ruby_basic.h"
8+
#include "symengine.h"
9+
#include "symengine_macros.h"
10+
11+
VALUE cfunction_func(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VALUE operand1);
12+
13+
VALUE cfunction_abs(VALUE self, VALUE operand1);
14+
VALUE cfunction_sin(VALUE self, VALUE operand1);
15+
VALUE cfunction_cos(VALUE self, VALUE operand1);
16+
VALUE cfunction_tan(VALUE self, VALUE operand1);
17+
VALUE cfunction_csc(VALUE self, VALUE operand1);
18+
VALUE cfunction_cot(VALUE self, VALUE operand1);
19+
VALUE cfunction_sec(VALUE self, VALUE operand1);
20+
VALUE cfunction_asin(VALUE self, VALUE operand1);
21+
VALUE cfunction_acos(VALUE self, VALUE operand1);
22+
VALUE cfunction_atan(VALUE self, VALUE operand1);
23+
VALUE cfunction_acsc(VALUE self, VALUE operand1);
24+
VALUE cfunction_acot(VALUE self, VALUE operand1);
25+
VALUE cfunction_asec(VALUE self, VALUE operand1);
26+
VALUE cfunction_sinh(VALUE self, VALUE operand1);
27+
VALUE cfunction_cosh(VALUE self, VALUE operand1);
28+
VALUE cfunction_tanh(VALUE self, VALUE operand1);
29+
VALUE cfunction_csch(VALUE self, VALUE operand1);
30+
VALUE cfunction_coth(VALUE self, VALUE operand1);
31+
VALUE cfunction_sech(VALUE self, VALUE operand1);
32+
VALUE cfunction_asinh(VALUE self, VALUE operand1);
33+
VALUE cfunction_acosh(VALUE self, VALUE operand1);
34+
VALUE cfunction_atanh(VALUE self, VALUE operand1);
35+
VALUE cfunction_acsch(VALUE self, VALUE operand1);
36+
VALUE cfunction_acoth(VALUE self, VALUE operand1);
37+
VALUE cfunction_asech(VALUE self, VALUE operand1);
38+
VALUE cfunction_lambertw(VALUE self, VALUE operand1);
39+
VALUE cfunction_dirichlet_eta(VALUE self, VALUE operand1);
40+
VALUE cfunction_zeta(VALUE self, VALUE operand1);
41+
VALUE cfunction_gamma(VALUE self, VALUE operand1);
42+
43+
#endif //RUBY_FUNCTION_H_

ext/symengine/symengine.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "ruby_integer.h"
55
#include "ruby_rational.h"
66
#include "ruby_constant.h"
7+
#include "ruby_function.h"
78
#include "symengine.h"
89

910
///////////////////
@@ -74,4 +75,74 @@ void Init_symengine() {
7475
//Pow class
7576
c_pow = rb_define_class_under(m_symengine, "Pow", c_basic);
7677

78+
//Functions Class
79+
c_function = rb_define_class_under(m_symengine, "Function", c_basic);
80+
81+
//Function SubClasses
82+
c_trig_function = rb_define_class_under(m_symengine, "TrigFunction", c_function);
83+
c_hyperbolic_function = rb_define_class_under(m_symengine, "HyperbolicFunction", c_function);
84+
c_lambertw = rb_define_class_under(m_symengine, "LambertW", c_function);
85+
c_dirichlet_eta = rb_define_class_under(m_symengine, "Dirichlet_eta", c_function);
86+
c_zeta = rb_define_class_under(m_symengine, "Zeta", c_function);
87+
c_gamma = rb_define_class_under(m_symengine, "Gamma", c_function);
88+
89+
//TrigFunction SubClasses
90+
c_sin = rb_define_class_under(m_symengine, "Sin", c_trig_function);
91+
c_cos = rb_define_class_under(m_symengine, "Cos", c_trig_function);
92+
c_tan = rb_define_class_under(m_symengine, "Tan", c_trig_function);
93+
c_csc = rb_define_class_under(m_symengine, "Csc", c_trig_function);
94+
c_sec = rb_define_class_under(m_symengine, "Sec", c_trig_function);
95+
c_cot = rb_define_class_under(m_symengine, "Cot", c_trig_function);
96+
c_asin = rb_define_class_under(m_symengine, "ASin", c_trig_function);
97+
c_acos = rb_define_class_under(m_symengine, "ACos", c_trig_function);
98+
c_atan = rb_define_class_under(m_symengine, "ATan", c_trig_function);
99+
c_acsc = rb_define_class_under(m_symengine, "ACsc", c_trig_function);
100+
c_asec = rb_define_class_under(m_symengine, "ASec", c_trig_function);
101+
c_acot = rb_define_class_under(m_symengine, "ACot", c_trig_function);
102+
103+
//HyperbolicFunction SubClasses
104+
c_sinh = rb_define_class_under(m_symengine, "Sinh", c_hyperbolic_function);
105+
c_cosh = rb_define_class_under(m_symengine, "Cosh", c_hyperbolic_function);
106+
c_tanh = rb_define_class_under(m_symengine, "Tanh", c_hyperbolic_function);
107+
c_csch = rb_define_class_under(m_symengine, "Csch", c_hyperbolic_function);
108+
c_sech = rb_define_class_under(m_symengine, "Sech", c_hyperbolic_function);
109+
c_coth = rb_define_class_under(m_symengine, "Coth", c_hyperbolic_function);
110+
c_asinh = rb_define_class_under(m_symengine, "ASinh", c_hyperbolic_function);
111+
c_acosh = rb_define_class_under(m_symengine, "ACosh", c_hyperbolic_function);
112+
c_atanh = rb_define_class_under(m_symengine, "ATanh", c_hyperbolic_function);
113+
c_acsch = rb_define_class_under(m_symengine, "ACsch", c_hyperbolic_function);
114+
c_asech = rb_define_class_under(m_symengine, "ASech", c_hyperbolic_function);
115+
c_acoth = rb_define_class_under(m_symengine, "ACoth", c_hyperbolic_function);
116+
117+
//SymEngine Functions as Module Level Funcions
118+
rb_define_module_function(m_symengine, "abs", cfunction_abs, 1);
119+
rb_define_module_function(m_symengine, "sin", cfunction_sin, 1);
120+
rb_define_module_function(m_symengine, "cos", cfunction_cos, 1);
121+
rb_define_module_function(m_symengine, "tan", cfunction_tan, 1);
122+
rb_define_module_function(m_symengine, "csc", cfunction_csc, 1);
123+
rb_define_module_function(m_symengine, "cot", cfunction_cot, 1);
124+
rb_define_module_function(m_symengine, "sec", cfunction_sec, 1);
125+
rb_define_module_function(m_symengine, "asin", cfunction_asin, 1);
126+
rb_define_module_function(m_symengine, "acos", cfunction_acos, 1);
127+
rb_define_module_function(m_symengine, "asec", cfunction_asec, 1);
128+
rb_define_module_function(m_symengine, "acsc", cfunction_acsc, 1);
129+
rb_define_module_function(m_symengine, "atan", cfunction_atan, 1);
130+
rb_define_module_function(m_symengine, "acot", cfunction_acot, 1);
131+
rb_define_module_function(m_symengine, "sinh", cfunction_sinh, 1);
132+
rb_define_module_function(m_symengine, "cosh", cfunction_cosh, 1);
133+
rb_define_module_function(m_symengine, "tanh", cfunction_tanh, 1);
134+
rb_define_module_function(m_symengine, "csch", cfunction_csch, 1);
135+
rb_define_module_function(m_symengine, "sech", cfunction_sech, 1);
136+
rb_define_module_function(m_symengine, "coth", cfunction_coth, 1);
137+
rb_define_module_function(m_symengine, "asinh", cfunction_asinh, 1);
138+
rb_define_module_function(m_symengine, "acosh", cfunction_acosh, 1);
139+
rb_define_module_function(m_symengine, "asech", cfunction_asech, 1);
140+
rb_define_module_function(m_symengine, "acsch", cfunction_acsch, 1);
141+
rb_define_module_function(m_symengine, "atanh", cfunction_atanh, 1);
142+
rb_define_module_function(m_symengine, "acoth", cfunction_acoth, 1);
143+
rb_define_module_function(m_symengine, "lambertw", cfunction_lambertw, 1);
144+
rb_define_module_function(m_symengine, "dirichlet_eta", cfunction_dirichlet_eta, 1);
145+
rb_define_module_function(m_symengine, "zeta", cfunction_zeta, 1);
146+
rb_define_module_function(m_symengine, "gamma", cfunction_gamma, 1);
147+
77148
}

ext/symengine/symengine.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,37 @@ VALUE c_constant;
1515
VALUE c_add;
1616
VALUE c_mul;
1717
VALUE c_pow;
18+
VALUE c_function;
19+
VALUE c_trig_function;
20+
VALUE c_hyperbolic_function;
21+
VALUE c_lambertw;
22+
VALUE c_dirichlet_eta;
23+
VALUE c_zeta;
24+
VALUE c_gamma;
25+
VALUE c_sin;
26+
VALUE c_cos;
27+
VALUE c_tan;
28+
VALUE c_csc;
29+
VALUE c_sec;
30+
VALUE c_cot;
31+
VALUE c_asin;
32+
VALUE c_acos;
33+
VALUE c_atan;
34+
VALUE c_acsc;
35+
VALUE c_asec;
36+
VALUE c_acot;
37+
VALUE c_sinh;
38+
VALUE c_cosh;
39+
VALUE c_tanh;
40+
VALUE c_csch;
41+
VALUE c_sech;
42+
VALUE c_coth;
43+
VALUE c_asinh;
44+
VALUE c_acosh;
45+
VALUE c_atanh;
46+
VALUE c_acsch;
47+
VALUE c_asech;
48+
VALUE c_acoth;
49+
1850

1951
#endif //SYMENGINE_H_

ext/symengine/symengine_macros.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,62 @@ VALUE Klass_of_Basic(const basic_struct *basic_ptr) {
5151
return c_mul;
5252
case SYMENGINE_POW:
5353
return c_pow;
54+
case SYMENGINE_SIN:
55+
return c_sin;
56+
case SYMENGINE_COS:
57+
return c_cos;
58+
case SYMENGINE_TAN:
59+
return c_tan;
60+
case SYMENGINE_CSC:
61+
return c_csc;
62+
case SYMENGINE_SEC:
63+
return c_sec;
64+
case SYMENGINE_COT:
65+
return c_cot;
66+
case SYMENGINE_ASIN:
67+
return c_asin;
68+
case SYMENGINE_ACOS:
69+
return c_acos;
70+
case SYMENGINE_ATAN:
71+
return c_atan;
72+
case SYMENGINE_ACSC:
73+
return c_acsc;
74+
case SYMENGINE_ASEC:
75+
return c_asec;
76+
case SYMENGINE_ACOT:
77+
return c_acot;
78+
case SYMENGINE_SINH:
79+
return c_sinh;
80+
case SYMENGINE_COSH:
81+
return c_cosh;
82+
case SYMENGINE_TANH:
83+
return c_tanh;
84+
case SYMENGINE_CSCH:
85+
return c_csch;
86+
case SYMENGINE_SECH:
87+
return c_sech;
88+
case SYMENGINE_COTH:
89+
return c_coth;
90+
case SYMENGINE_ASINH:
91+
return c_asinh;
92+
case SYMENGINE_ACOSH:
93+
return c_acosh;
94+
case SYMENGINE_ATANH:
95+
return c_atanh;
96+
case SYMENGINE_ACSCH:
97+
return c_acsch;
98+
case SYMENGINE_ASECH:
99+
return c_asech;
100+
case SYMENGINE_ACOTH:
101+
return c_acoth;
102+
case SYMENGINE_LAMBERTW:
103+
return c_lambertw;
104+
case SYMENGINE_DIRICHLET_ETA:
105+
return c_dirichlet_eta;
106+
case SYMENGINE_ZETA:
107+
return c_zeta;
108+
case SYMENGINE_GAMMA:
109+
return c_gamma;
54110
default:
55111
return c_basic;
56112
}

0 commit comments

Comments
 (0)