DevLabs > DevLabs Forums > Axum Incubation Project > Network Two Arguments to a Two Argument Function??? ... and assorted questions
Ask a questionAsk a question
 

AnswerNetwork Two Arguments to a Two Argument Function??? ... and assorted questions

  • Thursday, October 29, 2009 3:43 AMButtink Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    What I would like to do is be able to send two different arguments to a function that have different types something like this ...
    function Vector Multiply( Matrix a, Vector b)
    {
        // do mutliplication
    }
    
    MatrixInputPort, VectorInputPort ==> Multiply ==> Result;
    
    How what I have tried is to use Combine + change my function to accept Object like so ...
    function Vector Multiply( Object[] o )
    {
         Matrix a = o[0] as Matrix;
         Vector b = o[1] as Vector;
         // do mutliplication
    }
    
    ({MatrixInputPort, VectorInputPort} &>- Multiply) ==> Result;
    
    However, It always says that I have to send an IEnumerable or an Array for the left hand argument "{MatrixInputPort...}" of "&>-"? Isn't that why im using the "{" "}". I have also tried to put new Object[] in front of it and that hasn't worked. Combine is nice but i would love some sort of mechanism to make it act more like functional programming. But, even past this when I have a function that does work like ...
    function Matrix Multiply( Matrix[] m )
    {
         // do mutliplication
    }
    
    ({MatrixInputPort1, MatrixInputPort2} &>- Multiply) ==> Result;
    
    Works for the Combine but complains about mismatch of operands for ==>. It would be nice to know what the types of each are so I could Figure out what the compiler is trying to do.





    One other thing, lets say i have a network like this ...
    source ==> work ==> work2 ==> work3
    
    work3 does not return a actual value its just a "void, T". What i would love is if there was an easy way to say to the network HEY i finished sending you data + the network to say "I finished." Now the only way I have thought to do this is to know how many you are sending before hand and send that on some port. Then make work3 ==> counter function that sends a signal to a Done port. Now as far as building this into the language i was thinking something like this ...
    source ==> work ==> work2 ==> work3 : Done
    
    Where Done is a built in output port that counts every time something is passed until Done is sent a signal. Then when the number counted is the number processed you reply with a signal. I have no idea if this would work, but I would love it.

    Anyway, Wall of text over XP


    • Edited byButtink Thursday, October 29, 2009 3:44 AMMessed up formating
    •  

Answers

  • Thursday, October 29, 2009 10:02 PMButtink Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Messing around trying to get this to work at I GOT IT TO COMPILE Wooo

    I got around message passing two diffrent types with a generic Pair Schema like so

    schema Pair<T,S> {
       required T first;
       required S second;
    }

    then just make the channel like so

    channel MatrixOpChannel {
       input Pair<Matrix,Matrix> Multiply : Matrix;
       input Pair<Matrix,Vector> VMultiply : Vector;
    }

    and my constructor looked like this

    public MatrixMultiplication()
    {
       Multiply ==> Mul;
       VMuliply ==> VMul;
    }

    Haven't actually seen if this works but ... it compiled XP
    • Marked As Answer byButtink Saturday, November 07, 2009 8:10 PM
    •  

All Replies

  • Thursday, October 29, 2009 10:02 PMButtink Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Messing around trying to get this to work at I GOT IT TO COMPILE Wooo

    I got around message passing two diffrent types with a generic Pair Schema like so

    schema Pair<T,S> {
       required T first;
       required S second;
    }

    then just make the channel like so

    channel MatrixOpChannel {
       input Pair<Matrix,Matrix> Multiply : Matrix;
       input Pair<Matrix,Vector> VMultiply : Vector;
    }

    and my constructor looked like this

    public MatrixMultiplication()
    {
       Multiply ==> Mul;
       VMuliply ==> VMul;
    }

    Haven't actually seen if this works but ... it compiled XP
    • Marked As Answer byButtink Saturday, November 07, 2009 8:10 PM
    •  
  • Monday, November 02, 2009 3:41 PMJosh PhillipsMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Buttink,

    It looks like you figured out the first issue.  Schema are a great way to go but wouldn't it be nice if we had some of the features offered by functional languages like tuples?  You should check out this article by Matthew Podwysocki and let us know what you think. ;)

    As for your other question around networks: What are you ultimately hoping to achieve?  If you're just concerned about tearing down the network when you're done with it, you can place the network statement in an using statement, e.g.

    using ( var n1 = source ==> work ==> work2 ==> work3 )
    {
          // work
    }

    This will keep the network alive until all the work inside the using block is complete. 

    If you need something more complicated than that can you clarify what it is?

    Thanks!

    Josh
  • Monday, November 02, 2009 7:42 PMButtink Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Take the programming guide example of Fib numbers. It would be awesome to be able to have a network were we can send multiple messages then say that we finished. Then, we could wait until all the data has finished and proceed to do whatever we wanted to. This is actually something that would be a nicer way to write.

    I COULD do this

    List<int> source ==> FibOnList (which calls a function Fib( int ) ) ==> PrintList ==> finished (just a signal)

    to avoid sending a done .... so yah It would be nice if there was a some way to do this in a bit nicer of a way



    If you wanted to know, I'm insane and am trying to make a graphics engine in Axum. It is tied to a C# GUI app for displaying. >.> On that note, wheres all the info on communication with an axum project from C#. Iv just been reading the sample programs to find stuff.



    BTW I love networks. Its kinda strange how large they get ... it really starts to add up. I just hope this is .... "quick" when i finish it. Its also nicer then saying something like this in C#

    work3( work2( work1( work() ) ) ) LOL + this will never be ran in parallel



    RAN INTO PROBLEM what does "no applicable options for method group <some method>" mean? Its a private nonfunction inside of a reader agent. It gets some data from a writer agent if that means anything. Found Solution to this . It was mad at my jagged array ???? weird huh i just made it a [] because it was possible just more logical to make it [,]
  • Tuesday, November 03, 2009 9:03 PMJosh PhillipsMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    Ok, I think I'm starting to see your point. 

    The scenario: You know how many items you will push into a network before you create the network and you want a signal when all of the items have been completely processed. 

    The problem: Networks based on functions are stateless and, therefore, you cannot create a counter in the function that will signal once N elements have been processed.

    In this case, my recommendation is to create an agent whose sole-purpose is to count and signal, i.e (notepad-compiled):

    channel CtCountAndSignal
    {
         input int Count;
         input Signal Add;
         output Signal Done;
    }

    agent CounterAgent : channel CtCountAndSignal
    {
         public CounterAgent()
         {
              var count = receive( Count );
              while ( count > 0 ) 
              {
                   receive( Add );
                   --count;
              }
              Done <-- Signal.Value;
         }
    }


    // and in your code...

    var counter = CounterAgent.CreateInNewDomain();
    counter <-- N;
    List<int> source ==> FibOnList ==> PrintList ==> counter;

    and you could either use counter.Done in a different network or hook it up to a different agent.

    I agree that this is a lot of additional work just to get something so simple done but we want to avoid baking specific patterns into the language and keep as much in the framework as possible.  One thing we can do to mitigate this is to create that channel and agent for you and bake it into the framework, so all you'd be stuck with is the 3 or 4 lines of code setting up the agent and network?

    I'll also bring this up with the rest of the team to see if there's somethign even better we can do here.

    Thanks!

    Josh

  • Wednesday, November 04, 2009 3:18 AMButtink Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    sweet thanks for this little tidbit should help alot

    As for how to implement the pattern above, I think I could live with either of them. I see Axum right now as a complete language that has lots of power but at the same time lots of code. However much of a lazy argument it may seem, I think all programmers are naturally lazy to some degree :) Little things like in C# when you do new List<int>(){ 1,2,3,4 }; are amazing. Any time I do the exact same thing more then like 4 times, it gets annoying. I cant actually say for certain if this isnt or is true(never tried). But, I hope I can make schema constructors or use { var=val } like syntax for schemas. Otherwise, It might get kinda huge depending on what you are sending. At the same time, going overboard would make it harder to learn/read......hmmmmm. Im not sure right now. It is a delicate balance. Any who, mini-rant over. Here is hoping I get my prog to work right. lol I would so show that off XP