Problem Computing Dot Product with mir

Kyle Ingraham kyle at kyleingraham.com
Sun Feb 21 16:18:05 UTC 2021


I am trying to convert sRGB pixel values to XYZ with mir using 
the following guide: 
http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html

My problem is that I cannot figure out how to calculate a dot 
product using mir. Here is my code:

import std.stdio;

import mir.glas.l1 : dot;
import mir.ndslice;

void main()
{
	auto rgbToXyz = [0.4124564,  0.3575761,  0.1804375,
					 0.2126729,  0.7151522,  0.0721750,
  					 0.0193339,  0.1191920,  0.9503041]
  		.as!double
		.sliced(3, 3);

	alias reduceDot = reduce!"a * b";

	auto pixels = [255, 0, 0,
	 			   0, 255, 0,
	  			   0, 0, 255,
	   			   120, 120, 120]
		// convert input array elements to double - lazy
		.as!double
		// create a slice-shell over the input array
		.sliced(2, 2, 3)
		// normalize to range [0, 1]
		.map!(p => p / 255.0)
		// sRGB inverse compand
		.map!(V => V <= 0.04045 ? V / 12.92 : ((V + 0.055) / 1.055) ^^ 
2.4)
		// linear RGB to XYZ
		// iterator over pixel values - 3rd dimension
		.pack!1
		// dot product of pixel value with conversion matrix
		.map!(a => reduceDot(rgbToXyz, a));
		//.map!(a => dot(rgbToXyz, a));

	writeln(pixels);
	writeln(pixels.shape);
}

In the last step I am trying to take each pixel value from my 2x2 
'image' and compute a dot product of it and the conversion matrix 
rgbToXyz.

I have tried reduce and that results in:

Error: cannot implicitly convert expression 
nonInlinedNaryFun(seed, ls()) of type 
Slice!(VmapIterator!(double*, LeftOp!("*", double)), 2LU, 
cast(mir_slice_kind)2) to Slice!(double*, 2LU, 
cast(mir_slice_kind)2)

I have also tried dot from mir.glas.l1:

Error: template mir.glas.l1.dot cannot deduce function from 
argument types !()(Slice!(double*, 2LU, cast(mir_slice_kind)2), 
Slice!(MapIterator!(int*, pipe), 1LU, cast(mir_slice_kind)2))

I was expecting the conversion matrix (3x3) dotted with the pixel 
(3x1) to produce another pixel (3x1). What am I doing wrong here?


More information about the Digitalmars-d-learn mailing list