Intel MKL cblas_dgemm documention error? - blas

This link is the manual of MKL,
http://software.intel.com/sites/products/documentation/hpc/mkl/mklman/index.htm,
and This link is the example of cblas_dgemm,
http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?cmd=getdoc&coll=0650&db=man&fname=3%20INTRO_CBLAS
In the manual, Under RowMajor, NoTransA and NoTransB he says lda is the rows(A),ldb is the rows(B), ldc is the rows(C),
But,
In the example,
float a[10][20], b[20][30], c[10][30];
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 10, 30,
20, 1.0f, a, 20, b, 30, 0.0f, c, 30);
the lda and ldb and ldc is the cols(a) , cols(b) , cols(c)
What's wrong?

The example your showed is correct. For row-major matrix without padding byte, leading dimension is equal to the number of columns.
I can't find lda is the rows(A) in MKL doc, could you provide a traceable link instead?
PS: You may want to change to the latest version of MKL docs.
http://software.intel.com/en-us/articles/intel-math-kernel-library-documentation

Related

Export to Exodus file programmatically similar to can.ex2 example in Paraview

I have a similar question to Writing an Exodus II file programmatically. The linked question has still no accepted answer.
I am performing numerical simulations in MATLAB. My output consists of polyhedra in 3d space and I know the displacement for every vertex in terms of a displacement vector for a finite number of time steps. I would like to visualize the displacement as an animation in Paraview. On YouTube I found a tutorial on animations for the can.ex2 example in Paraview.
Therefore, I would like to export my data (i.e. initial vertex positions + displacement for each time step) to Exodus 2 format or similar. If possible, I would like to avoid any existing library and write the file myself in MATLAB. I was already successful with .vtk/.vti/.obj/... writers for other parts of my project.
Can someone recommend a comprehensive description on how the .ex2 files should be written and/or code that I can orientate myself on? Unfortunately, I was not very successful with my own research. I am also open for suggestions of similar file formats that would be sufficient for my plans.
Edit
Because I was asked for a code example:
% Vertices of unit triangle contained in (x,y)-plane
initialVertexPos = [0, 1, 0;
0, 0, 1;
0, 0, 0];
nVertices = size(initialVertexPos, 2);
% Linear displacement of all vertices along z-axis
nTimeSteps = 10;
disp_x = zeros(nTimeSteps, nVertices);
disp_y = zeros(nTimeSteps, nVertices);
disp_z = repmat(linspace(0,1,nTimeSteps)', 1, nVertices);
% Position of vertex kVertex at time step kTime is given by
% initialVertexPos(:,kVertex) + [disp_x(kTime,kVertex); disp_y(kTime,kVertex); disp_z(kTime,kVertex)]

Method ViroARScene.getCameraOrientationAsync() returns strange values in rotation array

I'm developing a PoC with ViroReact lib but I'm getting strage values for the camera rotation.
Environment:
Device: Android 10. Xiaomi Mi 9
ViroReact 2.20.2
The ViroARScene.getCameraOrientationAsync() returns unexpected values in rotation array when I rotate the device over the y-axis, trying to keep the x and z axis fixed.
Specifically, when the y-axis reaches the -90º the x/z values change to +/180º and from this point the y-axis values are getting close to 0, for instance, instead of -135º the y-axis value is -45 with the x/z values in +/-180. In other words the y-axis values NEVER return an absolute value over 90.
Some examples (values have got an error margin of about 6 degrees):
Rotation expected: [0, -90, 0]. Returned rotation: [+/-180, -90, +/-180]
Rotation expected: [0, -135, 0]. Returned rotation: [+/-180, -45, +/-180]
Rotation expected: [0, -180, 0]. Returned rotation: [+/-180, 0, +/-180]
Questions:
Why the absolute value of y-axis is never greater than 90 ?
Why the x/z values change to +/-180º when I reach some point (+/-90º in y-axis) if I'm just rotating the device over the y-axis.
Is this the expeted behavior ? If so, could anyone explain these values (please).
The code to retrieve the values:
<ViroARScene onTrackingUpdated={this._onInitialized} anchorDetectionTypes={"PlanesVertical"}>
...
</ViroARScene>
_onInitialized(state, reason) {
if (state === ViroConstants.TRACKING_NORMAL && reason === ViroConstants.TRACKING_REASON_NONE) {
console.log('Tracking initiated');
this._scene.getCameraOrientationAsync().then(
(orientation) => {
console.log('Cam rot:', round(orientation.rotation));
});
}
}
I've also created a GitHub issue with some mockups to show the rotation values expected and returned: https://github.com/ViroCommunity/viro/issues/13
I think what you're coming up against might be Gimbal lock, which is the reason that a lot of 3d rotators are expressed in Quaternions, instead of the xyz (aka Euler - pronounced "oiler") system you are using now. It's probably expected behaviour for your system.
I'm not familiar with your platform but it might have built-in helpers or alternative methods you can use in order to work with Quaternions instead, if not then a solution for you might be to install a library (or write some code) that translates between Euler angles and Quaternions so that your calculations make more sense, if you are going to be spending time around the y-0.

Define a matrix in VB2012 with Math.net Numeric Matrix

I am switching from MATLAB to VS2012. I want to use Math.net Numeric to solve my matrix based equations. I am having hard time to define a simple matrix in VS2012 in VB environment using Math.Net matrix. I have found many articles on F# and how to define a matrix, but no luck in VB. I tried Public MAT1 As Matrix(Of but I don't know how to finish the declaration. Does anyone know? Thank you.
The MathNet library has predefined Matrix classes for singles, doubles, and complex values.
For example, to instantiate a 3x3 matrix of doubles, use:
Dim m = MathNet.Numerics.LinearAlgebra.Double.Matrix.Build.DenseOfArray({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}})
Each operation on the matrix returns a transformed matrix:
Dim m2 = m.Multiply(1.5)

Graph a series of planes as a solid object in Mathematica

I'm trying to graph a series of planes as a solid object in mathematica. I first tried to use the RangePlot3D options as well as the fill options to graph the 3D volume, but was unable to find a working result.
The graphic I'm trying to create will show the deviation between the z axis and the radius from the origin of a 3D cuboid. The current equation I'm using is this:
Plot3D[Evaluate[{Sqrt[(C[1])^2 + x^2 + y^2]} /.
C[1] -> Range[6378100, 6379120]], {x, -1000000,
1000000}, {y, -1000000, 1000000}, AxesLabel -> Automatic]
(output for more manageable range looks as follows)
Where C1 was the origional Z-value at each plane and the result of this equation is z+(r-z)
for any point on the x,y plane.
However this method is incredibly inefficient. Because this will be used to model large objects with an original z-values of >6,000,000 and heights above 1000, mathematica is unable to graph thousands of planes and represent them in a responsive method.
Additionally, Because the Range of C1 only includes integer values, there is discontinuity between these planes.
Is there a way to rewrite this using different mathematica functionality that will generate a 3Dplot that is both a reasonable load on my system and is a smooth object?
2nd, What can I do to improve my perforamance? when computing the above input for >30min, mathematica was only utilizing about 30% CPU and 4GB of ram with a light load on my graphics card as well. This is only about twice as much as chrome is using right now on my system.
I attempted to enable CUDALink, but it wouldn't enable properly. Would this offer a performance boost for this type of processing?
For Reference, my system build is:
16GB Ram
Intel i7 4770K running at stock settings
Nvidia GeForce 760GTX
256 Samsung SSD
Plotting a million planes and hoping that becomes a 3d solid seems unlikely to succeed.
Perhaps you could adapt something like this
Show[Plot3D[{Sqrt[6^2+x^2+y^2], Sqrt[20^2+x^2+y^2]}, {x, -10, 10}, {y, -10, 10},
AxesLabel -> Automatic, PlotRange -> {{-15, 15}, {-15, 15}, All}],
Graphics3D[{
Polygon[Join[
Table[{x, -10, Sqrt[6^2 + x^2 + (-10)^2]}, {x, -10, 10, 1}],
Table[{x, -10, Sqrt[20^2 + x^2 + (-10)^2]}, {x, 10, -10, -1}]]],
Polygon[Join[
Table[{-10, y, Sqrt[6^2 + (-10)^2 + y^2]}, {y, -10, 10, 1}],
Table[{-10, y, Sqrt[20^2 + (-10)^2 + y^2]}, {y, 10, -10, -1}]]],
Polygon[Join[
Table[{x, 10, Sqrt[6^2 + x^2 + 10^2]}, {x, -10, 10, 1}],
Table[{x, 10, Sqrt[20^2 + x^2 + 10^2]}, {x, 10, -10, -1}]]],
Polygon[Join[
Table[{10, y, Sqrt[6^2 + 10^2 + y^2]}, {y, -10, 10, 1}],
Table[{10, y, Sqrt[20^2 + 10^2 + y^2]}, {y, 10, -10, -1}]]]}]]
What that does is plot the top and bottom surface and then construct four polygons, each connecting the top and bottom surface along one side. But one caution, if you look very very closely you will see that, because they are polygons, the edges of the four faces are made up of short line segments rather than parabolas and thus are not perfectly joining your two paraboloids, there can be tiny gaps or tiny overlaps. This may or may not make any difference for your application.
That graphic displays in a fraction of a second on a machine that is a fraction of yours.
Mathematica does not automatically parallelize computations onto multiple cores.
CUDA programming is a considerably bigger challenge than turning the link on.
If you can simply define each face of your solid and combine them with Show then
I think you will have a much greater chance of success.
Another way:
xyrange = 10
cmin = 6
cmax = 20
RegionPlot3D[
Abs[x] < xyrange && Abs[y] < xyrange &&
cmin^2 < z^2 - ( x^2 + y^2) < cmax^2 ,
{x, -1.2 xyrange, 1.2 xyrange}, {y, -1.2 xyrange, 1.2 xyrange},
{z, cmin, Sqrt[ cmax^2 + 2 xyrange^2]}, MaxRecursion -> 15,
PlotPoints -> 100]
This is nowhere near as fast as Bills' approach, but it may be useful if you plot a more complicated region. Note RegionPlot does not work for your original example because the volume is too small compared to the plot range.

Assign integer values to color in opengl es 2.0

i need to set color by byte type or integer, not float values.
How can i assign this type into gl_FragColor?
Dividing the value by 256 wont give me the wanted precision.
My main purpose is to know the specific value of each bit in the color buffer, if i draw line only with specific color.
for example i want that in the color buffer at the red value of pixel only 2 lsbits will be on, what color value should i transfer to gl_FragColor?
If i had an option to write byte type values, i would write the value 3 to red component
Thanks
As far as I know, gl_FragColor must always be floating point. However, if you know the colour buffer is 8 bits per channel it shouldn't be hard to force whatever you want into it. You might consider
gl_FragColor = vec4(floor(number)/255.0, 0, 0, 0);
for example. The more recent versions of GLSL support bitwise operations, but I doubt GLES2 does.
If you want to draw to specific bits, maybe...
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
...
gl_FragColor = vec4(pow(2.0, bitIndex)/255.0, 0, 0, 0);
I haven't tested this but see no reason why it couldn't work assuming geometry never overlaps (in which case the bit would overflow into the next).