matrix Diagonal addition

OP #2292567
Rate this post
• ▲ useful
▼ not useful
can somebody help me with a loop for diagonal addtion of a matrix datas.

i need to add the datas of an array but in diagonal fashion say i have a 
3X3 array.


a[3][3]=

0   1    2   3
4   5    6   7
8   9   10  11
12  13  14  15

the answer should be like

0=t0;
4+1=t2
8+5+2=t3;
12+9+6+3=t4;
13+10+7=t5;
14+11=t6;
15=t7;

ie in looply manners

a[0][0]=t[0];

a[1][0]+a[0][1]=t[1];

a[2][0]+a[1][1]+a[0][2]=t2;

a[3][0]+a[2][1]+a[1][2]+a[0][3]=t3;

a[3][1]+a[2][2]+a[1][3]=t4;

a[3][2]+a[2][3]=t5;

a[3][3]=t6;

sorry to make you work

and thanks a lot in advance
Guest #2293259
Rate this post
• ▲ useful
▼ not useful
for i in 0 to array_size-1 loop

   sum[i] := 0

   for x in 0 to array_size-1 loop

      y := i - x

      if (y>=0) then
         sum[i] := sum[i] + a[x][y];
      end if;

   end loop;
end loop;


array_size is 4 in this case.

untested, but should work.
It sums for all "rising" diagonals but drops fields that are not in the 
array.

this is the only one part of the calcs (t0-t3).

You need to copy this and use
y := i + x
as well as
if (y<=array_size-1)

for t3-t6 and ignore the sum that appears double(t3) for one of both.
OP #2295677
Rate this post
• ▲ useful
▼ not useful
abc wrote:
> for i in 0 to array_size-1 loop
>
>    sum[i] := 0
>
>    for x in 0 to array_size-1 loop
>
>       y := i - x
>
>       if (y>=0) then
>          sum[i] := sum[i] + a[x][y];
>       end if;
>
>    end loop;
> end loop;
>
>
> array_size is 4 in this case.
>
> untested, but should work.
> It sums for all "rising" diagonals but drops fields that are not in the
> array.
>
> this is the only one part of the calcs (t0-t3).
>
> You need to copy this and use
> y := i + x
> as well as
> if (y<=array_size-1)
>
> for t3-t6 and ignore the sum that appears double(t3) for one of both.


thanks it helped a lot.. but one more doubt prevails..
when i use the statement
sum(i) <= sum(i) + and1(x,y);
 the compiler gives me an error
"Line 63. + can not have such operands in this context".

sum is been declared as a signal,and1 as an variable of type 
std_logic_vector

pls help

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.