HISE Logo Forum
    • Categories
    • Register
    • Login

    Cartesian product function

    Scheduled Pinned Locked Moved Scripting
    20 Posts 3 Posters 739 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • d.healeyD
      d.healey
      last edited by

      Anyone got one that I can use in HISE, non-realtime of course.

      Libre Wave - Freedom respecting instruments and effects
      My Patreon - HISE tutorials
      YouTube Channel - Public HISE tutorials

      ustkU 1 Reply Last reply Reply Quote 0
      • ustkU
        ustk @d.healey
        last edited by

        @d-healey Does this can help somehow? 🙄

        HiseSnippet 802.3ocsUEtSZDDDdWjqof0lZRe.1vuv.kbXs1lPapUQaHspjh0zDCwrr2hr3wtj81yJw3aae.5aP6r2gbG0SiRRWRHLey2b7MyMyrs0JFOHPoQ3BGMYLGgelSmIRyfcFPERTqlH7yc1mFX3ZRLz1SFSCB3dHLdoOaAvExihN+9iaS8oRFOABgNVIX7uJFILIns25KBe+8nd7iDiRwdisZwTxcT9pPPOK43hFSYmSOie.0RKmCB+jc8DFktigZ3A.msUdS5LP8SYL+iEAhd9bqQcTG3AECi1Yfv2q8M4Z.Bgy2NIyWJNyeoy9BOwL7jJvKhbPRhHcM.madIkeNIU+tjzdJeO6C3NjGNk7xGKuUc5vzhwlDOVssrSKI7xoOEJ6okULWTtegc1QALjlZinmy2SCFyhn7lttUIuw0csFqTDnEn740X9bptrEw9AdgDXHWP0DJ4CjSpWkrd2Fog6YgK4oNqTURIF0Tpai4iiQ0PgQPkVhwNIvYkhVmBuKAX2Hz9JMorHxjHHumPq4ykmYF.VUpr1U2Dl86HpCioNDn1aF0gITSnaOyjwIv+YWqVnmH5Vkz6jgcsp51Q.7pToQj40Eu1JvPIyHTRhRdfxvOTVdshWUr.3i7ut52OSe1WEZkuOWmoa63f99BrrLbTOttJTX8C4yHB8Hy2Dt7CqIjE2YjhnR1RJLGNlO0NoM05KNquwqKZVxlFJIGSiFkZYPKA51SAnoctvu9dqlTC0NXLEC3MlqMBa1haxu.1xDOlTvoIO3biZLrm4VyPvjrxKzmZle71tGapCnbO2bjcVQFHLSRum6QLy6l4Le8rx1GnbW0osvvFjsdykgdgp1+a8NcC5JN61uOmYRDadm89whtt7QHkuoBMB4Y6SMZwkHryAgi5.Whv3fRjRtO7G4fyY6nhscs11JSGtzKx3OvYpy5Va7Tm0uwIZDkoUmxhaas6neZDBnIYz0SEf6IAaRcTzvIDmiaMWzH3piSYLao3Uf1yNl0WfXd8BDyFKPLuYAhYyEHl2t.w7t6MF6s1eJznFEOl..s2MZMBFuqjBcYQcjn+BDRxXFB
        

        Can't help pressing F5 in the forum...

        1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey
          last edited by

          Thanks, I need it to work with an unknown number of arrays but I think this gets me in the right direction.

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          ustkU 1 Reply Last reply Reply Quote 0
          • ustkU
            ustk @d.healey
            last edited by

            @d-healey said in Cartesian product function:

            Thanks, I need it to work with an unknown number of arrays but I think this gets me in the right direction.

            I was sure of that, damn it 😛

            Can't help pressing F5 in the forum...

            1 Reply Last reply Reply Quote 0
            • d.healeyD
              d.healey
              last edited by d.healey

              I feel I'm getting close with this but I'm missing something. Any ideas?

              const var data = [
                  [1, 2, 3],
                  ["dog", "cat", "fish"]
              ];
              
              const var cp = cartesianProduct(data);
              
              inline function cartesianProduct(array)
              {
                  local i;
                  local j;
                  local k;
                  
                  local result = [[]];
              
                  for (i = 0; i < array.length; i++)
                  {
                      local subArray = array[i];
                      local temp = [];
                      
                      for (j = 0; j < result.length; j++)
                      {
                          for (k = 0; k < subArray.length; k++)
                          {
                              concatArrays(result[j], [subArray[k]]);
                              temp.push(result[j]);
                          }
                      }
                      result = temp;
                  }
              
                  return result;
              }
              
              inline function concatArrays(a, b)
              {
                  local i;    
                  for (i = 0; i < b.length; i++) a.push(b[i]);
              }
              

              Libre Wave - Freedom respecting instruments and effects
              My Patreon - HISE tutorials
              YouTube Channel - Public HISE tutorials

              1 Reply Last reply Reply Quote 0
              • ustkU
                ustk
                last edited by

                @d-healey Will the inner arrays inside data have the same size?

                Can't help pressing F5 in the forum...

                d.healeyD 1 Reply Last reply Reply Quote 0
                • d.healeyD
                  d.healey @ustk
                  last edited by

                  @ustk Not always.

                  Libre Wave - Freedom respecting instruments and effects
                  My Patreon - HISE tutorials
                  YouTube Channel - Public HISE tutorials

                  1 Reply Last reply Reply Quote 0
                  • d.healeyD
                    d.healey
                    last edited by

                    I just did a test in jsfiddle using the proper javascript concat function temp.push(result[j].concat(array[i][k])); and it worked. So I think it's something to do with the way I've implemented my concat function in HISE.

                    Libre Wave - Freedom respecting instruments and effects
                    My Patreon - HISE tutorials
                    YouTube Channel - Public HISE tutorials

                    1 Reply Last reply Reply Quote 0
                    • ustkU
                      ustk
                      last edited by

                      @d-healey Ouch...
                      Do you mean like:

                      [
                      [1, 2, 3],
                      [a, b, c, d, e, f],
                      [15, 16]
                      ]
                      

                      That complicates the beast a wee bit...

                      Can't help pressing F5 in the forum...

                      d.healeyD 1 Reply Last reply Reply Quote 0
                      • d.healeyD
                        d.healey @ustk
                        last edited by

                        @ustk Yeah like that.

                        My function works in normal JS once I swap out the concat function. You can see it here - https://jsfiddle.net/aktLe5d9/ - open your developer tools console (F12) to see the output.

                        Libre Wave - Freedom respecting instruments and effects
                        My Patreon - HISE tutorials
                        YouTube Channel - Public HISE tutorials

                        1 Reply Last reply Reply Quote 0
                        • ustkU
                          ustk
                          last edited by

                          @d-healey Found this, it may help:
                          https://rosettacode.org/wiki/Cartesian_product_of_two_or_more_lists

                          Can't help pressing F5 in the forum...

                          d.healeyD 1 Reply Last reply Reply Quote 0
                          • d.healeyD
                            d.healey @ustk
                            last edited by

                            @ustk I found that too :) I'm currently using it to make a new concat function.

                            Libre Wave - Freedom respecting instruments and effects
                            My Patreon - HISE tutorials
                            YouTube Channel - Public HISE tutorials

                            1 Reply Last reply Reply Quote 0
                            • d.healeyD
                              d.healey
                              last edited by

                              Yippie, I got it working.

                              const var data = [
                                  [1, 2, 3],
                                  ["dog", "cat", "fish"]
                              ];
                              
                              const var cp = cartesianProduct(data);
                              
                              inline function cartesianProduct(array)
                              {
                                  local i;
                                  local j;
                                  local k;
                                  
                                  local result = [[]];
                              
                                  for (i = 0; i < array.length; i++)
                                  {
                                      local subArray = array[i];
                                      local temp = [];
                                      
                                      for (j = 0; j < result.length; j++)
                                      {
                                          for (k = 0; k < subArray.length; k++)
                                          {
                                              local c = concatArrays(result[j], [subArray[k]]);
                                              temp.push(c);
                                          }
                                      }
                                      result = temp;
                                  }
                              
                                  return result;
                              }
                              
                              inline function concatArrays(a, b)
                              {    
                                  local c = [];
                                  local i;
                                  
                                  for (i = 0; i < a.length; i++)
                                  {
                                      c[i] = a[i];
                                  }
                                  
                                  for (i = 0; i < b.length; i++)
                                  {
                                      c.push(b[i]);
                                  }
                                  
                                  return c;
                              }
                              

                              Libre Wave - Freedom respecting instruments and effects
                              My Patreon - HISE tutorials
                              YouTube Channel - Public HISE tutorials

                              ustkU 1 Reply Last reply Reply Quote 0
                              • ustkU
                                ustk @d.healey
                                last edited by

                                @d-healey Woww! Good job man! That was a hard one!
                                Could I ask what for you need it?

                                Can't help pressing F5 in the forum...

                                d.healeyD 1 Reply Last reply Reply Quote 0
                                • d.healeyD
                                  d.healey @ustk
                                  last edited by d.healey

                                  @ustk I'm trying to find ways to generate playable guitar chords. I came up with one method already but I was looking for a more efficient way and found this article which uses the cartesian product.

                                  I just tried it in HISE but I'm getting an execution time out error. I think it's quite a slow method to implement in HISE so I'll stick with my existing function for now. Still I'm sure it will come in useful for other things in the future.

                                  This is how it looks so far

                                  Peek 2019-12-22 01-48.gif

                                  Libre Wave - Freedom respecting instruments and effects
                                  My Patreon - HISE tutorials
                                  YouTube Channel - Public HISE tutorials

                                  ustkU NatanN 2 Replies Last reply Reply Quote 3
                                  • ustkU
                                    ustk @d.healey
                                    last edited by ustk

                                    @d-healey Very interesting solution indeed, although I thought there was a simpler solution (just saying, I don't know how...)
                                    Especially since with the cartesian product solution, you have a lot of filtering to implement, apparently.

                                    Can't help pressing F5 in the forum...

                                    1 Reply Last reply Reply Quote 0
                                    • d.healeyD
                                      d.healey
                                      last edited by

                                      My function requires filtering too.

                                      Libre Wave - Freedom respecting instruments and effects
                                      My Patreon - HISE tutorials
                                      YouTube Channel - Public HISE tutorials

                                      1 Reply Last reply Reply Quote 0
                                      • d.healeyD
                                        d.healey
                                        last edited by d.healey

                                        I realised I'd made a mistake implementing Pete Corey's method so I'm attempting it again.

                                        689d111f-2d1a-4899-8a4f-3e94ebabddb1-image.png

                                        Libre Wave - Freedom respecting instruments and effects
                                        My Patreon - HISE tutorials
                                        YouTube Channel - Public HISE tutorials

                                        1 Reply Last reply Reply Quote 2
                                        • NatanN
                                          Natan @d.healey
                                          last edited by

                                          @d-healey Sir David, Any Chance You Suplly The Sacles Interval Numbers?
                                          Thanks

                                          d.healeyD 1 Reply Last reply Reply Quote 0
                                          • d.healeyD
                                            d.healey @Natan
                                            last edited by

                                            @Natanr Not sure what you mean. In the image above it's just a C major chord, so the intervals would be 0, 4, and 7.

                                            Libre Wave - Freedom respecting instruments and effects
                                            My Patreon - HISE tutorials
                                            YouTube Channel - Public HISE tutorials

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            27

                                            Online

                                            1.8k

                                            Users

                                            12.0k

                                            Topics

                                            104.1k

                                            Posts