Michael – it's great to hear that you're getting the kind of speed you'd hoped for. Happy to help. Let us know if you hit any other issues.
On Thu, Apr 2, 2015 at 4:24 PM, Michael Bullman <[email protected]> wrote: > Wow, thank you guys so much! Just finished my first run with the new type > definitions/constructors. Previously the pypy implmentation had taken > several days to run, I just finished a run in 5 hours! I wish I had > documented the run times of the two programs a bit better to compare them, > but nevertheless very happy with the speed boost. > > Thank you guys for taking the time to help me work through this, very > excited that the runtime has dropped this much, this actually enters the > realm of being able to run the simulation overnight and get results. As > where before I was waiting days between runs. Very happy that the switch to > Julia paid off. > > ...Thanks again :) > > On Tuesday, March 31, 2015 at 7:12:56 PM UTC-4, Stefan Karpinski wrote: >> >> Try this: >> >> type Node >> threads::Vector{Fyle} >> maxthreads::Int >> complete::Vector{Fyle} >> percent::Float64 >> name::UTF8String >> end >> >> >> Differences: >> >> - capitalized Node: the convention is that types are capitalized >> - made threads & complete of type Vector{Fyle} – Array{Fyle} is an >> abstract type with unspecified number of dimensions >> - made name of type UTF8String. String is an abstract type, which has >> been renamed to AbstractString to make that clearer; since all >> strings can be converted to UTF8String, this will transparently just >> work with better performance. >> >> Note that without additional methods you can only invoke Node with all >> five arguments given positionally. If you want a constructor that takes >> keywords, you'll need to provide it. Similarly, if you want a constructor >> that constructs incomplete Node objects, you'll need to provide that too. >> >> On Tue, Mar 31, 2015 at 5:55 PM, Michael Bullman <[email protected]> >> wrote: >> >>> Hi Pablo, >>> >>> Thanks for the help so far. I've tried to rewrite the node type using >>> the outer constructor, but I'm getting Stack Overflow errors and I'm 99% >>> certain it's my outer constructors fault >>> >>> type node >>> >>> threads::Array{Fyle} >>> >>> maxthreads::Int >>> >>> complete::Array{Fyle} >>> >>> percent::Float64 >>> >>> name::String >>> >>> end >>> >>> >>> #Outer Constructor >>> >>> node(name) = node(maxthreads=400;name="Default") >>> >>> I tried using your outer constructor as a template along with using the Doc >>> page on constructors. >>> The above outer constructor does not work, I get "ERROR: function node does >>> not accept keyword arguments" even though I thought putting the semi-colon >>> before name defined name as a keyword argument. >>> >>> I'm also wondering if this falls under the Incomplete Initialization >>> <http://julia.readthedocs.org/en/latest/manual/constructors/?highlight=constructors#incomplete-initialization> >>> subsection of the constructor Doc, since I define many more fields than I >>> initialize in the constructor. >>> >>> >>> I'm not looking for anyone to write this out for me, I'm just fairly >>> confused by what my outer constructor is saying. >>> >>> I've tried it with >>> >>> node(name) = node(maxthreads=400;name=name) and a second empty constructor >>> for default values that looked like >>> >>> node() = node(maxthreads=400;name="Default") >>> node(name) = node(maxthreads=400;name=name) >>> >>> Thinking that the node() constructor would become the "Default" Constructor >>> and the node(name) constructor would pass name to name, but it's still >>> getting the does not accept keywords error. >>> >>> I think I'm just fundamentally thinking of this incorrectly. >>> >>> >>> >>> On Friday, March 27, 2015 at 2:53:28 PM UTC-4, Pablo Zubieta wrote: >>>> >>>> Hi Michael >>>> >>>> As Stefan just pointed out, in Julia one should in general take >>>> advantage of the Multiple Dispatch paradigm and write functions that >>>> dispatch on the types instead of having functions belonging to the type (as >>>> you would have in Python). >>>> >>>> Let me give you a simple example by rewriting you Fyle type. >>>> >>>> You have something like this >>>> >>>> type Fyle >>>> size::Float64 >>>> origSize::Float64 >>>> lifetime::Int >>>> >>>> get_lifetime::Function >>>> get_size::Function >>>> >>>> function Fyle(size = 0) >>>> this = new() >>>> >>>> this.size=size >>>> this.lifetime=0 >>>> this.origSize=size >>>> >>>> this.get_lifetime = function() >>>> return(this.lifetime) >>>> end >>>> this.get_size = function() >>>> return(this.size) >>>> end >>>> >>>> return this >>>> end >>>> end >>>> >>>> when you should have really written something like this >>>> >>>> # I am going to define a method size for you type Fyle >>>> # size is a generic function in Base, so one should import it on order >>>> to be able to extend it for a user Type >>>> import Base.size >>>> >>>> type Fyle >>>> size::Float64 >>>> origSize::Float64 >>>> lifetime::Int >>>> end >>>> >>>> # Outer constructor (in some cases you might want to define an inner >>>> one as you did) >>>> # Read the manual section on Constructors >>>> Fyle(size=0) = Fyle(size, size, 0) >>>> >>>> # Define the desired functions to dispatch on the Type >>>> lifetime(f::Fyle) = f.lifetime >>>> size(f::Fyle) = f.size >>>> >>>> Hope this helps. >>>> >>>> Greetings, Pablo >>>> >>>> >>>> >>
