summaryrefslogtreecommitdiffstats
path: root/firmware/os/algos/common/math/mat.h
diff options
context:
space:
mode:
authorMeng-hsuan Chung <menghsuan@google.com>2016-10-17 10:26:23 -0700
committerMeng-hsuan Chung <menghsuan@google.com>2016-10-17 10:33:56 -0700
commit4a1df3e8bc58f0b3fbb449d6aac178eeacc833da (patch)
tree8a03d2429be39cd7b9d2709a145edb88cce6b7b2 /firmware/os/algos/common/math/mat.h
parent3325ea79d2b6b9547e9cef600c824b2ebe6e33f8 (diff)
downloaddevice_google_contexthub-4a1df3e8bc58f0b3fbb449d6aac178eeacc833da.tar.gz
device_google_contexthub-4a1df3e8bc58f0b3fbb449d6aac178eeacc833da.tar.bz2
device_google_contexthub-4a1df3e8bc58f0b3fbb449d6aac178eeacc833da.zip
[calibration] sync from google3
SyncChange: 136362540 Test: syncing files from googl3, not used yet. bug: 32168214 Change-Id: I6fbdf58f3cfc6425dd5ccb65f03d043e338c06a9
Diffstat (limited to 'firmware/os/algos/common/math/mat.h')
-rw-r--r--firmware/os/algos/common/math/mat.h102
1 files changed, 102 insertions, 0 deletions
diff --git a/firmware/os/algos/common/math/mat.h b/firmware/os/algos/common/math/mat.h
new file mode 100644
index 00000000..f8aad436
--- /dev/null
+++ b/firmware/os/algos/common/math/mat.h
@@ -0,0 +1,102 @@
+#ifndef LOCATION_LBS_CONTEXTHUB_NANOAPPS_COMMON_MATH_MAT_H_
+#define LOCATION_LBS_CONTEXTHUB_NANOAPPS_COMMON_MATH_MAT_H_
+
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdint.h>
+#include <sys/types.h>
+#include "common/math/vec.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct Mat33 {
+ float elem[3][3];
+};
+
+struct Size3 {
+ uint32_t elem[3];
+};
+
+struct Mat44 {
+ float elem[4][4];
+};
+
+struct Size4 {
+ uint32_t elem[4];
+};
+
+void initZeroMatrix(struct Mat33 *A);
+void initDiagonalMatrix(struct Mat33 *A, float x);
+
+void initMatrixColumns(struct Mat33 *A, const struct Vec3 *v1,
+ const struct Vec3 *v2, const struct Vec3 *v3);
+
+void mat33Apply(struct Vec3 *out, const struct Mat33 *A, const struct Vec3 *v);
+void mat33Multiply(struct Mat33 *out, const struct Mat33 *A,
+ const struct Mat33 *B);
+void mat33ScalarMul(struct Mat33 *A, float c);
+
+void mat33Add(struct Mat33 *out, const struct Mat33 *A);
+void mat33Sub(struct Mat33 *out, const struct Mat33 *A);
+
+int mat33IsPositiveSemidefinite(const struct Mat33 *A, float tolerance);
+
+// out = A^(-1)
+void mat33Invert(struct Mat33 *out, const struct Mat33 *A);
+
+// out = A^T B
+void mat33MultiplyTransposed(struct Mat33 *out, const struct Mat33 *A,
+ const struct Mat33 *B);
+
+// out = A B^T
+void mat33MultiplyTransposed2(struct Mat33 *out, const struct Mat33 *A,
+ const struct Mat33 *B);
+
+// out = A^T
+void mat33Transpose(struct Mat33 *out, const struct Mat33 *A);
+
+void mat33DecomposeLup(struct Mat33 *LU, struct Size3 *pivot);
+
+void mat33SwapRows(struct Mat33 *A, const uint32_t i, const uint32_t j);
+
+void mat33Solve(const struct Mat33 *A, struct Vec3 *x, const struct Vec3 *b,
+ const struct Size3 *pivot);
+
+void mat33GetEigenbasis(struct Mat33 *S, struct Vec3 *eigenvals,
+ struct Mat33 *eigenvecs);
+
+uint32_t mat33Maxind(const struct Mat33 *A, uint32_t k);
+
+void mat33Rotate(struct Mat33 *A, float c, float s, uint32_t k, uint32_t l,
+ uint32_t i, uint32_t j);
+
+void mat44Apply(struct Vec4 *out, const struct Mat44 *A, const struct Vec4 *v);
+
+void mat44DecomposeLup(struct Mat44 *LU, struct Size4 *pivot);
+
+void mat44SwapRows(struct Mat44 *A, const uint32_t i, const uint32_t j);
+
+void mat44Solve(const struct Mat44 *A, struct Vec4 *x, const struct Vec4 *b,
+ const struct Size4 *pivot);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // LOCATION_LBS_CONTEXTHUB_NANOAPPS_COMMON_MATH_MAT_H_