Re: [julia-users] Converting a string to a custom type results in a function that is not type stable

2015-06-24 Thread Milan Bouchet-Valat
Le mercredi 24 juin 2015 à 01:18 -0700, colintbow...@gmail.com a écrit
 :
 Hi all,
 
 I've got an issue I don't really like in one of my modules, and I was 
 wondering the best thing (if anything) to do about it.
 
 The module if for dependent bootstraps, but the problem is more of a 
 project design issue. I have a type for each bootstrap method, e.g. 
 `StationaryBootstrap`, `MovingBlockBootstrap` e.t.c. and they are all 
 sub-types of an abstract `BootstrapMethod`. Then I have functions 
 that can be called over these different bootstrap method types and 
 multiple dispatch will make sure the appropriate code is called, e.g 
 `bootindices(::StationaryBootstrap)` or 
 `bootindices(::MovingBlockBootstrap)`. This all works nicely.
 
 I now want to define some keyword wrapper type functions in the 
 module for users who don't want to learn much about how the types 
 within the module work. For example, my wrapper might let the user 
 describe the bootstrap procedure they want with a string, eg 
 `bootindices(...; bootstrapmethod::ASCIIString=stationary)`.
 
 The keyword wrapper is called, and I have a variable 
 `bootstrapMethod` which is a string. I need to convert it into the 
 appropriate bootstrap method type so I can then call the appropriate 
 method via multiple dispatch. Currently I have one function that does 
 this and looks something like this:
 
 function boot_string_to_type(x::ASCIIString)
 x == stationary  return(StationaryBootstrap())
 x == movingBlock  return(MovingBlock())
 ...
 end
 
 The problem is that this function is not type-stable.
 
 Should I be worried? Does anyone have a better way of dealing with 
 this kind of issue? Maybe something involving symbols or expressions, 
 or anonymous functions etc?
 
 Note, the situation can sometimes get quite a bit more complicated 
 than this, with multiple key-word arguments, all of which need to be 
 combined into the constructor for the relevant type.
I think the most Julian way to do this is to have users pass a type
instead of a string. They would write
bootindices{T:BootstrapMethod}(...; method::Type{T}=StationaryBootstrap)

That's simpler for the user as passing a string (since autocompletion w
ill work), you don't need to define boot_string_to_type(), and it's
type-stable. This is the idiom used by fit() in StatsBase.jl (and
GLM.jl) to choose which type of model should be estimated.


Hope this helps


PS: in the cases where you still want to pass a string as an argument,
rather than a type, consider using symbols instead, as it is more
efficient.


[julia-users] Converting a string to a custom type results in a function that is not type stable

2015-06-24 Thread colintbowers
Hi all,

I've got an issue I don't really like in one of my modules, and I was 
wondering the best thing (if anything) to do about it.

The module if for dependent bootstraps, but the problem is more of a 
project design issue. I have a type for each bootstrap method, e.g. 
`StationaryBootstrap`, `MovingBlockBootstrap` e.t.c. and they are all 
sub-types of an abstract `BootstrapMethod`. Then I have functions that can 
be called over these different bootstrap method types and multiple dispatch 
will make sure the appropriate code is called, e.g 
`bootindices(::StationaryBootstrap)` or 
`bootindices(::MovingBlockBootstrap)`. This all works nicely.

I now want to define some keyword wrapper type functions in the module for 
users who don't want to learn much about how the types within the module 
work. For example, my wrapper might let the user describe the bootstrap 
procedure they want with a string, eg `bootindices(...; 
bootstrapmethod::ASCIIString=stationary)`.

The keyword wrapper is called, and I have a variable `bootstrapMethod` 
which is a string. I need to convert it into the appropriate bootstrap 
method type so I can then call the appropriate method via multiple 
dispatch. Currently I have one function that does this and looks something 
like this:

function boot_string_to_type(x::ASCIIString)
x == stationary  return(StationaryBootstrap())
x == movingBlock  return(MovingBlock())
...
end

The problem is that this function is not type-stable.

Should I be worried? Does anyone have a better way of dealing with this 
kind of issue? Maybe something involving symbols or expressions, or 
anonymous functions etc?

Note, the situation can sometimes get quite a bit more complicated than 
this, with multiple key-word arguments, all of which need to be combined 
into the constructor for the relevant type.

Cheers,

Colin




Re: [julia-users] Converting a string to a custom type results in a function that is not type stable

2015-06-24 Thread John Myles White
Excited you're working on dependent data bootstraps. I implemented one just 
the other day since it could be useful for analyzing benchmark data. Would 
be great to have other methods to do out.

 -- John

On Wednesday, June 24, 2015 at 5:31:52 AM UTC-4, Milan Bouchet-Valat wrote:

 Le mercredi 24 juin 2015 à 01:18 -0700, colintbow...@gmail.com a écrit 
  : 
  Hi all, 
  
  I've got an issue I don't really like in one of my modules, and I was 
  wondering the best thing (if anything) to do about it. 
  
  The module if for dependent bootstraps, but the problem is more of a 
  project design issue. I have a type for each bootstrap method, e.g. 
  `StationaryBootstrap`, `MovingBlockBootstrap` e.t.c. and they are all 
  sub-types of an abstract `BootstrapMethod`. Then I have functions 
  that can be called over these different bootstrap method types and 
  multiple dispatch will make sure the appropriate code is called, e.g 
  `bootindices(::StationaryBootstrap)` or 
  `bootindices(::MovingBlockBootstrap)`. This all works nicely. 
  
  I now want to define some keyword wrapper type functions in the 
  module for users who don't want to learn much about how the types 
  within the module work. For example, my wrapper might let the user 
  describe the bootstrap procedure they want with a string, eg 
  `bootindices(...; bootstrapmethod::ASCIIString=stationary)`. 
  
  The keyword wrapper is called, and I have a variable 
  `bootstrapMethod` which is a string. I need to convert it into the 
  appropriate bootstrap method type so I can then call the appropriate 
  method via multiple dispatch. Currently I have one function that does 
  this and looks something like this: 
  
  function boot_string_to_type(x::ASCIIString) 
  x == stationary  return(StationaryBootstrap()) 
  x == movingBlock  return(MovingBlock()) 
  ... 
  end 
  
  The problem is that this function is not type-stable. 
  
  Should I be worried? Does anyone have a better way of dealing with 
  this kind of issue? Maybe something involving symbols or expressions, 
  or anonymous functions etc? 
  
  Note, the situation can sometimes get quite a bit more complicated 
  than this, with multiple key-word arguments, all of which need to be 
  combined into the constructor for the relevant type. 
 I think the most Julian way to do this is to have users pass a type 
 instead of a string. They would write 
 bootindices{T:BootstrapMethod}(...; method::Type{T}=StationaryBootstrap) 

 That's simpler for the user as passing a string (since autocompletion w 
 ill work), you don't need to define boot_string_to_type(), and it's 
 type-stable. This is the idiom used by fit() in StatsBase.jl (and 
 GLM.jl) to choose which type of model should be estimated. 


 Hope this helps 


 PS: in the cases where you still want to pass a string as an argument, 
 rather than a type, consider using symbols instead, as it is more 
 efficient. 



Re: [julia-users] Converting a string to a custom type results in a function that is not type stable

2015-06-24 Thread Colin Bowers
If you're interested, the source is here:

https://github.com/colintbowers/DependentBootstrap.jl

I haven't tried to make it into a registered package yet as I'm still
tinkering with it a fair bit. But I think I'm nearly there. It is fairly
comprehensive for univariate bootstrapping, ie lots of methods and  block
length selection procedures, but I haven't really thought about extending
it to multivariate data yet. Maybe later this year.

Cheers,

Colin

On 24 June 2015 at 23:42, John Myles White johnmyleswh...@gmail.com wrote:

 Excited you're working on dependent data bootstraps. I implemented one
 just the other day since it could be useful for analyzing benchmark data.
 Would be great to have other methods to do out.

  -- John


 On Wednesday, June 24, 2015 at 5:31:52 AM UTC-4, Milan Bouchet-Valat wrote:

 Le mercredi 24 juin 2015 à 01:18 -0700, colintbow...@gmail.com a écrit
  :
  Hi all,
 
  I've got an issue I don't really like in one of my modules, and I was
  wondering the best thing (if anything) to do about it.
 
  The module if for dependent bootstraps, but the problem is more of a
  project design issue. I have a type for each bootstrap method, e.g.
  `StationaryBootstrap`, `MovingBlockBootstrap` e.t.c. and they are all
  sub-types of an abstract `BootstrapMethod`. Then I have functions
  that can be called over these different bootstrap method types and
  multiple dispatch will make sure the appropriate code is called, e.g
  `bootindices(::StationaryBootstrap)` or
  `bootindices(::MovingBlockBootstrap)`. This all works nicely.
 
  I now want to define some keyword wrapper type functions in the
  module for users who don't want to learn much about how the types
  within the module work. For example, my wrapper might let the user
  describe the bootstrap procedure they want with a string, eg
  `bootindices(...; bootstrapmethod::ASCIIString=stationary)`.
 
  The keyword wrapper is called, and I have a variable
  `bootstrapMethod` which is a string. I need to convert it into the
  appropriate bootstrap method type so I can then call the appropriate
  method via multiple dispatch. Currently I have one function that does
  this and looks something like this:
 
  function boot_string_to_type(x::ASCIIString)
  x == stationary  return(StationaryBootstrap())
  x == movingBlock  return(MovingBlock())
  ...
  end
 
  The problem is that this function is not type-stable.
 
  Should I be worried? Does anyone have a better way of dealing with
  this kind of issue? Maybe something involving symbols or expressions,
  or anonymous functions etc?
 
  Note, the situation can sometimes get quite a bit more complicated
  than this, with multiple key-word arguments, all of which need to be
  combined into the constructor for the relevant type.
 I think the most Julian way to do this is to have users pass a type
 instead of a string. They would write
 bootindices{T:BootstrapMethod}(...; method::Type{T}=StationaryBootstrap)

 That's simpler for the user as passing a string (since autocompletion w
 ill work), you don't need to define boot_string_to_type(), and it's
 type-stable. This is the idiom used by fit() in StatsBase.jl (and
 GLM.jl) to choose which type of model should be estimated.


 Hope this helps


 PS: in the cases where you still want to pass a string as an argument,
 rather than a type, consider using symbols instead, as it is more
 efficient.




Re: [julia-users] Converting a string to a custom type results in a function that is not type stable

2015-06-24 Thread Colin Bowers
Thanks for responding. Yes, I think I will do it your way. I was initially
hoping there would be a neat way to duplicate how R would do it, ie, with
keyword arguments typically always strings or numbers since this is what
many new users will be familiar with, but maybe in the end it would just be
setting a bad example.

Cheers,

Colin

On 24 June 2015 at 19:31, Milan Bouchet-Valat nalimi...@club.fr wrote:

 Le mercredi 24 juin 2015 à 01:18 -0700, colintbow...@gmail.com a écrit
  :
  Hi all,
 
  I've got an issue I don't really like in one of my modules, and I was
  wondering the best thing (if anything) to do about it.
 
  The module if for dependent bootstraps, but the problem is more of a
  project design issue. I have a type for each bootstrap method, e.g.
  `StationaryBootstrap`, `MovingBlockBootstrap` e.t.c. and they are all
  sub-types of an abstract `BootstrapMethod`. Then I have functions
  that can be called over these different bootstrap method types and
  multiple dispatch will make sure the appropriate code is called, e.g
  `bootindices(::StationaryBootstrap)` or
  `bootindices(::MovingBlockBootstrap)`. This all works nicely.
 
  I now want to define some keyword wrapper type functions in the
  module for users who don't want to learn much about how the types
  within the module work. For example, my wrapper might let the user
  describe the bootstrap procedure they want with a string, eg
  `bootindices(...; bootstrapmethod::ASCIIString=stationary)`.
 
  The keyword wrapper is called, and I have a variable
  `bootstrapMethod` which is a string. I need to convert it into the
  appropriate bootstrap method type so I can then call the appropriate
  method via multiple dispatch. Currently I have one function that does
  this and looks something like this:
 
  function boot_string_to_type(x::ASCIIString)
  x == stationary  return(StationaryBootstrap())
  x == movingBlock  return(MovingBlock())
  ...
  end
 
  The problem is that this function is not type-stable.
 
  Should I be worried? Does anyone have a better way of dealing with
  this kind of issue? Maybe something involving symbols or expressions,
  or anonymous functions etc?
 
  Note, the situation can sometimes get quite a bit more complicated
  than this, with multiple key-word arguments, all of which need to be
  combined into the constructor for the relevant type.
 I think the most Julian way to do this is to have users pass a type
 instead of a string. They would write
 bootindices{T:BootstrapMethod}(...; method::Type{T}=StationaryBootstrap)

 That's simpler for the user as passing a string (since autocompletion w
 ill work), you don't need to define boot_string_to_type(), and it's
 type-stable. This is the idiom used by fit() in StatsBase.jl (and
 GLM.jl) to choose which type of model should be estimated.


 Hope this helps


 PS: in the cases where you still want to pass a string as an argument,
 rather than a type, consider using symbols instead, as it is more
 efficient.