Jump to content
Sign in to follow this  
JRowe

c question

Recommended Posts

JRowe

I basically want to be able to have multiple ANNs (artificial neural nets) in an AutoIt script. I can initialize a single ANN struct very easily, and I've gotten all the examples working and my project set up,but before I dive in, I wanted to know if I can somehow use a string to reference and create a struct, and then pass that string back and forth between the c and autoIt code to manipulate the ANN?

ann = fann_create_standard(num_layers, num_input, num_neurons_hidden, num_output);

Every function working with the neural net thereafter refers to "ann."

How can I design the plugin so that I can create multiple ANN structs and pass the references back and forth between AutoIt and the plugin dll?

Is there a way to create and reference a struct using a string as its variable name, either in c or in AutoIt?

Something along the lines of:

char            *szStructName;
szStructName = AU3_GetString(&p_AU3_Params[0]);

temp = fann_create_standard(num_layers, num_input, num_neurons_hidden, num_output);

/*some awesome function that creates a new, unique struct identified by the value of szStructName */
StringToStruct(szStructName , temp);
fann_destroy(temp);

Or dynamically setting

struct fann *ann;
to

struct fann *szStructName;

I've considered that multiple neural nets could be used by a coprocessing setup or other multi-script design, and if this gets to be too involved I'll probably just implement the single net. However, I'd like to make it easy on the AutoIt side, so... can I do some sort of String to Struct, or should I use an array, or should I use c++?

I'm kinda lost and was wondering if someone could point me in the right direction.

Share this post


Link to post
Share on other sites
Valik

Most of your post seems to be useless information, thus, I'm not sure if I've picked out what you are asking. My stab in the dark is, are you asking if there's a way to marshal a structure back and forth as a string? If that is indeed your question, then all the comments about neural networks are extraneous fluff. Also, the answer is "yes, but it's stupid". The plugin architecture is likely too limiting for this. Use a normal Dll with DllCall() so you can specify proper structures in both AutoIt and the Dll.

Share this post


Link to post
Share on other sites
JRowe
JRowe

Ok, maybe this would be one of the stupid things to do...

struct something *array[2];
This allows me to create an array of structs and then fill it in later, and I treat array[0], array[1] like normal structs, at least from my testing so far. This is literally the only thing I need to deal with before building the plugin functions.

Is that a bad idea? I'd have a function initializing the plugin functions, explicitly declaring how many neural nets that could be created, and then the rest of the plugin code would require an index number, to identify the correct struct to work with.

Edited by JRowe

Share this post


Link to post
Share on other sites
Valik

You're trying to design an interface for interacting with a neural network via AutoIt. You're asking about an implementation detail. Can you see the problem with your question?

Share this post


Link to post
Share on other sites
Richard Robertson

How about passing an integer that represents a pointer? That's easy to cast.

Edited by Richard Robertson

Share this post


Link to post
Share on other sites
JRowe

I think I've got it figured out. I'm just going to hard code a limit of 16 neural nets and input arrays, and create functions that manage them. I was trying to magic up an easy/lazy way of making things resize and initialize on demand. The AutoIt side of things will manage an array of indices, and the functions will use those parameters to manage everything in the dll. I suppose the thread wasn't necessary, but it helped clarify my thoughts, at least.

Anyway, I've gotten all the examples to compile and work as AutoIt plugin functions, and there are no errors or warnings being tossed at me, so I think I'm on the right track. Just a matter of time, now.

I think that if it compiles, and works as intended, I can wrangle with the details later.

Can you see the problem with your question?

It's probably kind of pointless for me to be asking people how they think I should think about doing something. I should probably just get to it, and if there are specific problems, Google will make up for most of the knowledge I lack, and if there's a real problem, then I'll have real code for people to pick through and help me with.

Thanks for the help, Richard, but I think I'm on the right track now. If I start messing with relaying pointers it will probably only confuse me, so I'm gonna KISS and get'er done.

Share this post


Link to post
Share on other sites
monoceres

Hard coding a limit when you don't need to seems stupid. Can't you use std::vector or a native linked list?


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
JRowe

I was using c and avoiding c++, after a few experiments and determining that I understood what was going on in the c code.

After more searching and googling, I ended up back at the thread I started with back in February, and combined what I'd learned since then with the information in that thread, and ended up with using DLLCall.

Now, I'm back to using DLLCall, since using something like this:

Func CreateNeuralNet($numLayers, $arrayOfLayers)


$ArrayStruct = DllStructCreate("int[" & $numLayers & "]")

For $i = 1 to UBound($arrayOfLayers) step 1
DllStructSetData($ArrayStruct, 1, $arrayOfLayers[$i-1], $i)
Next

DllStructGetPtr($ArrayStruct)

$AnnCall = DllCall($hFannDll, "hwnd:cdecl", "_fann_create_standard_array", _
                                "dword", $numLayers, _
                                "dword",DllStructGetPtr($ArrayStruct))
$hAnn = $AnnCall[0]
Return $hAnn
EndFunc

That should take an array of integers, create a dllStruct array of integers, then call the function _fann_create_standard_array() and pass $num_layers and the array as parameters, returning a pointer to the neural net created. No hard limits, no mucking about with c code, and I finally finish this thing.

Use a normal Dll with DllCall() so you can specify proper structures in both AutoIt and the Dll.

So, yeah. Do you ever get tired of being right? :)

Anyway, thanks to monoceres, valik, RichardRobertson, trancexx, martin, and Smoke_N for helping me out. I really appreciate it.

Edited by JRowe

Share this post


Link to post
Share on other sites
Valik

I suggest you lookup what opaque handles are. Richard, too.

Share this post


Link to post
Share on other sites
Richard Robertson

I've done things like that before. I never really knew what it was called.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×