-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot deduce adding type of: i32
when function is defined in seperate include file
#1574
Comments
UNREACHABLE executed
when function is defined in seperate include fileCannot deduce adding type of: i32
when function is defined in seperate include file
Any insights? I revisited it and it seems the error stems from one of the input integer argument, but I do not understand |
I think I narrowed it down to the fact that in function
Therefore I modified the code to assign variable a upper cutoff value number_of_neighbors = (number_of_neighbors > MAX_NEIGHBORS) ? MAX_NEIGHBORS:number_of_neighbors; and for some reason it has to be like this. Raising exception does not help either. if (number_of_neighbors > MAX_NEIGHBORS){
throw std::runtime_error("neigbors out of bound");
} Also gives the same error. I think this qualifies as a bug. Somehow same behavior is not observed when function is defined in the same file. |
Also for some reason it is a recurrent problem. Down the line in my library there is another loop using same number_of_neighbors variable
I also fails to compile. But with error message:
And googling it yields nothing of importance. I think it has to do with looping over undefined integer. Because I defined the same loop in 3 formats, one of them compiles successfully, other two fails. FAILS: #define MAX_NEIGH=100
for(int i =0; i< number_of_neighbors; i++){
do something
}
// and
int i = 0;
while((i < number_of_neighbors) && (i < MAX_NEIGH)){
do something
...
} Compiles: int i = 0;
while(i < MAX_NEIGH){
do something
...
i++;
if (i == number_of_neighbors){
break;
}
} |
Haven't had a chance to look at yet (will try to in near future), but that error message indicate that type analysis cannot determine the type of a variable. You can add looseTypeAnalysis to have it make its best guess, or look at the error message for where it cannot deduce it and add an annotation like |
I can confirm that adding Can you please give small example on how to use
What i tried:
what is the correct way of using |
hi @ipcamit you have to forward declare the function. Otherwise that looks reasonable. |
Doh! forward declaration does solve the issue. |
Hi,
I get the following error:
when I define my function in a separate file,
maths.cpp
/maths.hpp
. If I include the function in same file,Descriptors.cpp/hpp
, it compiles fine. I am copy pasting the files below, as well as a tar folder to reproduce the error.Full error:
LLVM version: 13.0.1
Enzyme Version: 0.0.94
dummy-descriptor-library.tar.gz
FILES
}
class Descriptor::DescriptorKind {
public:
AvailableDescriptor descriptor_kind; //!< Kind of instantiated descriptor, will be used in creating clone for AD
std::string descriptor_param_file; //!< Full path to descriptor parameter file.
int width=-1; //!< Dimension of the descriptor
};
typedef double VectorOfSize3[3];
using namespace Descriptor;
class Xi final : public DescriptorKind{
public:
Xi() {}; //TODO delete the default constructor
Xi(std::string &filename){};//TODO complete this constructor
private:
std::vector radial_basis_array;
};
// UNCOMMENT THIS FOR SUCCESSFUL COMPILATION
//void bessel_basis(int n_max, double rc, int r_size, double *r,int r_basis_size, double *r_basis);
Function files: maths.cpp and hpp
Compile command:
The text was updated successfully, but these errors were encountered: