aboutsummaryrefslogtreecommitdiff
path: root/vendor/libftm/src/mat
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-05-11 13:29:51 +0200
committerCharles <sircharlesaze@gmail.com>2020-05-11 13:29:51 +0200
commitd07d87964f13d3c1e6ad8c2f6d7db21101f1ef34 (patch)
tree52dd2e82580eb3c70201991b53a2a2b4c434908b /vendor/libftm/src/mat
parent0700a8f567ab733a57fe688e45e5092d3fa1c1a0 (diff)
downloadscop-d07d87964f13d3c1e6ad8c2f6d7db21101f1ef34.tar.gz
scop-d07d87964f13d3c1e6ad8c2f6d7db21101f1ef34.tar.bz2
scop-d07d87964f13d3c1e6ad8c2f6d7db21101f1ef34.zip
libftm matrix, dynamic vector instead of fixed size
Diffstat (limited to 'vendor/libftm/src/mat')
-rw-r--r--vendor/libftm/src/mat/ftm_matadd.c30
-rw-r--r--vendor/libftm/src/mat/ftm_matat.c18
-rw-r--r--vendor/libftm/src/mat/ftm_matdestroy.c19
-rw-r--r--vendor/libftm/src/mat/ftm_matmul.c19
-rw-r--r--vendor/libftm/src/mat/ftm_matmulvec.c37
-rw-r--r--vendor/libftm/src/mat/ftm_matnew.c29
-rw-r--r--vendor/libftm/src/mat/ftm_matscale.c28
-rw-r--r--vendor/libftm/src/mat/ftm_matsub.c30
8 files changed, 210 insertions, 0 deletions
diff --git a/vendor/libftm/src/mat/ftm_matadd.c b/vendor/libftm/src/mat/ftm_matadd.c
new file mode 100644
index 0000000..97352a3
--- /dev/null
+++ b/vendor/libftm/src/mat/ftm_matadd.c
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_matadd.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:56:00 by charles #+# #+# */
+/* Updated: 2020/05/11 13:06:50 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat.h"
+
+t_ftmmat *ftm_matadd(t_ftmmat *dst, t_ftmmat *other)
+{
+ size_t i;
+ size_t size;
+
+ if (dst->shape.x != other->shape.x || dst->shape.y != other->shape.y)
+ return (NULL);
+ size = dst->shape.x * dst->shape.y;
+ i = 0;
+ while (i < size)
+ {
+ dst->m[i] += other->m[i];
+ i++;
+ }
+ return (dst);
+}
diff --git a/vendor/libftm/src/mat/ftm_matat.c b/vendor/libftm/src/mat/ftm_matat.c
new file mode 100644
index 0000000..0c77ced
--- /dev/null
+++ b/vendor/libftm/src/mat/ftm_matat.c
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_matat.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 13:11:34 by charles #+# #+# */
+/* Updated: 2020/05/11 13:27:17 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat.h"
+
+float ftm_matat(t_ftmmat *mat, size_t y, size_t x)
+{
+ return (mat->m[y * mat->shape.x + x]);
+}
diff --git a/vendor/libftm/src/mat/ftm_matdestroy.c b/vendor/libftm/src/mat/ftm_matdestroy.c
new file mode 100644
index 0000000..4d39270
--- /dev/null
+++ b/vendor/libftm/src/mat/ftm_matdestroy.c
@@ -0,0 +1,19 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_matdestroy.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:56:00 by charles #+# #+# */
+/* Updated: 2020/05/11 12:59:41 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat.h"
+
+void ftm_matdestroy(t_ftmmat *mat)
+{
+ free(mat->m);
+ free(mat);
+}
diff --git a/vendor/libftm/src/mat/ftm_matmul.c b/vendor/libftm/src/mat/ftm_matmul.c
new file mode 100644
index 0000000..0d26a20
--- /dev/null
+++ b/vendor/libftm/src/mat/ftm_matmul.c
@@ -0,0 +1,19 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_matmul.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:56:00 by charles #+# #+# */
+/* Updated: 2020/05/11 13:27:08 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat.h"
+
+t_ftmmat *ftm_matmul(t_ftmmat *dst, t_ftmmat *other)
+{
+ (void)other;
+ return (dst);
+}
diff --git a/vendor/libftm/src/mat/ftm_matmulvec.c b/vendor/libftm/src/mat/ftm_matmulvec.c
new file mode 100644
index 0000000..48af456
--- /dev/null
+++ b/vendor/libftm/src/mat/ftm_matmulvec.c
@@ -0,0 +1,37 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_matmulvec.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:56:00 by charles #+# #+# */
+/* Updated: 2020/05/11 13:18:10 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat.h"
+
+t_ftmvec *ftm_matmulvec(t_ftmmat *mat, t_ftmvec *dst)
+{
+ size_t i;
+ t_ftmmat *tmp;
+
+ if ((tmp = ftm_matnew(dst->size, 1)) == NULL)
+ return (NULL);
+ i = 0;
+ while (i < dst->size)
+ {
+ tmp->m[i] = dst->v[i];
+ i++;
+ }
+ if (ftm_matmul(tmp, mat) == NULL)
+ return (NULL);
+ i = 0;
+ while (i < dst->size)
+ {
+ dst->v[i] = tmp->m[i];
+ i++;
+ }
+ return (dst);
+}
diff --git a/vendor/libftm/src/mat/ftm_matnew.c b/vendor/libftm/src/mat/ftm_matnew.c
new file mode 100644
index 0000000..c7ddb36
--- /dev/null
+++ b/vendor/libftm/src/mat/ftm_matnew.c
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_matnew.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:56:00 by charles #+# #+# */
+/* Updated: 2020/05/11 13:13:27 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat.h"
+
+t_ftmmat *ftm_matnew(size_t y, size_t x)
+{
+ t_ftmmat *mat;
+
+ if ((mat = malloc(sizeof(t_ftmmat))) == NULL)
+ return (NULL);
+ if ((mat->m = malloc(sizeof(float) * x * y)) == NULL)
+ {
+ free(mat);
+ return (NULL);
+ }
+ mat->shape.y = y;
+ mat->shape.x = x;
+ return (mat);
+}
diff --git a/vendor/libftm/src/mat/ftm_matscale.c b/vendor/libftm/src/mat/ftm_matscale.c
new file mode 100644
index 0000000..8347e1a
--- /dev/null
+++ b/vendor/libftm/src/mat/ftm_matscale.c
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_matscale.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:56:00 by charles #+# #+# */
+/* Updated: 2020/05/11 13:07:25 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat.h"
+
+t_ftmmat *ftm_matscale(t_ftmmat *dst, float scalar)
+{
+ size_t i;
+ size_t size;
+
+ size = dst->shape.x * dst->shape.y;
+ i = 0;
+ while (i < size)
+ {
+ dst->m[i] *= scalar;
+ i++;
+ }
+ return (dst);
+}
diff --git a/vendor/libftm/src/mat/ftm_matsub.c b/vendor/libftm/src/mat/ftm_matsub.c
new file mode 100644
index 0000000..54ad900
--- /dev/null
+++ b/vendor/libftm/src/mat/ftm_matsub.c
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ftm_matsub.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/11 12:56:00 by charles #+# #+# */
+/* Updated: 2020/05/11 13:06:43 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libftm_mat.h"
+
+t_ftmmat *ftm_matsub(t_ftmmat *dst, t_ftmmat *other)
+{
+ size_t i;
+ size_t size;
+
+ if (dst->shape.x != other->shape.x || dst->shape.y != other->shape.y)
+ return (NULL);
+ size = dst->shape.x * dst->shape.y;
+ i = 0;
+ while (i < size)
+ {
+ dst->m[i] -= other->m[i];
+ i++;
+ }
+ return (dst);
+}