Anonymous avatar Anonymous committed 6fa7987

add ftimes21: vectorizable multiplication sample

Comments (0)

Files changed (2)

accesscarray/accesscarraymodule.c

 }
 
 
+static PyObject *
+ftimes21(PyObject *dummy, PyObject *args)
+{
+  PyObject *o0, *o1, *o2;
+  double *d0, *d1, *d2;
+  int n0, n1, i, j;
+
+  if (PyArg_ParseTuple(args, "OO:ftimes21", &o0, &o1, &o2) < 0) {
+    PyErr_SetString( PyExc_TypeError, "bad arguments");
+    return NULL;
+  }
+  if (PyArray_NDIM(o0) != 2) {
+    PyErr_SetString( PyExc_ValueError, "bad ndim");
+    return NULL;
+  }
+  if (PyArray_NDIM(o1) != 1) {
+    PyErr_SetString( PyExc_ValueError, "bad ndim");
+    return NULL;
+  }
+  if (PyArray_NDIM(o2) != 1) {
+    PyErr_SetString( PyExc_ValueError, "bad ndim");
+    return NULL;
+  }
+  n0 = PyArray_DIM(o0, 0);
+  n1 = PyArray_DIM(o0, 1);
+  if (PyArray_DIM(o1, 0) != n1) {
+    PyErr_SetString( PyExc_ValueError, "bad shape");
+    return NULL;
+  }
+  if (PyArray_DIM(o2, 0) != n0) {
+    PyErr_SetString( PyExc_ValueError, "bad shape");
+    return NULL;
+  }
+  
+  d0 = (double *)PyArray_BYTES(o0);
+  d1 = (double *)PyArray_BYTES(o1);
+  d2 = (double *)PyArray_BYTES(o2);
+
+  for (i = 0; i < n0; ++i) {
+    d2[i] = 0;
+    for (j = 0; j < n1; ++j) {
+      d2[i] += d0[i*n1 + j] * d1[j];
+    }
+  }
+
+  return Py_BuildValue("");  /* return None */
+}
+
 
 static PyMethodDef module_methods[] = {
   {"print_a1", (PyCFunction)print_a1, METH_VARARGS, ""},
   {"print_a2", (PyCFunction)print_a2, METH_VARARGS, ""},
   {"check_pointer", (PyCFunction)check_pointer, METH_VARARGS, ""},
+  {"ftimes21", (PyCFunction)ftimes21, METH_VARARGS, ""},
   {NULL}  /* Sentinel */
 };
 

accesscarray/setup.py

 module1 = Extension(
     'accesscarray',
     sources = ['accesscarraymodule.c'],
-    extra_compile_args = ["-O3", "-fPIC", ],
+    extra_compile_args = ["-fPIC", "-O3", "-vec-report1", ],
 )
 
 setup( name = 'my',
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.