I have one int array and one float array, both of size 9. I multiply them by each other. I have two ways of doing it that I thought were equal, but give different results!
As you can see, the first one uses a for-loop, and the second one unrolls it all out. When I use the second one, I get the results I expect, and when I use the first one ( the for-loop ) I get weird results and I can't figure out why.
The pixels array is int, and the kernel array is float. Is it just me, or is there something wrong going on?
If blue2 is an int, then at each point in the loop, you're rounding your result to an int. In the unrolled version, you are doing floating point arithmetic, before saving the entire result in an int. So with the second version, you only do the rounding once, where in the loop version, you do it for every iteration.
Try using a float as your accumulator in the loop, and then after the loop save the answer into blue2.
The novice realizes that the difference between code and data is trivial. The expert realizes that all code is data. And the true master realizes that all data is code.
blue2 is type int! I knew it had something to do with the different types, but couldn't figure out what! You hit the nail right on the head dude! I changed blue2 to float and when I needed it, just type-casted it back to int and voila! Thank you kind sir!