Hi John,
Gobject is just the variable that is assigned either the new "graphNEL"
object or the graph G (a matrix of "TRUE" and "FALSE" values) that is
coerced into a "graphNEL" object. I guess if I had to translate it into
Java pseudocode it would look something like this:
Graph Gobject = G.sum() == 0 ? new Graph(nnms) : (Graph) G;
How would one translate that into Julia?
Here is my fumbling attempt:
typealias RGraph GenericGraph{Int,IEdge,Range1{Int},Vector{IEdge},Vector{
Vector{IEdge}}}
if sum(G) == 0
Gobject(n::Integer; is_directed::Bool=true) =
RGraph(is_directed,
1:int(n), # vertices
IEdge[], # edges
multivecs(IEdge, n), # finclist
multivecs(IEdge, n)) # binclist
else
convert(RGraph, G)
Gobject = G
If you see any errors in the code above or can think of simpler ways to express
it, I would really appreciate it!
Thanks.
On Sunday, February 23, 2014 2:19:49 PM UTC-8, John Myles White wrote:
>
> Hi Ted,
>
> The equivalent of new is a Julia constructor:
> http://julia.readthedocs.org/en/latest/manual/constructors/
>
> For graphs from Graphs.jl, there are a lot of different constructor
> functions depending on the type of graph.
>
> Unfortunately, I don’t know enough about what Gobject means in R to be
> able to help translate your specific example.
>
> — John
>
> On Feb 23, 2014, at 12:11 AM, Ted Fujimoto <[email protected]<javascript:>>
> wrote:
>
> Hi,
>
> Is there a Julia equivalent of the R function "new"? The documentation of
> the function is here:
> http://stat.ethz.ch/R-manual/R-devel/library/methods/html/new.html
>
> (I'm somewhat new to programming so bear with me). I'm guessing this
> function is similar to the reserved keyword in Java known as "new", which
> creates a new instance of a class or array. Say, for example, I want to
> create a new graph from Graphs.jl. How would I proceed? For a more concrete
> example, I'm trying to translate the R code below:
>
> nnms <- as.character(seq_p)
> Gobject <-
> if (sum(G) == 0) {
> new("graphNEL", nodes = nnms)
> } else {
> colnames(G) <- rownames(G) <- nnms
> as(G,"graphNEL")
> }
>
>
>