aboutsummaryrefslogtreecommitdiff
path: root/modules/matrix_basic/pdp_mat_lu.c
blob: af8931d95f3c72012b7f3064e1b967459b69ca59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 *   Pure Data Packet module. LU decomposition module.
 *   Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

//#include <gsl/gsl_block.h>
//#include <gsl/gsl_vector.h>
//#include <gsl/gsl_matrix.h>
//#include <gsl/gsl_blas.h>
#include "pdp.h"
#include "pdp_base.h"


typedef struct pdp_mat_LU_struct
{
    t_pdp_base x_base;

} t_pdp_mat_LU;



static void pdp_mat_LU_process_LU_inverse(t_pdp_mat_LU *x)
{
    int p = pdp_base_get_packet(x, 0);
    int p_LU = pdp_packet_matrix_LU_to_inverse(p);
    pdp_base_set_packet(x, 0, p_LU); // replace packet
}

static void pdp_mat_LU_process_LU(t_pdp_mat_LU *x)
{
    int p = pdp_base_get_packet(x, 0);
    int p_LU = pdp_packet_matrix_LU(p);
    pdp_base_set_packet(x, 0, p_LU); // replace packet
}

static void pdp_mat_LU_process_LU_solve(t_pdp_mat_LU *x)
{
    int p0 = pdp_base_get_packet(x, 0);
    int p1 = pdp_base_get_packet(x, 1);
    int pvr, pm, pv;

    /* determine which is vector and which is matrix */
    if (pdp_packet_matrix_ismatrix(p0) && pdp_packet_matrix_isvector(p1)){
	pm = p0;
	pv = p1;
    }
    else {
	pm = p1;
	pv = p0;
    }

    /* create the result vector */
    pvr = pdp_packet_matrix_LU_solve(pm, pv);

    /* replace the active packet */
    pdp_base_set_packet(x, 0, pvr);
}

static void pdp_mat_LU_free(t_pdp_mat_LU *x)
{
    /* remove process method from queue before deleting data */
    pdp_base_free(x);
}

t_class *pdp_mat_LU_class;


/* common new methods */
t_pdp_mat_LU *pdp_mat_LU_base_new(void)
{
    t_pdp_mat_LU *x = (t_pdp_mat_LU *)pd_new(pdp_mat_LU_class);
    pdp_base_init(x);
    pdp_base_add_pdp_outlet(x);
    return x;
}

void *pdp_mat_LU_inverse_new(void)
{
    t_pdp_mat_LU *x = pdp_mat_LU_base_new();
    pdp_base_set_process_method(x,(t_pdp_method)pdp_mat_LU_process_LU_inverse);
    pdp_base_readonly_active_inlet(x);
    return (void *)x;
}


void *pdp_mat_LU_new(void)
{
    t_pdp_mat_LU *x = pdp_mat_LU_base_new();
    pdp_base_set_process_method(x,(t_pdp_method)pdp_mat_LU_process_LU);
    pdp_base_readonly_active_inlet(x);
    return (void *)x;
}

void *pdp_mat_LU_solve_new(void)
{
    t_pdp_mat_LU *x = pdp_mat_LU_base_new();
    pdp_base_set_process_method(x,(t_pdp_method)pdp_mat_LU_process_LU_solve);
    pdp_base_readonly_active_inlet(x);
    pdp_base_add_pdp_inlet(x);
    return (void *)x;
}

#ifdef __cplusplus
extern "C"
{
#endif


void pdp_mat_lu_setup(void)
{


    pdp_mat_LU_class = class_new(gensym("pdp_m_LU_inverse"), (t_newmethod)pdp_mat_LU_inverse_new,
    	(t_method)pdp_mat_LU_free, sizeof(t_pdp_mat_LU), 0, A_NULL);

    pdp_base_setup(pdp_mat_LU_class);


    class_addcreator((t_newmethod)pdp_mat_LU_new, gensym("pdp_m_LU"), A_NULL);
    class_addcreator((t_newmethod)pdp_mat_LU_solve_new, gensym("pdp_m_LU_solve"), A_NULL);

 

}

#ifdef __cplusplus
}
#endif