Skip to content
Merged

Abs #50

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext/symengine/symengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ void Init_symengine() {
c_zeta = rb_define_class_under(m_symengine, "Zeta", c_function);
c_gamma = rb_define_class_under(m_symengine, "Gamma", c_function);

//Abs Class
c_abs = rb_define_class_under(m_symengine, "Abs", c_function);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c_function -> c_one_arg_function

Btw, do we want one_arg_function? This was introduced in C++ to avoid code duplication, but I don't think there'll be any practical use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking it's better to keep the same class hierarchy as in C++, maybe it will be useful in the future. Currently there's absolutely no practical use though. What do you think? I can get rid of it if you want.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add it later when an actual need arises.

It usually doesn't occur to anyone to remove something that is not being
used(as long as that doesn't obstruct anything) but it will occur to us if
we feel something is missing.

On Tue, Jun 7, 2016, 11:11 PM Rajith Vidanaarachchi <
notifications@github.com> wrote:

In ext/symengine/symengine.c
#50 (comment):

@@ -113,6 +113,10 @@ void Init_symengine() {
c_dirichlet_eta = rb_define_class_under(m_symengine, "Dirichlet_eta", c_function);
c_zeta = rb_define_class_under(m_symengine, "Zeta", c_function);
c_gamma = rb_define_class_under(m_symengine, "Gamma", c_function);

  • c_one_arg_function = rb_define_class_under(m_symengine, "OneArgFunction", c_function);
  • //Abs Class
  • c_abs = rb_define_class_under(m_symengine, "Abs", c_function);

I was thinking it's better to keep the same class hierarchy as in C++,
maybe it will be useful in the future. Currently there's absolutely no
practical use though. What do you think? I can get rid of it if you want.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/symengine/symengine.rb/pull/50/files/189089ac7e60c7ce7299f33f62fe63aa8d6bdb30#r66117718,
or mute the thread
https://github.com/notifications/unsubscribe/AGmQ6xP1b6DDIkMiCA8Cypitn0pGdp8oks5qJa0zgaJpZM4IwKla
.


//TrigFunction SubClasses
c_sin = rb_define_class_under(m_symengine, "Sin", c_trig_function);
c_cos = rb_define_class_under(m_symengine, "Cos", c_trig_function);
Expand Down
1 change: 1 addition & 0 deletions ext/symengine/symengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ VALUE c_lambertw;
VALUE c_dirichlet_eta;
VALUE c_zeta;
VALUE c_gamma;
VALUE c_abs;
VALUE c_sin;
VALUE c_cos;
VALUE c_tan;
Expand Down
2 changes: 2 additions & 0 deletions ext/symengine/symengine_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ VALUE Klass_of_Basic(const basic_struct *basic_ptr) {
return c_mul;
case SYMENGINE_POW:
return c_pow;
case SYMENGINE_ABS:
return c_abs;
case SYMENGINE_SIN:
return c_sin;
case SYMENGINE_COS:
Expand Down
20 changes: 20 additions & 0 deletions spec/functions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
let(:pi) { SymEngine::PI }
let(:e) { SymEngine::E }
let(:x) { sym("x") }
let(:y) { sym("y") }

context "Abs" do
context "with a symbol" do
subject { SymEngine::abs(x)}
it { is_expected.to be_a SymEngine::Abs }
end
context "with an integer" do
subject { SymEngine::abs(SymEngine(1))}
it { is_expected.to be_a SymEngine::Integer }
end
context "with a symbol addition" do
subject { SymEngine::abs(x+y) }
it { is_expected.to be_a SymEngine::Abs }
end
context "with a function of a symbol" do
subject { SymEngine::abs(SymEngine::sin(x)) }
it { is_expected.to be_a SymEngine::Abs }
end
end

context '2*x' do
[
Expand Down