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

Lagged Fibonacci Generator #727

Closed
wants to merge 12 commits into from
Closed

Lagged Fibonacci Generator #727

wants to merge 12 commits into from

Conversation

monarchdodra
Copy link
Collaborator

D2 test results for 764

Ported from boost:
http://www.boost.org/doc/libs/1_50_0/boost/random/linear_congruential.hpp

While boost provided two different classes for UInt/Real types, this implementation merges both into the same class.

My doubts on the implementation are:
*Aliases: Boost uses doubles as the defaults for the engine, and doesn't provide any aliases for the unsigned types. Should we follow the same scheme? Provided alliases for both?
*Default Alias: Not sure which config to use for the "LaggedFibonacci", so I chose LaggedFibonacci607, but documented it as "implementation chosen".
*Reference type & unseeded engine: The generator is a reference type forward range. In thoery, it can't be used until it has been seeded. I have put in asserts about this. Maybe it should be enforece instead?
*Boost provides a "generate" function, which is used to fill a range of integers. I did not write these, as they can be replaced by simply chosing the correct engine, an manually calling std.algo.fill.

Open to all suggestions/criticism, even the "minor" ones, such as documentation/licensing.

@monarchdodra
Copy link
Collaborator Author

I will be away from August 6 to August 20. Apologies for not being able to answer comments during that time.

Type[longLag] x;
size_t i = 0;

void ThrowSeedException()
Copy link
Member

Choose a reason for hiding this comment

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

lowercase t

@andralex
Copy link
Member

ping?

@andralex
Copy link
Member

Sorry, saw the notice only now. Let's get back to this after Aug 20. Enjoy vacations!

@andralex
Copy link
Member

due for review next week

@monarchdodra
Copy link
Collaborator Author

Thanks a lot for the re-read. In my defense, I tried to stay close to the boost code, but I think your comments are pertinent, and the code should be more D-Like.

I have nothing to add to any of the comments, except the "ref?" one.

Will provide a new version in 2 days.

@monarchdodra
Copy link
Collaborator Author

Ok, I did all the above fixes, plus a few internal tweaks. Also added the unittests I had forgotten to add.

Added complexity ratings, and merged a few docs with ditto's.

Tells if the generator has been seeded/initialized
*/
@property @safe nothrow const
bool seeded()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is this a good name? Maybe "isSeeded" instead?

Property?

Copy link
Member

Choose a reason for hiding this comment

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

seeded is fine as long as it's a property

}
}
}
Payload* payload;
Copy link
Member

Choose a reason for hiding this comment

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

RefCounted!Payload?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Isn't it simpler to just let the GC handle it? I don't think there is any reason to force RAII on the allocated space here.

Copy link
Member

Choose a reason for hiding this comment

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

fine (this actually works great with the suggestion to make this a class)

@andralex
Copy link
Member

Getting there. Nice work!

@monarchdodra
Copy link
Collaborator Author

Thank you again for the re-read. I did not have time to work on it this week, but I needed your feedback on the constructor/payload issue before continuing anyways. Regarding everything else, I think one more week of work, and everything should be final.

D is still a learning process for me, so I don't want to rush this.

@andralex
Copy link
Member

andralex commented Sep 2, 2012

Just do what the Mersenne Twister does (i.e. ctor with seed and also seed method). We can always add the opCall trick if we decide it's worth it. For now let's aim for conservative uniformity. Thanks!

@monarchdodra
Copy link
Collaborator Author

Fixed what needed to be fixed. Made everything as conservative as and straight forward as possible. I kept the reference semantics. It is kind of discussed in this thread:
http://forum.dlang.org/thread/spjfsyaqrcpboypgfrsd@forum.dlang.org
And the rationale in this post:
http://forum.dlang.org/thread/spjfsyaqrcpboypgfrsd@forum.dlang.org?page=3#post-bloacgckmnejwhbnjdlp:40forum.dlang.org

Long story short: It is much more convenient for the type itself to provide reference semantics, then for the developers to do it themselves. As a reminder, LaggedFibonacci44497 is 300K in size (!)

Anyways, I don't think there is much else to say here on my end.

I was still curious about nested structs and have a hidden "outer" pointer:
According to http://dlang.org/struct.html, they do.
According to TDPL, they don't.

Could we have your input in this discussion? Or here and I'll relay.
http://forum.dlang.org/thread/cwohbwozowasyfpkcoim@forum.dlang.org

Ported from boost.
* numbers in the range [0 .. 2^^bits). Real Type will generate
* floating points in the range [0 .. 1), with a step of 1/2^^bits.
*
* The engine uses reference semantics, and models a ForwardRange.
Copy link
Member

Choose a reason for hiding this comment

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

s/ForwardRange/$(D ForwardRange)/

Copy link
Member

Choose a reason for hiding this comment

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

The fact that it uses reference semantics must be emphasize and discussed with examples. Documentation should also mention that this semantics is different from all other types in this module.

@monarchdodra
Copy link
Collaborator Author

Closed for development

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants