Csound Csound-dev Csound-tekno Search About

[Csnd] Initialisation issues with k-rate arrays

Date2023-09-22 19:28
From"Jeanette C."
Subject[Csnd] Initialisation issues with k-rate arrays
Hey hey,
I've come up against a challange I can't solve. I have an opcode with a 2d 
array parameter, internally a slightly transformed version of that matrix 
shall be stored. Updates only occur when the input parameter changes. the idea 
is:
init interla matrix from parameter matrix
if parameter matrix has changed
   update at k-rate

The code construct for the initialisation appears to fail.

The parameter handed to the opcode is known as
kRoutes

The internal matrix is called:
kMatrix
the first dimension is iterated through with iIndIns, the second dimension 
with iIndOuts. iIndInsWrite is the actual position in kMatrix where something 
will be written.

Consider this piece of code, Itried variants...
iIndOuts = 0
while (iIndOuts < iLenOuts) do
   iIndIns = 0 ; reset pointer to kRoutes
   iIndInsWrite = 0 ; reset pointer to kMatrix
   while (iIndIns < iLenIns) do
     if (kRoutes[iIndIns][iIndOuts] == 1 ) then ; This fails, I think!
       kMatrix[iIndInsWrite][iIndOuts] = iIndIns
 	   iIndInsWrite += 1
     endif
 	 iIndIns += 1
   od

   ; Fill the rest of the column
   while (iIndInsWrite < iLenIns) do
     kMatrix[iIndInsWrite][iIndOuts] = -1
 	 iIndInsWrite += 1
   od
   iIndOuts += 1
od

Instead of if (kRoutes[... I also tried if (i(kRoutes, ...)
I also tried using:
kMatrix[iIndInsWrite][iIndOuts] init iIndIns
So exchanging init for '='.

The best I could get with using init for assignment to matrix was a
matrix of -1. Otherwise I get a matrix of 0.

does anyone have an idea how to properly code/structure this use-case?
Or does anyone know which point I missed?

Best wishes,

Jeanette

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

I thought love was just a tingling of the skin <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2023-09-22 20:41
Fromjoachim heintz
SubjectRe: [Csnd] Initialisation issues with k-rate arrays
would it work with setrow?

and can you break down your code to a more minimal example?

(my guess is that kArr[i][i] does not work.)

	joachim


On 22/09/2023 20:28, Jeanette C. wrote:
> Hey hey,
> I've come up against a challange I can't solve. I have an opcode with a 
> 2d array parameter, internally a slightly transformed version of that 
> matrix shall be stored. Updates only occur when the input parameter 
> changes. the idea is:
> init interla matrix from parameter matrix
> if parameter matrix has changed
>    update at k-rate
> 
> The code construct for the initialisation appears to fail.
> 
> The parameter handed to the opcode is known as
> kRoutes
> 
> The internal matrix is called:
> kMatrix
> the first dimension is iterated through with iIndIns, the second 
> dimension with iIndOuts. iIndInsWrite is the actual position in kMatrix 
> where something will be written.
> 
> Consider this piece of code, Itried variants...
> iIndOuts = 0
> while (iIndOuts < iLenOuts) do
>    iIndIns = 0 ; reset pointer to kRoutes
>    iIndInsWrite = 0 ; reset pointer to kMatrix
>    while (iIndIns < iLenIns) do
>      if (kRoutes[iIndIns][iIndOuts] == 1 ) then ; This fails, I think!
>        kMatrix[iIndInsWrite][iIndOuts] = iIndIns
>         iIndInsWrite += 1
>      endif
>       iIndIns += 1
>    od
> 
>    ; Fill the rest of the column
>    while (iIndInsWrite < iLenIns) do
>      kMatrix[iIndInsWrite][iIndOuts] = -1
>       iIndInsWrite += 1
>    od
>    iIndOuts += 1
> od
> 
> Instead of if (kRoutes[... I also tried if (i(kRoutes, ...)
> I also tried using:
> kMatrix[iIndInsWrite][iIndOuts] init iIndIns
> So exchanging init for '='.
> 
> The best I could get with using init for assignment to matrix was a
> matrix of -1. Otherwise I get a matrix of 0.
> 
> does anyone have an idea how to properly code/structure this use-case?
> Or does anyone know which point I missed?
> 
> Best wishes,
> 
> Jeanette
> 

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2023-09-23 02:02
From"Jeanette C."
SubjectRe: [Csnd] Initialisation issues with k-rate arrays
Hi Joachim,
my application is a matrix mixer. I get in a full matrix, with a 1 at each 
point where a connection is made and try to condense the number of 
multiplications and additions by having another matrix which only contains the 
necessary indices to focus on. For that I have to initialise this "condensed" 
internal matrix. The internal matrix contains the array indices that are 
relevant and -1 after that. Example. The connections matrix looks like this:
out1 out2
0    1 in1
1    0 in2
this condesned matrix:
out1 out2
1    0 in1
-1  -1 in2
So in the real multiplications that happen every k-cycle, I will loop:
while index2 < cols
   while index1 < rows
   if kmatrix[index1][index2] == -1
     index1 = huge!
   index1++
index2++
I update the internal kmatrix whenver something changes in the real 
connections matrix at k-rate,but I have to initialise it once. the idea is: in 
your average matrx mixer out of n times n i/o combinations you will only use a 
fraction and thus it is good sense to optimised the looping and 
multiplication and addition operations.

Does that make more sense?

In the end it comes down to operations like:
aOut[IndexOut] = aOut[IndexOut] + aIn[Indexin] * kLevel[IndexIn]
If the inner IndexIn loop can be be shortened to the actual number of inputs 
summed into the output that is a great help. That expression is simplified, I 
actually take the IndexIn from the condensed kMatrix. Thus it's a twofold 
process.

Best wishes,

Jeanette

Sep 22 2023, joachim heintz has written:

> would it work with setrow?
>
> and can you break down your code to a more minimal example?
>
> (my guess is that kArr[i][i] does not work.)
>
> 	joachim
>
>
> On 22/09/2023 20:28, Jeanette C. wrote:
>>  Hey hey,
>>  I've come up against a challange I can't solve. I have an opcode with a 2d
>>  array parameter, internally a slightly transformed version of that matrix
>>  shall be stored. Updates only occur when the input parameter changes. the
>>  idea is:
>>  init interla matrix from parameter matrix
>>  if parameter matrix has changed
>>     update at k-rate
>>
>>  The code construct for the initialisation appears to fail.
>>
>>  The parameter handed to the opcode is known as
>>  kRoutes
>>
>>  The internal matrix is called:
>>  kMatrix
>>  the first dimension is iterated through with iIndIns, the second dimension
>>  with iIndOuts. iIndInsWrite is the actual position in kMatrix where
>>  something will be written.
>>
>>  Consider this piece of code, Itried variants...
>>  iIndOuts = 0
>>  while (iIndOuts < iLenOuts) do
>>     iIndIns = 0 ; reset pointer to kRoutes
>>     iIndInsWrite = 0 ; reset pointer to kMatrix
>>     while (iIndIns < iLenIns) do
>>       if (kRoutes[iIndIns][iIndOuts] == 1 ) then ; This fails, I think!
>>         kMatrix[iIndInsWrite][iIndOuts] = iIndIns
>>          iIndInsWrite += 1
>>       endif
>>        iIndIns += 1
>>     od
>>
>>     ; Fill the rest of the column
>>     while (iIndInsWrite < iLenIns) do
>>       kMatrix[iIndInsWrite][iIndOuts] = -1
>>        iIndInsWrite += 1
>>     od
>>     iIndOuts += 1
>>  od
>>
>>  Instead of if (kRoutes[... I also tried if (i(kRoutes, ...)
>>  I also tried using:
>>  kMatrix[iIndInsWrite][iIndOuts] init iIndIns
>>  So exchanging init for '='.
>>
>>  The best I could get with using init for assignment to matrix was a
>>  matrix of -1. Otherwise I get a matrix of 0.
>>
>>  does anyone have an idea how to properly code/structure this use-case?
>>  Or does anyone know which point I missed?
>>
>>  Best wishes,
>>
>>  Jeanette
>> 
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>       https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

I thought love was just a tingling of the skin <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2023-09-23 08:12
Fromjoachim heintz
SubjectRe: [Csnd] Initialisation issues with k-rate arrays
hi jeanette -

sure it makes sense.  i just thought it could be good to have a minimal 
example to see why / what is not working.

i remember when i was working with 2d arrays i had to use the setrow 
opcode, but i don't know if it was the same problem as in your case.

best -
	joachim


On 23/09/2023 03:02, Jeanette C. wrote:
> Hi Joachim,
> my application is a matrix mixer. I get in a full matrix, with a 1 at 
> each point where a connection is made and try to condense the number of 
> multiplications and additions by having another matrix which only 
> contains the necessary indices to focus on. For that I have to 
> initialise this "condensed" internal matrix. The internal matrix 
> contains the array indices that are relevant and -1 after that. Example. 
> The connections matrix looks like this:
> out1 out2
> 0    1 in1
> 1    0 in2
> this condesned matrix:
> out1 out2
> 1    0 in1
> -1  -1 in2
> So in the real multiplications that happen every k-cycle, I will loop:
> while index2 < cols
>    while index1 < rows
>    if kmatrix[index1][index2] == -1
>      index1 = huge!
>    index1++
> index2++
> I update the internal kmatrix whenver something changes in the real 
> connections matrix at k-rate,but I have to initialise it once. the idea 
> is: in your average matrx mixer out of n times n i/o combinations you 
> will only use a fraction and thus it is good sense to optimised the 
> looping and multiplication and addition operations.
> 
> Does that make more sense?
> 
> In the end it comes down to operations like:
> aOut[IndexOut] = aOut[IndexOut] + aIn[Indexin] * kLevel[IndexIn]
> If the inner IndexIn loop can be be shortened to the actual number of 
> inputs summed into the output that is a great help. That expression is 
> simplified, I actually take the IndexIn from the condensed kMatrix. Thus 
> it's a twofold process.
> 
> Best wishes,
> 
> Jeanette
> 
> Sep 22 2023, joachim heintz has written:
> 
>> would it work with setrow?
>>
>> and can you break down your code to a more minimal example?
>>
>> (my guess is that kArr[i][i] does not work.)
>>
>>     joachim
>>
>>
>> On 22/09/2023 20:28, Jeanette C. wrote:
>>>  Hey hey,
>>>  I've come up against a challange I can't solve. I have an opcode 
>>> with a 2d
>>>  array parameter, internally a slightly transformed version of that 
>>> matrix
>>>  shall be stored. Updates only occur when the input parameter 
>>> changes. the
>>>  idea is:
>>>  init interla matrix from parameter matrix
>>>  if parameter matrix has changed
>>>     update at k-rate
>>>
>>>  The code construct for the initialisation appears to fail.
>>>
>>>  The parameter handed to the opcode is known as
>>>  kRoutes
>>>
>>>  The internal matrix is called:
>>>  kMatrix
>>>  the first dimension is iterated through with iIndIns, the second 
>>> dimension
>>>  with iIndOuts. iIndInsWrite is the actual position in kMatrix where
>>>  something will be written.
>>>
>>>  Consider this piece of code, Itried variants...
>>>  iIndOuts = 0
>>>  while (iIndOuts < iLenOuts) do
>>>     iIndIns = 0 ; reset pointer to kRoutes
>>>     iIndInsWrite = 0 ; reset pointer to kMatrix
>>>     while (iIndIns < iLenIns) do
>>>       if (kRoutes[iIndIns][iIndOuts] == 1 ) then ; This fails, I think!
>>>         kMatrix[iIndInsWrite][iIndOuts] = iIndIns
>>>          iIndInsWrite += 1
>>>       endif
>>>        iIndIns += 1
>>>     od
>>>
>>>     ; Fill the rest of the column
>>>     while (iIndInsWrite < iLenIns) do
>>>       kMatrix[iIndInsWrite][iIndOuts] = -1
>>>        iIndInsWrite += 1
>>>     od
>>>     iIndOuts += 1
>>>  od
>>>
>>>  Instead of if (kRoutes[... I also tried if (i(kRoutes, ...)
>>>  I also tried using:
>>>  kMatrix[iIndInsWrite][iIndOuts] init iIndIns
>>>  So exchanging init for '='.
>>>
>>>  The best I could get with using init for assignment to matrix was a
>>>  matrix of -1. Otherwise I get a matrix of 0.
>>>
>>>  does anyone have an idea how to properly code/structure this use-case?
>>>  Or does anyone know which point I missed?
>>>
>>>  Best wishes,
>>>
>>>  Jeanette
>>>
>>
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>> Send bugs reports to
>>       https://github.com/csound/csound/issues
>> Discussions of bugs and features can be posted here
>>
> 

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2023-09-23 12:52
From"Jeanette C."
SubjectRe: [Csnd] Initialisation issues with k-rate arrays
Hi Joachim,
Sep 23 2023, joachim heintz has written:
...
> i remember when i was working with 2d arrays i had to use the setrow opcode, 
> but i don't know if it was the same problem as in your case.
...
I did naturally come across setrow and setcol. I must admit that I'm not
sure which one pertains to wich dimension of the array.

Best wishes and thanks,

Jeanette

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

Baby, take the time to realize
I'm not the kind to sacrifice <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here