You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to use CNTK's reduce operations, but I am facing some issues when I try to reduce alongside a particular axis. I am writing below a test case with 4 assertions, 2 of them which pass and 2 which do not:
privatestaticdouble[][]sum(paramsint[]axes){vararr=new[]{/* total: /* */1.0,2.0,3.0,/* 6.0 *//* */4.0,5.0,6.0,/* 15.0 *//* total: 5.0, 7.0, 9.0 21.0 */};varshape=NDShape.CreateNDShape(new[]{2,3});Valuevx=Value.CreateBatch(shape,arr,DeviceDescriptor.CPUDevice,readOnly:true);Variablex=Variable.InputVariable(shape,CNTK.DataType.Double,name:"input");CNTK.Functionf;if(axes==null){f=CNTKLib.Alias(x);}else{varaxisVector=newAxisVector(axes.Select(ax =>newAxis(ax)).ToArray());f=CNTKLib.ReduceSum(x,axis:axisVector);}varinputs=newDictionary<Variable,Value>(){{x,vx}};varoutputs=newDictionary<Variable,Value>(){{f,null}};f.Evaluate(inputs,outputs,DeviceDescriptor.CPUDevice);varr=outputs[f].GetDenseData<double>((Variable)f);returnr.Select(ri =>ri.ToArray()).ToArray();}[Test]publicvoidcntk_sum_test_direct_api(){double[][]r;r=sum(null);// first, a sanity check to verify that values are being read correctlydouble[,]d=newdouble[2,3];// result will be { 0, 1, 2, 3, 4, 5, 6 }Buffer.BlockCopy(r[0],0,d,0,sizeof(double)*d.Length);Assert.AreEqual(new[,]{{1,2,3},{4,5,6}},d);// okr=sum(0,1);// sum over all axesdoublea=r[0][0];// result will be { 21 }Assert.AreEqual(21,a);// okr=sum(0);// sum over first axisdouble[]b=r[0];// result will be { 3, 7, 11 }Assert.AreEqual(new[]{5.0,7.0,9.0},b);// failsr=sum(1);// sum over second axisdouble[]c=r[0];// result will be { 9, 12 }Assert.AreEqual(new[]{6.0,15.0},b);// fails}
As you see, the sum method is just using CNTK to perform a ReduceSum operation over the axes it receives as a parameter, or defaults to a simple Alias operation when the vector of axes is null to just let the data pass through.
When the test function is called passing both axes to be summed, it returns the correct value. When it is called passing null, it correctly lets the data pass. However, when reducing in a particular direction, it returns wrong values albeit with correct shape.
Could someone please help shed a light on what is wrong in the above test?
Regards,
Cesar
The text was updated successfully, but these errors were encountered:
cesarsouza
added a commit
to cesarsouza/keras-sharp
that referenced
this issue
Nov 28, 2017
actually it works little other other way.
the array you providing is processed as follows
{1.0, 2.0, 3.0, 4.0, 5.0, 6.0}
processed
{
1.0 3.0 5.0
2.0 4.0 6.0
}
I've checked few other functions, same logic
CNTKLib.ReduceSum
CNTKLib.ReduceMax
CNTKLib.ReduceProd
Hello there,
I've been trying to use CNTK's reduce operations, but I am facing some issues when I try to reduce alongside a particular axis. I am writing below a test case with 4 assertions, 2 of them which pass and 2 which do not:
As you see, the
sum
method is just using CNTK to perform aReduceSum
operation over the axes it receives as a parameter, or defaults to a simpleAlias
operation when the vector of axes isnull
to just let the data pass through.When the test function is called passing both axes to be summed, it returns the correct value. When it is called passing null, it correctly lets the data pass. However, when reducing in a particular direction, it returns wrong values albeit with correct shape.
Could someone please help shed a light on what is wrong in the above test?
Regards,
Cesar
The text was updated successfully, but these errors were encountered: