aboutsummaryrefslogtreecommitdiff
path: root/redist
diff options
context:
space:
mode:
Diffstat (limited to 'redist')
-rw-r--r--redist/Makefile4
-rw-r--r--redist/minimal_opencv.c43
-rw-r--r--redist/minimal_opencvtest.c39
-rw-r--r--redist/os_generic.h16
4 files changed, 81 insertions, 21 deletions
diff --git a/redist/Makefile b/redist/Makefile
index 58536c9..5598c9b 100644
--- a/redist/Makefile
+++ b/redist/Makefile
@@ -6,11 +6,15 @@ jsmntest : jsmntest.c jsmn.c
lintest : lintest.c linmath.c linmath.h
gcc -g -O0 -o $@ $^ -lm
+minimal_opencvtest : minimal_opencvtest.c minimal_opencv.c minimal_opencv.h
+ gcc -g -O0 -o $@ $^ -lcblas -lm -llapacke
+
test_dcl : test_dcl.c dclhelpers.c minimal_opencv.c ../src/epnp/epnp.c
gcc -o $@ $^ os_generic.c -DFLT=double -lpthread -lcblas -lm -llapacke -O3 -msse2 -ftree-vectorize
.run_tests: clean all
./lintest
+ ./minimal_opencvtest
./test_dcl
./jsmntest
diff --git a/redist/minimal_opencv.c b/redist/minimal_opencv.c
index d569d96..c9cacf3 100644
--- a/redist/minimal_opencv.c
+++ b/redist/minimal_opencv.c
@@ -30,27 +30,39 @@ SURVIVE_LOCAL_ONLY void cvCopyTo(const CvMat *srcarr, CvMat *dstarr) {
SURVIVE_LOCAL_ONLY void cvGEMM(const CvMat *src1, const CvMat *src2, double alpha, const CvMat *src3, double beta,
CvMat *dst, int tABC) {
- lapack_int rows1 = src1->rows;
- lapack_int cols1 = src1->cols;
- lapack_int rows2 = src2->rows;
- lapack_int cols2 = src2->cols;
+ int rows1 = (tABC & GEMM_1_T) ? src1->cols : src1->rows;
+ int cols1 = (tABC & GEMM_1_T) ? src1->rows : src1->cols;
- lapack_int lda = cols1;
- lapack_int ldb = cols2;
+ int rows2 = (tABC & GEMM_2_T) ? src2->cols : src2->rows;
+ int cols2 = (tABC & GEMM_2_T) ? src2->rows : src2->cols;
- assert(src1->cols == src2->rows);
- assert(src1->rows == dst->rows);
- assert(src2->cols == dst->cols);
+ assert(cols1 == rows2);
+ assert(rows1 == dst->rows);
+ assert(cols2 == dst->cols);
+ lapack_int lda = src1->cols;
+ lapack_int ldb = src2->cols;
+
if (src3)
cvCopyTo(src3, dst);
else
beta = 0;
- cblas_dgemm(CblasRowMajor, (tABC & GEMM_1_T) ? CblasTrans : CblasNoTrans,
- (tABC & GEMM_2_T) ? CblasTrans : CblasNoTrans, src1->rows, dst->cols, src1->cols, alpha, src1->data.db,
- lda, src2->data.db, ldb, beta, dst->data.db, dst->cols);
+ cblas_dgemm(CblasRowMajor,
+ (tABC & GEMM_1_T) ? CblasTrans : CblasNoTrans,
+ (tABC & GEMM_2_T) ? CblasTrans : CblasNoTrans,
+ dst->rows,
+ dst->cols,
+ cols1,
+ alpha,
+ src1->data.db,
+ lda,
+ src2->data.db,
+ ldb,
+ beta,
+ dst->data.db,
+ dst->cols);
}
SURVIVE_LOCAL_ONLY void cvMulTransposed(const CvMat *src, CvMat *dst, int order, const CvMat *delta, double scale) {
@@ -296,10 +308,11 @@ SURVIVE_LOCAL_ONLY void cvTranspose(const CvMat *M, CvMat *dst) {
if (inPlace) {
tmp = cvCloneMat(dst);
src = tmp->data.db;
+ } else {
+ assert(M->rows == dst->cols);
+ assert(M->cols == dst->rows);
}
- assert(M->rows == dst->cols);
- assert(M->cols == dst->rows);
for (unsigned i = 0; i < M->rows; i++) {
for (unsigned j = 0; j < M->cols; j++) {
dst->data.db[j * M->rows + i] = src[i * M->cols + j];
@@ -329,7 +342,7 @@ SURVIVE_LOCAL_ONLY void cvSVD(CvMat *aarr, CvMat *warr, CvMat *uarr, CvMat *varr
lapack_int arows = aarr->rows, acols = aarr->cols;
lapack_int ulda = uarr ? uarr->cols : 1;
lapack_int plda = varr ? varr->cols : acols;
-
+
double *superb = malloc(sizeof(double) * MIN(arows, acols));
inf = LAPACKE_dgesvd(LAPACK_ROW_MAJOR, jobu, jobvt, arows, acols, aarr->data.db, acols, warr ? warr->data.db : 0,
uarr ? uarr->data.db : 0, ulda, varr ? varr->data.db : 0, plda, superb);
diff --git a/redist/minimal_opencvtest.c b/redist/minimal_opencvtest.c
new file mode 100644
index 0000000..6320a27
--- /dev/null
+++ b/redist/minimal_opencvtest.c
@@ -0,0 +1,39 @@
+#include "minimal_opencv.h"
+#include <assert.h>
+#include <math.h>
+#include <stdbool.h>
+#include <stdio.h>
+
+void print_mat(const CvMat *M) {}
+
+void test_gemm() {
+ double _2x3[2*3] = {1, 2, 3, 4, 5, 6};
+ CvMat m2x3 = cvMat(2, 3, CV_64F, _2x3);
+
+ double _3x2[2*3] = {1, 2, 3, 4, 5, 6};
+ CvMat m3x2 = cvMat(3, 2, CV_64F, _3x2);
+
+ double _2x2[2*2] = {1, 2, 3, 4};
+ CvMat m2x2 = cvMat(2, 2, CV_64F, _2x2);
+
+ double _3x3[3*3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+ CvMat m3x3 = cvMat(3, 3, CV_64F, _3x3);
+
+ cvGEMM(&m2x3, &m3x2, 1, 0, 0, &m2x2, 0);
+ cvGEMM(&m3x2, &m2x3, 1, 0, 0, &m3x3, 0);
+
+ cvGEMM(&m2x3, &m2x3, 1, 0, 0, &m3x3, GEMM_1_T);
+ cvGEMM(&m2x3, &m2x3, 1, 0, 0, &m2x2, GEMM_2_T);
+
+ cvGEMM(&m2x3, &m3x2, 1, 0, 0, &m3x3, GEMM_1_T | GEMM_2_T);
+ // cvGEMM(&m3x2, &m2x3, 1, 0, 0, &m2x2, GEMM_1_T | GEMM_2_T);
+
+}
+
+int main()
+{
+ test_gemm();
+
+ return 0;
+}
+
diff --git a/redist/os_generic.h b/redist/os_generic.h
index 0d1c7e7..c0cb4f8 100644
--- a/redist/os_generic.h
+++ b/redist/os_generic.h
@@ -205,7 +205,7 @@ OSG_INLINE double OGGetFileTime(const char *file) {
}
OSG_INLINE og_thread_t OGCreateThread(void *(routine)(void *), void *parameter) {
- pthread_t *ret = malloc(sizeof(pthread_t));
+ pthread_t *ret = (pthread_t *)malloc(sizeof(pthread_t));
int r = pthread_create(ret, 0, routine, parameter);
if (r) {
free(ret);
@@ -268,26 +268,30 @@ OSG_INLINE void OGDeleteMutex(og_mutex_t om) {
}
OSG_INLINE og_sema_t OGCreateSema() {
- sem_t *sem = malloc(sizeof(sem_t));
+ sem_t *sem = (sem_t *)malloc(sizeof(sem_t));
sem_init(sem, 0, 0);
return (og_sema_t)sem;
}
OSG_INLINE int OGGetSema(og_sema_t os) {
int valp;
- sem_getvalue(os, &valp);
+ sem_getvalue((sem_t *)os, &valp);
return valp;
}
-OSG_INLINE void OGLockSema(og_sema_t os) { sem_wait(os); }
+OSG_INLINE void OGLockSema(og_sema_t os) { sem_wait((sem_t *)os); }
-OSG_INLINE void OGUnlockSema(og_sema_t os) { sem_post(os); }
+OSG_INLINE void OGUnlockSema(og_sema_t os) { sem_post((sem_t *)os); }
OSG_INLINE void OGDeleteSema(og_sema_t os) {
- sem_destroy(os);
+ sem_destroy((sem_t *)os);
free(os);
}
#endif
#endif
+
+#ifdef __cplusplus
+}
+#endif