Sam Preston avatar Sam Preston committed dd1a831

added a Sum function to reduction that takes a Field3D and produces a Vec3Df of component-wise sums. Added this to python interface as SumComp to avoid name conflict with old Sum. Other component-wise reduction functions on Field3Ds should be added, but this can be used as a template.

Comments (0)

Files changed (5)

Code/Cxx/inc/math/ReduceOb.h

 
 class Image3D;
 class Field3D;
-template<typename T>
-class Vec2D;
+template<typename T> class Vec2D;
+template<typename T> class Vec3D;
 
 template<int mode>
 class ReduceOb {
 		   bool update,StreamT stream,bool onDev);
    static void Sum(float& FLOAT_OUT,const Field3D& a_i,
 		   bool update,StreamT stream,bool onDev);
+   static void Sum(Vec3D<float>& a_o,const Field3D& a_i, 
+                   StreamT stream);
    static void LInf(float& FLOAT_OUT,const Field3D& a_i,
 		    bool update,StreamT stream,bool onDev);
    static void L1(float& FLOAT_OUT,const Field3D& a_i,

Code/Cxx/inc/math/Reduction.h

 
 class Image3D;
 class Field3D;
-template<typename T>
-class Vec2D;
+template<typename T> class Vec2D;
+template<typename T> class Vec3D;
 
 namespace Opers {
 
 	 bool update=false,StreamT stream=NULL,bool onDev=false);
 void Sum(float& FLOAT_OUT,const Field3D& a_i,
 	 bool update=false,StreamT stream=NULL,bool onDev=false);
+void Sum(Vec3D<float>& a_o,const Field3D& a_i, 
+	 StreamT stream=NULL);
 void LInf(float& FLOAT_OUT,const Field3D& a_i,
 	  bool update=false,StreamT stream=NULL,bool onDev=false);
 void L1(float& FLOAT_OUT,const Field3D& a_i,

Code/Cxx/src/math/ReduceOb.cxx

 
 template<int mode>
 void ReduceOb<mode>::
+Sum(Vec3D<float>& a_o,const Field3D& a_i, StreamT stream)
+{
+   size_t n = a_i.nVox();
+   Reduce<mode>::Sum(a_o.x, a_i.x, n, false, stream);
+   Reduce<mode>::Sum(a_o.y, a_i.y, n, false, stream);
+   Reduce<mode>::Sum(a_o.z, a_i.z, n, false, stream);
+}
+
+template<int mode>
+void ReduceOb<mode>::
 LInf(float& a_o,const Field3D& a_i, 
      bool update, StreamT stream,bool onDev)
 {

Code/Cxx/src/math/Reduction.cxx

    AUTO_EXEC_ONDEV(a_i.memType(), ReduceOb, Sum(a_o, a_i, update, stream, onDev));
 }
 
+void Sum(Vec3D<float>& a_o,const Field3D& a_i, StreamT stream)
+{
+   AUTO_EXEC(a_i.memType(), ReduceOb, Sum(a_o, a_i, stream));
+}
+
 void LInf(float& a_o,const Field3D& a_i, bool update,StreamT stream,bool onDev)
 {
    AUTO_EXEC_ONDEV(a_i.memType(), ReduceOb, LInf(a_o, a_i, update, stream, onDev));
 #include "VFOpers.h"
 #include "Reduction.h"
 #include "Vec2D.h"
+#include "Vec3D.h"
 %}
 
 // include generated docstrings
 
 %include "Reduction.h"
 
- // fix maxmin function to return multiple values
-%apply float *OUTPUT{ float *MIN_OUT, float *MAX_OUT };
+ // fix maxmin/sum functions to return multiple values
+%apply float *OUTPUT{ float *MIN_OUT, float *MAX_OUT};
 
 //
 // Add MinMax function for mapped for python
 }   
 %}
 
+// add version of Sum for Field3Ds that returns a Vec3Df
+
+namespace PyCA {
+namespace Opers{
+
+    Vec3D<float> SumComp(const Field3D& a_i, StreamT stream=NULL);
+}
+}
+
+%{
+namespace PyCA {
+namespace Opers{
+
+    Vec3D<float> SumComp(const Field3D& a_i, StreamT stream=NULL)
+   {
+      Vec3D<float> sum;
+      Sum(sum, a_i, stream);
+      return sum;
+   }
+
+}
+}   
+%}
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.