Undefined arguments(Image Processing) - image

I am having a little problem here. In the code below is a function that has two arguments when I attempt to execute the functions i obtained this error
Undefined function or method for input
arguments of type 'double' (X,CX) as shown in (1).
the function is coded as below
[CX,sse]= (vgg_kmiter(X, CX)) ....(1)
can someone point me out where is the problem with this code?
note that the x is the input points in a columns which is integer and the CX is the center of clustering which is also integer.
Thank you

[CX,sse]= (vgg_kmiter(X, CX)) ....(1)
Is not a valid line of code.
[CX,sse]= (vgg_kmiter(X, CX));
is fine, though the outer parentheses aren't needed.
[CX,sse]= (vgg_kmiter(X, CX)) %....(1)
is fine as well - everything after the % sign is considered a comment

Related

Operands in verilog

I am trying to implement a PID controller using Verilog, but I faced some problems in the coding.
I try to set the position as a parameter like shown in the screens shot:
but, I faced an error which I am not aware of:
Error1:-
Error (10170): Verilog HDL syntax error at Verilog1.v(16) near text: "["; expecting an operand. Check for and fix any syntax errors that appear immediately before or at the specified keyword. The Intel FPGA Knowledge Database contains many articles with specific details on how to resolve this error. Visit the Knowledge Database at https://www.altera.com/support/support-resources/knowledge-base/search.html and search for this specific error message number.
Error2:-
Error (10170): Verilog HDL syntax error at Verilog1.v(34) near text: "["; expecting "#", or an operand. Check for and fix any syntax errors that appear immediately before or at the specified keyword. The Intel FPGA Knowledge Database contains many articles with specific details on how to resolve this error. Visit the Knowledge Database at https://www.altera.com/support/support-resources/knowledge-base/search.html and search for this specific error message number.
I also tried the like integer position= [0*IRL+1000*CIR+2000*IRR];, but still, I face the same problem. How do I fix this syntax error?
After compiling, parameter values can only be read; not modified. They are runtime constants. An integer type can only be assigned within an procedural block. You can give it an initial value at declarations, but it will not auto update. So you want a procedure assignment or a net type with continuous assignment.
Square brackets ([]) are used for indexing an array or slice of a vector. They cannot be used like parentheses (()) or curly brackets ({}). In your case non are needed.
Change:
integer position= [0*IRL+1000*CIR+2000*IRR];
To:
wire [31:0] position= 0*IRL+1000*CIR+2000*IRR;
Or:
wire [31:0] position;
assign position= 0*IRL+1000*CIR+2000*IRR;
Or:
integer position;
always #* begin
position= 0*IRL+1000*CIR+2000*IRR;
end
Also change:
Proportional<= [position/IRL+CIR+IRR]-1000;
To:
Proportional<= (position/IRL+CIR+IRR)-1000;
Assuming IRL, CIR and IRR are declared as constant type (like parameter), then you should remove the square brackets:
parameter position = 0*IRL+1000*CIR+2000*IRR;

Please Explain Octave-Error : operator /: nonconformant arguments (op1 is 1x1, op2 is 1x10)

I have an issue running a certain script in octave.
This is the code that produces the error:
#germanium
T=410:20:600;
x=linspace(400,410,100);
y=linspace(10^9,10^9,100);
k=8.5*10 .^(-5);
Eg=0.59;
Nc300=1.02*10^13;
Nc=Nc300*((T/300).^(3/2));
n=Nc*(e.^(-Eg/(2*k*T)));
plot(T,n,x,y,'m');
grid on
xlabel('Temprature');
ylabel('Electron Density n');
title('Germanium n(T)');
As mentioned in the Title, the error that is produced is the following:
error: ger5: operator /: nonconformant arguments (op1 is 1x1, op2 is 1x10)
I have done a lot of testing, and I figured that the problem originates from the T variable on the 9th line : n=Nc*(e.^(-Eg/(2*k*T)));
The codes run fine without it. For example :
#germanium
T=410:20:600;
x=linspace(400,410,100);
y=linspace(10^9,10^9,100);
k=8.5*10 .^(-5);
Eg=0.59;
Nc300=1.02*10^13;
Nc=Nc300*((T/300).^(3/2));
n=Nc*(e.^(-Eg/(2*k*500)));
plot(T,n,x,y,'m');
grid on
xlabel('Temprature');
ylabel('Electron Density n');
title('Germanium n(T)');
In which case I simply replaced T with 500 , the code runs perfectly fine.
Sadly T, can not be replaced by a certain number since it is the variable used in my graph. Although I did some digging, I never managed to fully understand this error, or how to fix it, thus any help would be greatly appreciated.
Thanks.
Add a . before your *, /, and ^ signs. This will ensure that octave uses scalar multiplication instead of matrix multiplication.
n=Nc.*(e.^(-Eg./(2.*k.*T)));

What is wrong with this mat lab code?

This is the problem:
Write a function called top_right that takes two inputs: a matrix N and a scalar non-negative integer n, in that order, where each dimension of N is greater than or equal to n. The function returns the n-by-n square array at the top right corner of N.
My code:
function s=top_right(A,n)
s=A(1:n,end-n+1:end);
I dont know where I am wrong,
Thank you!
from your post and the corresponding commments its fair to assume you are new to MATLAB and stackoverflow. first to your question:
Your code works fine and does what it should, but i think it is somewhere it the script you work in. to use that as a function open a new script copy
function s=top_right(A,n)
s=A(1:n,end-n+1:end);
end
in there and save as 'top_right.m' (the name will be suggested when you save). while you work in that folder you can call your function with top_right(A,n)
Second on how to ask question here so you can get a correct answer quickly. Check https://stackoverflow.com/help/mcve and make your question look like it is described, like:
hey you beautiful people! i am trying to get the top_right function to work, which should return the top right part of a matrix. my code is:
A=[(1:10)'*(1:10)];
function s=top_right(A,n)
s=A(1:n,end-n+1:end);
end;
but leaves me with the error
Error: File: test.m Line: 1 Column: 1
Function definitions are not permitted in this context.
Welcome to stackoverflow!

Halide::Expr' is not contextually convertible to 'bool' -- Storing values of functions in variables

I am new to using Halide and I am playing around with implementing algorithms first. I am trying to write a function which, depending on the value of the 8 pixels around it, either skips to the next pixel or does some processing and then moves on to the next pixel. When trying to write this I get the following compiler error:
84:5: error: value of type 'Halide::Expr' is not contextually convertible to 'bool'
if(input(x,y) > 0)
I have done all the tutorials and have seen that the select function is an option, but is there a way to either compare the values of a function or store them somewhere?
I also may be thinking about this problem wrong or might not be implementing it with the right "Halide mindset", so any suggestions would be great. Thank you in advance for everything!
The underlying issue here is that, although they are syntactically interleaved, and Halide code is constructed by running C++ code, Halide code is not C++ code and vice versa. Halide code is entirely defined by the Halide::* data structures you build up inside Funcs. if is a C control flow construct; you can use it to conditionally build different Halide programs, but you can't use it inside the logic of the Halide program (inside an Expr/Func). select is to Halide (an Expr which conditionally evaluates to one of two values) as if/else is to C (a statement which conditionally executes one of two sub-statements).
Rest assured, you're hardly alone in having this confusion early on. I want to write a tutorial specifically addressing how to think about staged programming inside Halide.
Until then, the short, "how do I do what I want" answer is as you suspected and as Khouri pointed out: use a select.
Since you've provided no code other than the one line, I'm assuming input is a Func and both x and y are Vars. If so, the result of input(x,y) is an Expr that you cannot evaluate with an if, as the error message indicates.
For the scenario that you describe, you might have something like this:
Var x, y;
Func input; input(x,y) = ...;
Func output; output(x,y) = select
// examine surrounding values
( input(x-1,y-1) > 0
&& input(x+0,y-1) > 0
&& ...
&& input(x+1,y+1) > 0
// true case
, ( input(x-1,y-1)
+ input(x+0,y-1)
+ ...
+ input(x+1,y+1)
) / 8
// false case
, input(x,y)
);
Working in Halide definitely requires a different mindset. You have to think in a more mathematical form. That is, a statement of a(x,y) = b(x,y) will be enforced for all cases of x and y.
Algorithm and scheduling should be separate, although the algorithm may need to be tweaked to allow for better scheduling.

Unclassifiable statement when calling a specific function

I want to add a function to my code that will calculate some variable. I created a dummy function
double precision FUNCTION rawSE(x)
double precision x
real ax
rawSE = 0.0d0
return
END
And I call it using
selfE=rawSE(1.0d0)
When I try to compile the code, I get the error in the title. When I replace the rawSE with a value (1.0d0) I don't get an error. When I replace it with another function, I don't get an error. I copied a function that work properly and renamed it. I get the error.
So... what is going on here? This is not a column position issue (at least not a simple one) as they are all start on the same line.
How to resolve this?
The rawSE function was declared in a module and a value was expected instead of a function. Moving the declaration out of the module part solved this.
I asked whether you declared rawSE in the program that uses it, and you replied that you declared it as double precision. Do you mean that you declare the function both in the module and in the program that uses the module? Like this?
module my_stuff
implicit none
contains
double precision FUNCTION rawSE(x)
double precision x
rawSE = 2.0d0 * x
return
end FUNCTION rawSE
end module my_stuff
program test_rawSE
use my_stuff
implicit none
double precision rawSE ! <-- This line
write (*, *) rawSE (2.0d0)
end program test_rawSE
If so, that is the problem. You should declare the function once, so the line "This line" should be removed. It is better to keep the module because that makes the interface explicit to the compiler. Not only does it "know" that that the function return is double precision, it also "knows" that the function has a single double-precision argument. This enables it to check the arguments of calls for consistency with these properties.
P.S. gfortran 4.1 is really old and out of date. More recent versions are much improved. That might be why the error message is cryptic. gfortran 4.7 identifies that two statements conflict with each other:
double precision rawSE
1
rawSE.f90:18.4:
use my_stuff
2
Error: Symbol 'rawse' at (1) conflicts with symbol from module 'my_stuff', use-associated at (2)

Resources