Thank you, Páll and Yichao. To clarify:

The function is a Dijkstra shortest-paths calculation. The function can 
take an optional array of distances, but should be able to function without 
one (in which case the edge distances are assumed to be 1.0). I don't 
really want to have to default to an array of NxN floats for the default 
case, since that will cause very large graphs (say, 1 billion vertices) to 
use tons of memory for no real reason.

My thought was that if I could somehow allow some other type in 
"edge_dists" that would indicate "use the defaults", I could then test for 
that and use (hardcoded) defaults if it's set, otherwise the data will be 
an array of floats that represent edge distances.

Is there a better approach?

Thanks,

S.



On Friday, May 29, 2015 at 2:33:00 PM UTC-7, Yichao Yu wrote:
>
> On Fri, May 29, 2015 at 3:50 PM, Seth <catc...@bromberger.com 
> <javascript:>> wrote: 
> > I have an function that takes an optional (potentially very large) 
> matrix 
> > (AbstractArray{Float64,2}). I'd like to create a parameter to the 
> function 
> > that's EITHER this array, or a boolean (false). If I define 
> > 
> > edge_dists::Union(Bool, AbstractArray{Float64,2}) = false 
> > 
> > 
> > 
> > in my function declaration, would that cause significant performance 
> > penalties when accessing the parameter? 
>
> The function will specialize on (the type of) this parameter so there 
> shouldn't be a big penalty. If you need to do something different when 
> this parameter is missing and if the two cases shares a lot of code, 
> this might not be a bad idea (although IMHO ::Union(Void, 
> AbstractArray{Float64, 2})=nothing might be more intuitive) 
>

Reply via email to