Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RealDouble class #439

Merged
merged 6 commits into from May 15, 2015
Merged

RealDouble class #439

merged 6 commits into from May 15, 2015

Conversation

isuruf
Copy link
Member

@isuruf isuruf commented May 12, 2015

No description provided.

@isuruf
Copy link
Member Author

isuruf commented May 14, 2015

I added automatic evaluation to some of the functions using single_dispatch.

@isuruf isuruf force-pushed the real branch 2 times, most recently from 98cfab7 to a6110f7 Compare May 14, 2015 14:37
};
virtual Evaluate* get_eval() const {
return nullptr;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You should never return a raw pointer like this. In this particular case, since Evaluate is a small class with no members, you can just return Evaluate by value. In more complicated cases, you need to use a smart pointer, perhaps std::unique_ptr.

Copy link
Member Author

Choose a reason for hiding this comment

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

I forgot to remove these methods. Evaluate cannot be returned by value since it is an abstract class, we could use std::unique_ptr.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. The problem with both RCP and unique_ptr is that they require to call new, so it's going to be very slow compared to other options.

Copy link
Member Author

Choose a reason for hiding this comment

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

using RCP slows down things considerably. We'll go with the single dispatch and look at two argument functions later.
Since this PR is getting big, shall I remove automatic evaluations and send it as a separate PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Either way is fine, whatever is easier to review / get in.

As to pointers, I created #445 with more details.

@isuruf
Copy link
Member Author

isuruf commented May 14, 2015

@certik, this is now ready for review.

@isuruf isuruf changed the title [WIP] RealDouble RealDouble class May 14, 2015
NUMBER, INTEGER, RATIONAL, COMPLEX, CONSTANT,
INTEGER, RATIONAL, COMPLEX, REAL_DOUBLE, NUMBER,
// 'NUMBER' returns the number of subclasses of Number.
// All subclasses of Number must be added before it.
Copy link
Contributor

Choose a reason for hiding this comment

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

How about renaming NUMBER to TypeID_Number_Count, to make it clear what it does?

Copy link
Contributor

Choose a reason for hiding this comment

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

Another problem with this is that now TypeID_Count is off by 1, or to be precise, the NUMBER slot is not being used.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this only used in is_a_Number? If so, perhaps we can find a different solution.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's only used by is_a_Number at the moment. I'll use REAL_DOUBLE instead.

@certik
Copy link
Contributor

certik commented May 14, 2015

Otherwise I think it looks good. But we also need to run benchmarks to make sure things didn't get slower.

const RealDouble &s = static_cast<const RealDouble &>(o);
return this->i == s.i;
}
return false;
Copy link
Member Author

Choose a reason for hiding this comment

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

Should this method just return false without the checks?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine as it is --- the only defined comparison is if the double is the same variable, perhaps pointed to from two different pointers. Which is what you are doing. I think that's fine, otherwise it would be confusing if you did:

a = 1.0
b = a

and then a == b would return False.

@isuruf
Copy link
Member Author

isuruf commented May 15, 2015

I ran expand2

PR:

1070ms
1105ms
1152ms
1095ms
1132ms
1067ms
1050ms
1135ms

Master:

1154ms
1069ms
1174ms
1111ms
1108ms
1194ms
1147ms
1177ms

} else {
Mul::as_base_exp(b, outArg(exp), outArg(t));
Mul::dict_add_term_new(outArg(coef), d, exp, t);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This change has made an unexpected speedup.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you think it is faster? Probably a faster number handling?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's a slight difference on what they do. When multiplying 2**x by 2 previously we got 2**(x+1), but multiplying 2**x*y by 2 we got (1/2)*2**x*y. This change makes them all behave as the latter. Therefore avoids the dictionary lookup.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, yes. Very good.

@certik
Copy link
Contributor

certik commented May 15, 2015

Very cool. +1 to merge

Sent from my mobile phone.
On May 15, 2015 7:37 AM, "Isuru Fernando" notifications@github.com wrote:

I ran expand2

PR:

1070ms
1105ms
1152ms
1095ms
1132ms
1067ms
1050ms
1135ms

Master:

1154ms
1069ms
1174ms
1111ms
1108ms
1194ms
1147ms
1177ms


Reply to this email directly or view it on GitHub
#439 (comment).

isuruf added a commit that referenced this pull request May 15, 2015
@isuruf isuruf merged commit 09cecb1 into symengine:master May 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants