Re: Submatrix function and arrays

2020-03-29 Thread zetashift
Wow weird, I missed your post in it's entirety. Yardanico on IRC/Gitter also got the same error so it I don't think it's something that's wrong locally. Anyway I couldn't solve it, I opened a GitHub issue here: [https://github.com/nim-lang/Nim/issues/13785](https://github.com/nim-lang/Nim/issue

Re: Submatrix function and arrays

2020-03-27 Thread zetashift
I seem to be able to reproduce the problem on the playground too: [https://play.nim-lang.org/#ix=2fGO](https://play.nim-lang.org/#ix=2fGO) If you uncomment the lines in the suite it'll error out. So the problem wasn't with == but with something I'm setup-ing wrong in the suite I guess.. I'll ti

Re: Submatrix function and arrays

2020-03-27 Thread Stefan_Salewski
It is hard to believe that it is OS related, but maybe it is. I did my test on Linux 64 bit. Maybe you can ask on IRC hoping that someone has the same OS and Nim version as you. First I had the impression that it may be related to other packages that you may have installed, but when you do not

Re: Submatrix function and arrays

2020-03-27 Thread conlaoch
If it works on the playground, and it works when you compile the snippet, whats in your projects nimcache that is conflicting/overriding it? Can you clean the nimcache and recompile everything? Now, just for full disclosure, I have maybe 3 hours of Nim experience, but I have done lots of portin

Re: Submatrix function and arrays

2020-03-27 Thread zetashift
I'm not the smartest but I tried to postpone this thread as long as possible to and try different things on my own, so I can't accept lazy man D: . I can see why == is the main problem here, what blocks me is that it works fine on the playground, also when I run that playground snippet on my loc

Re: Submatrix function and arrays

2020-03-27 Thread Stefan_Salewski
> no idea how to fix this I think you are only lazy :-) The general approach would be to shrink and simplify the code -- the core problem seems to be the ==`() proc, so one would remove all what is not necessary to test this proc, and maybe to modify or simplify that proc. For example I would

Re: Submatrix function and arrays

2020-03-27 Thread zetashift
See my project here: [https://github.com/zetashift/naytracer](https://github.com/zetashift/naytracer) the code I pasted in the playground comes from src/naytracerpkg/matrix.nim having the definitations and tests/tmatrix.nim having the test. The test fails for me on my local machine with a type

Re: Submatrix function and arrays

2020-03-27 Thread Stefan_Salewski
The code from the playground link above compiles and runs fine with my Nim compiler, which is latest devil. Even with new --gc:arc option.

Re: Submatrix function and arrays

2020-03-26 Thread zetashift
Ah sorry seems I posted a faulty link there, it all boils down too: [https://play.nim-lang.org/#ix=2fBQ](https://play.nim-lang.org/#ix=2fBQ)

Re: Submatrix function and arrays

2020-03-26 Thread zetashift
Well on my computer Nim compiler still throws the error out, I have no idea why it compiles correctly on the playground because I literally copy pasted my code blocks... Andd thanks for the tip on the equals function, I got it from a quick google and I thought it would suffice for this project

Re: Submatrix function and arrays

2020-03-26 Thread Stefan_Salewski
Fine that it works for you now. For your equal test, I personally would never do it in that way, as with physics background we may work with really tiny values like plank constant (6 * 10^-34) and many more really small values. Maybe better somethink like (a/b - 1.0).abs < 1e-12

Re: Submatrix function and arrays

2020-03-26 Thread zetashift
So test() and check() are from the unittest module. As for my newMatrix function: func newMatrix*[W, H: static int](elements: array[W, array[H, float]]): Matrix[W, H] = result = elements Run My equals() function being this float comparison function:

Re: Submatrix function and arrays

2020-03-26 Thread Stefan_Salewski
> So with the == is where I'm getting that error. I have no idea what exactly your newMatrix(), your equal(), your check() and your test() is, so it is too hard for me to guess the error.

Re: Submatrix function and arrays

2020-03-26 Thread zetashift
Ah yes I forgot I was using that function in a test like this: test "getting the submatrix of a 4 x 4 matrix with row / column indicators": check matrix4x4.submatrix(2, 1) == [[-6.0, 1.0, 6.0], [-8.0, 8.0, 6.0],

Re: Submatrix function and arrays

2020-03-25 Thread solo989
Find at the top of the manual page only gives you proc/template/macro/etc headers. I barely ever use it. Try searching the webpage manually using the the find shortcut built into your web browser.

Re: Submatrix function and arrays

2020-03-25 Thread zetashift
Currently also struggling with this type mismatch error with using this function: # Remove specified row and column func submatrix*[W, H](m: Matrix[W, H], rowIdx, colIdx: int): Matrix[W - 1, H - 1] = for row in 0 .. high(m): var resultRow = row if row == ro

Re: Submatrix function and arrays

2020-03-25 Thread Stefan_Salewski
Your error message makes no sense for me, and your proc compiles fine for me: type Matrix*[W, H: static int] = array[W, array[H, float]] func xsubmatrix*[W, H](m: Matrix[W, H]): Matrix[W - 1, H - 1] = for row in 0 ..< high(m): for col in 0 ..< high(m[0]):

Re: Submatrix function and arrays

2020-03-25 Thread zetashift
I didn't know you could do that with generics damn. My initiation function needs a rework with your solution, previously I had: func newMatrix*[W, H](elements: array[W, array[H, float]]): Matrix[W, H] = result = elements Run But with that I get the error:

Re: Submatrix function and arrays

2020-03-25 Thread Stefan_Salewski
You may try type Matrix*[W, H: static int] = array[W, array[H, float]] func submatrix*[W, H](m: Matrix[W, H]): Matrix[W - 1, H - 1] = for row in 0 ..< high(m): for col in 0 ..< high(m[0]): result[row][col] = m[row][col] var m: Matr

Submatrix function and arrays

2020-03-25 Thread zetashift
I have this Matrix type defined as follows: type Matrix*[W, H] = array[W, array[H, float]] Run And for my raytracer I have to make a function that removes the last column and row. But I can't get this right because my submatrix function always returns a matrix o