I did not understand the parameters that needed to be passed into the API call to tf.contrib.seq2seq.simple_decoder_fn_inference in Tensorflow 1.0
for building the inference block for a Seq2Seq Attention mechanism RNN.
Can someone explain, in detail, what each parameter of this function call means and is supposed to do?
The link to the documentation is here :
tf.contrib.seq2seq.attention_decoder_fn_inference()
Related
I'm currently trying to understand how custom credential providers are made.
I have a sample to help me. This sample especially implements ICredentialProvider and ICredentialProviderFilter for WinLogon.
My job is to implement the CPUS_CREDUI usage scenario.
However, there is a lot of things i don't get in the initial implementation so i can't even expect to do my own implementation.
All the documentation i found only explains what each part actually do. Which is the only part 'clear enough' in my mind.
The problem is that i can't connect those parts together.
The different functions seemed to be called by Windows itself. How can i know what's the caller, which parameters are used, this kind of things ?
If i knew, i might have a better understanding of the whole process.
For example :
There is a recurrent parameter of type CREDENTIAL_PROVIDER_USAGE_SCENARIO which seems to change the way the CP is initialized further in the code.
It seems to be first defined in the CredentialProvider constructor but since i don't know what the caller of the constructor is...
I'm guessing it's called by WinLogon but if so, what actually define the parameters ?
The logs of the sample always show this parameter value as 'CPUS_LOGON'.
If this is a consequence of the CP constructor being called by WinLogon (If my previous hypothesis is true), how does CPUS_CREDUI can be called since it's post Logon ?
That's the main questions i have so far. Thank you if someone can unlight me.
I'm also open for every additional informations you would have for me.
Have a look at Microsoft's docs
One of the first calls to your credential provider will be SetUsageScenario
HRESULT SetUsageScenario(
CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus,
DWORD dwFlags
);
The first parameter is scenario.
If your provider is not designed for the provided scenario you can just return E_INVALIDARG.
Now that Java 8 was officially released here: http://www.oracle.com/technetwork/java/javase/downloads/index.html
Does anyone know if we can instantiate java-lambdas or call them from JNI? There's lots of documentation for using Lambdas and all the new features in Java but nothing for JNI :S
Lambda expressions are a compile-time Java language level artifact. The Java compiler will compile the expression into a synthetic method and generate the code necessary to create an instance of the functional interface whose single abstract method will invoke the method.
Since JNI is a runtime interface there is no such thing than a lambda expression from the JNI’s point of view. There are only JRE generated implementations of functional interfaces flying around which will execute pre-built methods. They may be created in order to implement a lambda expression, a method reference, or just created manually as the creation facility is part of the public JRE API.
“Calling a lambda” is quite simple then as “calling a lambda” means invoking the single abstract interface method of the functional interface on such a generated instance. There’s no need for any special JNI function just like there is no need for special Java language features to call that method.
What JNI could do about generating a lambda is telling the JRE to generate a functional interface implementation that will invoke a specified method. If that target method is the synthetic method generated by a Java compiler for a lambda expression, you have created a lambda via JNI then. Otherwise the generated instance will just behave like a method reference to the target method.
This answer shows how such an instance can be generated using pure Java code. Most of it consists of ordinary method calls which can be invoked by JNI as well. The only tricky part is invoking the factory method represented by the MethodHandle returned by the CallSite. Since invoke and invokeExact cannot be called by JNI you have to invoke invokeWithArguments for the final step of the creation.
To summarize the creation procedure, it is all centered about the method LambdaMetafactory.metafactory which is normally used as a bootstrap method for an invokedynamic instruction but which might be invoked like an ordinary method as well, including via JNI. It’s documentation as well as it’s class documentation is quite comprehensive.
Note that this is not even an entirely new thing. A limited predecessor already exists in Java 7.
I have a Java function which can take variable number of parameters and in JNI I am receiving all the parameters in jobjectArray. But the problem is all the parameters available in String type,but originally thy are of different datatype. So in c/c++ converting them to their original type is not possible. So if i could call some other java method which will make these conversions easy for me.is it possible in to call a java method from native code in JNI?
Please help me out. I am really struck at it from a long time. Thanks in advance.
Here's a succinct example: http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/method.html.
Fundamentally you need to look up native objects representing the class and method you want to call, format your arguments, call the appropriate JNIEnv->CallXXX method, and process the resulting value.
we can pass the String as a parameter from native code when you callback the java method using env->NewStringUTF(actual parameter).
I'm in the process of writing a kind of runtime system/interpreter, and one of things that I need to be able to do is call c/c++ functions located in external libraries.
On linux I'm using the dlfcn.h functions to open a library, and call a function located within. The problem is that, when using dlsysm() the function pointer returned need to be cast to an appropriate type before being called so that the function arguments and return type are know, however if I’m calling some arbitrary function in a library then obviously I will not know this prototype at compile time.
So what I’m asking is, is there a way to call a dynamically loaded function and pass it arguments, and retrieve it’s return value without knowing it’s prototype?
So far I’ve come to the conclusion there is not easy way to do this, but some workarounds that I’ve found are:
Ensure all the functions I want to load have the same prototype, and provide some sort mechanism for these functions to retrieve parameters and return values. This is what I am doing currently.
Use inline asm to push the parameters onto the stack, and to read the return value. I really want to steer clear of doing this if possible!
If anyone has any ideas then it would be much appreciated.
Edit:
I have now found exactly what I was looking for:
http://sourceware.org/libffi/
"A Portable Foreign Function Interface Library"
(Although I’ll admit I could have been clearer in the original question!)
What you are asking for is if C/C++ supports reflection for functions (i.e. getting information about their type at runtime). Sadly the answer is no.
You will have to make the functions conform to a standard contract (as you said you were doing), or start implementing mechanics for trying to call functions at runtime without knowing their arguments.
Since having no knowledge of a function makes it impossible to call it, I assume your interpreter/"runtime system" at least has some user input or similar it can use to deduce that it's trying to call a function that will look like something taking those arguments and returning something not entirely unexpected. That lookup is hard to implement in itself, even with reflection and a decent runtime type system to work with. Mix in calling conventions, linkage styles, and platforms, and things get nasty real soon.
Stick to your plan, enforce a well-defined contract for the functions you load dynamically, and hopefully make due with that.
Can you add a dispatch function to the external libraries, e.g. one that takes a function name and N (optional) parameters of some sort of variant type and returns a variant? That way the dispatch function prototype is known. The dispatch function then does a lookup (or a switch) on the function name and calls the corresponding function.
Obviously it becomes a maintenance problem if there are a lot of functions.
I believe the ruby FFI library achieves what you are asking. It can call functions
in external dynamically linked libraries without specifically linking them in.
http://wiki.github.com/ffi/ffi/
You probably can't use it directly in your scripting language but perhapps the ideas are portable.
--
Brad Phelan
http://xtargets.heroku.com
I'm in the process of writing a kind of runtime system/interpreter, and one of things that I need to be able to do is call c/c++ functions located in external libraries.
You can probably check for examples how Tcl and Python do that. If you are familiar with Perl, you can also check the Perl XS.
General approach is to require extra gateway library sitting between your interpreter and the target C library. From my experience with Perl XS main reasons are the memory management/garbage collection and the C data types which are hard/impossible to map directly on to the interpreter's language.
So what I’m asking is, is there a way to call a dynamically loaded function and pass it arguments, and retrieve it’s return value without knowing it’s prototype?
No known to me.
Ensure all the functions I want to load have the same prototype, and provide some sort mechanism for these functions to retrieve parameters and return values. This is what I am doing currently.
This is what in my project other team is doing too. They have standardized API for external plug-ins on something like that:
typedef std::list< std::string > string_list_t;
string_list_t func1(string_list_t stdin, string_list_t &stderr);
Common tasks for the plug-ins is to perform transformation or mapping or expansion of the input, often using RDBMS.
Previous versions of the interface grew over time unmaintainable causing problems to both customers, products developers and 3rd party plug-in developers. Frivolous use of the std::string is allowed by the fact that the plug-ins are called relatively seldom (and still the overhead is peanuts compared to the SQL used all over the place). The argument stdin is populated with input depending on the plug-in type. Plug-in call considered failed if inside output parameter stderr any string starts with 'E:' ('W:' is for warnings, rest is silently ignored thus can be used for plug-in development/debugging).
The dlsym is used only once on function with predefined name to fetch from the shared library array with the function table (function public name, type, pointer, etc).
My solution is that you can define a generic proxy function which will convert the dynamic function to a uniform prototype, something like this:
#include <string>
#include <functional>
using result = std::function<std::string(std::string)>;
template <class F>
result proxy(F func) {
// some type-traits technologies based on func type
}
In user-defined file, you must add define to do the convert:
double foo(double a) { /*...*/ }
auto local_foo = proxy(foo);
In your runtime system/interpreter, you can use dlsym to define a foo-function. It is the user-defined function foo's responsibility to do calculation.
I'm having a bit of difficulty passing a reference type between webservices.
My set up is as follows.
I have a console application that references two web-services:
WebServiceOne
WebServiceTwo
WebServiceOne declares the details of a class I am using in my console application...let's call it MyClass.
My console application calls WebServiceOne to retrieve a list of MyClass.
It then sends each MyClass off to WebServiceTwo for processing.
Within in the project that holds WebServiceTwo, there is a reference to WebServiceOne so that I can have the declaration of MyClass.
The trouble I'm having is that, when I compile, it can't seem to determine that the MyClass passed from the console application is the same as the MyClass declared in WebServiceOne referenced in WebServiceTwo.
I basically get an error saying Console.WebServiceOne.MyClass is not the same as MyProject.WebServiceOne.MyClass.
Does anyone know if doing this is possible? Perhaps I'm referencing WebServiceOne incorrectly? Any idea what I might be doing wrong?
My only other option is to pass each of the properties of the reference type directly to WebServiceTwo as value types...but I'd like to avoid that since I'd end up passing 10-15 parameters.
Any help would be appreciated!
I had a chat with one of the more senior guys at my work and they proposed the following solution that has worked out well for me.
The solution was to use a Data Transfer Object and remove the reference to WebServiceOne in WebServiceTwo.
Basically, in WebServiceTwo I defined a representation of all the value type fields needed as BenefitDTO. This effectively allows me to package up all the fields into one object so I don't have to pass each of them as parameters in a method.
So for the moment, that seems to be the best solution...since it works and achieves my goal.
It's likely that I didn't explain my question very well...which explains why no one was able to help...
But thanks anyway! :-)
Move the types to a separate assembly and ensure that both services use this. In the web service reference there is probably some autogenerated code called Reference.cs. Alter this to use your types.
Edit: To reflect comments
In that case take the reference.cs from that web service you cannot control use it as the shared type.
Your error message explains the problem. The proxy class on the client side is not the same type as the original class on the server side, and never will be. Whether it's a reference type or a value type is irrelevant to how it works.
I don't quite understand what your exact problem is, but here are a few guesses:
If you are trying to compare two objects for equality, then you will have to write your own compare function that compares the values of each significant property/field in turn.
If you are trying to copy an object from one service to the other, then you will have to write your own copy function that copies the values of each significant property/field in turn.
If you were using WCF, you would have the option of bypassing all this and just sharing one class definition between the client and both services.