<div dir="ltr">Hello! <div><br></div><div>If you feel like taking on a little challenge read on!</div><div><br></div><div>I am currently working on a gambit UI kit that is</div><div>containing glfw and OpenGL</div><div><br>
</div><div>(It will be open source and free)</div><div><br></div><div>It will also be native to gambit, so no weird hocus pokus required!</div><div>Well a little bit of black magic and sacrificial of virgins is always needed to get things to run properly...</div>
<div><br></div><div>(The result will hopefully be better then my so called jokes)</div><div><br></div><div><br></div><div>Since modern OpenGL requires some hefty matrix math I need to make a matrix math library.</div><div>
Since I want this to be multi platform compatible and easy to use even in the interpreter. I have to do all this in scheme. </div><div>(Except we're forced to allocate the the scheme binary vectors in c to make them not move during garbage collection)</div>
<div><br></div><div>But back to business!</div><div>I've made the following macro and procedure to test matrix multiplication</div><div><br></div><div>(To test simply copy paste into interpreter)</div><div><br></div><div>
But as you will se on the test i've added on the last row of code this is a pretty "slow" procedure.</div><div><br></div><div>The question is, How do you make this quicker?</div><div><br></div><div>Thank you for reading this long! :)</div>
<div><br></div><div>!!!! warning "ugly" code</div><div>#######################CODE START############################</div><div><p style="margin:0px;font-size:12px;font-family:'Anonymous Pro';color:rgb(2,145,146)">
;; because the multiplication of matricies require a ton of commands we make a macro! :D</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro';color:rgb(2,145,146)">;; the macro requires the nr of columns and the number of rows and the current position of both column and row</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">(<span style="color:rgb(64,64,64)">define-macro</span>  (f32-mat*-elem columns rows column-pos row-pos first-vector second-vector)</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">  (<span style="color:rgb(4,52,255)">let</span> ((result '()))</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">    (<span style="color:rgb(4,52,255)">let</span> loop ((i <span style="color:rgb(113,10,0)">0</span>))</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">      (<span style="color:rgb(209,29,0)">set!</span> result (cons  `(##fl* (##f32vector-ref ,first-vector  ,(fx+ row-pos i))</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">                                  (##f32vector-ref ,second-vector ,(fx+ column-pos (* i columns)))</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">                                  ) result))</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">      (<span style="color:rgb(4,52,255)">if</span> (not (eq? i rows)) (loop (+ i <span style="color:rgb(113,10,0)">1</span>)))</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">      )</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">    (<span style="color:rgb(209,29,0)">set!</span> result (reverse result))</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">    `(##fl+ ,@result)</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">    ))</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro';color:rgb(2,145,146)">;; multiplies two matricites of the dimetions 4x4 into one</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">(<span style="color:rgb(64,64,64)">define</span> (f32mat4* first-vector second-vector)</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">  (f32vector <span style="color:rgb(2,145,146)">;;-still</span></p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">   (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">0</span> <span style="color:rgb(113,10,0)">0</span> first-vector second-vector)  (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">1</span> <span style="color:rgb(113,10,0)">0</span> first-vector second-vector) (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">2</span> <span style="color:rgb(113,10,0)">0</span> first-vector second-vector) (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">3</span> <span style="color:rgb(113,10,0)">0</span> first-vector second-vector)</p>

<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">   (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">0</span> <span style="color:rgb(113,10,0)">1</span> first-vector second-vector)  (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">1</span> <span style="color:rgb(113,10,0)">1</span> first-vector second-vector) (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">2</span> <span style="color:rgb(113,10,0)">1</span> first-vector second-vector) (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">3</span> <span style="color:rgb(113,10,0)">1</span> first-vector second-vector)</p>

<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">   (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">0</span> <span style="color:rgb(113,10,0)">2</span> first-vector second-vector)  (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">1</span> <span style="color:rgb(113,10,0)">2</span> first-vector second-vector) (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">2</span> <span style="color:rgb(113,10,0)">2</span> first-vector second-vector) (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">3</span> <span style="color:rgb(113,10,0)">2</span> first-vector second-vector)</p>

<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">   (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">0</span> <span style="color:rgb(113,10,0)">3</span> first-vector second-vector)  (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">1</span> <span style="color:rgb(113,10,0)">3</span> first-vector second-vector) (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">2</span> <span style="color:rgb(113,10,0)">3</span> first-vector second-vector) (f32-mat*-elem <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">4</span> <span style="color:rgb(113,10,0)">3</span> <span style="color:rgb(113,10,0)">3</span> first-vector second-vector)</p>

<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">   ))</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro';min-height:14px"><br></p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">(<span style="color:rgb(64,64,64)">define</span> x (f32vector 1. 2. 3. 4. 1. 2. 3. 4. 1. 2. 3. 4. 1. 2. 3. 4.))</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">(<span style="color:rgb(64,64,64)">define</span> y (f32vector 1. 2. 3. 4. 1. 2. 3. 4. 1. 2. 3. 4. 1. 2. 3. 4.))</p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro';min-height:14px"><br></p>
<p style="margin:0px;font-size:12px;font-family:'Anonymous Pro'">(time (<span style="color:rgb(4,52,255)">let</span> loop ((i <span style="color:rgb(113,10,0)">1000</span>)) (f32mat4* x y) (<span style="color:rgb(4,52,255)">if</span> (not (eq? i <span style="color:rgb(113,10,0)">0</span>)) (loop (- i <span style="color:rgb(113,10,0)">1</span>)))))</p>
####################### CODE END ####################################</div></div>