File: sfmult_anxtyn.c

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (171 lines) | stat: -rw-r--r-- 4,782 bytes parent folder | download | duplicates (2)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//==============================================================================
//=== sfmult_AN_XT_YN ==========================================================
//==============================================================================

// SFMULT, Copyright (c) 2009, Timothy A Davis. All Rights Reserved.
// SPDX-License-Identifier: BSD-3-clause

// y = A*x'	    A is m-by-n, x is k-by-n, y is m-by-k

// compare with sfmult_AN_XT_YT for kernel usage
// compare with sfmult_AN_XN_YN for outer loop structure but different kernels

#include "sfmult.h"

mxArray *sfmult_AN_XT_YN    // y = A*x'
(
    const mxArray *A,
    const mxArray *X,
    int ac,		// if true: conj(A)   if false: A. ignored if A real
    int xc,		// if true: conj(x)   if false: x. ignored if x real
    int yc		// if true: conj(y)   if false: y. ignored if y real
)
{
    mxArray *Y ;
    double *Ax, *Az, *Xx, *Xz, *Yx, *Yz, *Wx, *Wz ;
    Int *Ap, *Ai ;
    Int m, n, k, k1, i ;
    int Acomplex, Xcomplex, Ycomplex ;

    //--------------------------------------------------------------------------
    // get inputs
    //--------------------------------------------------------------------------

    m = mxGetM (A) ;
    n = mxGetN (A) ;
    k = mxGetM (X) ;
    if (n != mxGetN (X)) sfmult_invalid ( ) ;
    Acomplex = mxIsComplex (A) ;
    Xcomplex = mxIsComplex (X) ;
    Ap = mxGetJc (A) ;
    Ai = mxGetIr (A) ;
    Ax = mxGetPr (A) ;
    Az = mxGetPi (A) ;
    Xx = mxGetPr (X) ;
    Xz = mxGetPi (X) ;

    //--------------------------------------------------------------------------
    // allocate result
    //--------------------------------------------------------------------------

    Ycomplex = Acomplex || Xcomplex ;
    Y = sfmult_yalloc (m, k, Ycomplex) ;
    Yx = mxGetPr (Y) ;
    Yz = mxGetPi (Y) ;

    //--------------------------------------------------------------------------
    // special cases
    //--------------------------------------------------------------------------

    if (k == 0 || m == 0 || n == 0 || Ap [n] == 0)
    {
	// Y = 0
	return (sfmult_yzero (Y)) ;
    }
    if (k == 1)
    {
	// Y = A*X
	sfmult_AN_x_1 (Yx, Yz, Ap, Ai, Ax, Az, m, n, Xx, Xz, ac, xc, yc) ;
	return (Y) ;
    }

    //--------------------------------------------------------------------------
    // allocate workspace
    //--------------------------------------------------------------------------

    sfmult_walloc ((k == 2) ? 2 : 4, m, &Wx, &Wz) ;

    //--------------------------------------------------------------------------
    // Y = A*X', in blocks of up to 4 columns of X, using sfmult_anxtyt
    //--------------------------------------------------------------------------

    k1 = k % 4 ;
    if (k1 == 1)
    {
	// Y (:,1) = A * X(1,:)'
	sfmult_AN_xk_1 (Yx, Yz, Ap, Ai, Ax, Az, m, n, Xx, Xz, ac, xc, yc, k) ;
	Yx += m ;
	Yz += m ;
	Xx += 1 ;
	Xz += 1 ;
    }
    else if (k1 == 2)
    {
	// W = (A * X(1:2,:)')'
	sfmult_AN_XT_YT_2 (Wx, Wz, Ap, Ai, Ax, Az, m, n, Xx, Xz, ac, xc, yc, k);
	// Y (:,1:2) = W'

	for (i = 0 ; i < m ; i++) Yx [i] = Wx [2*i  ] ; Yx += m ; Yz += m ;
	for (i = 0 ; i < m ; i++) Yx [i] = Wx [2*i+1] ; Yx += m ; Yz += m ;

	#if 0
	for (i = 0 ; i < m ; i++)
	{
	    Yx [i  ] = Wx [2*i  ] ;
	    Yx [i+m] = Wx [2*i+1] ;
	}
	Yx += 2*m ;
	Yz += 2*m ;
	#endif

	Xx += 2 ;
	Xz += 2 ;
    }
    else if (k1 == 3)
    {
	// W = (A * X(1:3,:)')'
	sfmult_AN_XT_YT_3 (Wx, Wz, Ap, Ai, Ax, Az, m, n, Xx, Xz, ac, xc, yc, k);
	// Y (:,1:3) = W'

	for (i = 0 ; i < m ; i++) Yx [i] = Wx [4*i  ] ; Yx += m ; Yz += m ;
	for (i = 0 ; i < m ; i++) Yx [i] = Wx [4*i+1] ; Yx += m ; Yz += m ;
	for (i = 0 ; i < m ; i++) Yx [i] = Wx [4*i+2] ; Yx += m ; Yz += m ;

	#if 0
	for (i = 0 ; i < m ; i++)
	{
	    Yx [i    ] = Wx [4*i  ] ;
	    Yx [i+  m] = Wx [4*i+1] ;
	    Yx [i+2*m] = Wx [4*i+2] ;
	}
	Yx += 3*m ;
	Yz += 3*m ;
	#endif

	Xx += 3 ;
	Xz += 3 ;
    }
    for ( ; k1 < k ; k1 += 4)
    {
	// W = (A * X(1:4,:)')'
	sfmult_AN_XT_YT_4 (Wx, Wz, Ap, Ai, Ax, Az, m, n, Xx, Xz, ac, xc, yc, k);
	// Y (:,k1+(1:4)) = W'

	for (i = 0 ; i < m ; i++) Yx [i] = Wx [4*i  ] ; Yx += m ; Yz += m ;
	for (i = 0 ; i < m ; i++) Yx [i] = Wx [4*i+1] ; Yx += m ; Yz += m ;
	for (i = 0 ; i < m ; i++) Yx [i] = Wx [4*i+2] ; Yx += m ; Yz += m ;
	for (i = 0 ; i < m ; i++) Yx [i] = Wx [4*i+3] ; Yx += m ; Yz += m ;

#if 0
	for (i = 0 ; i < m ; i++)
	{
	    Yx [i    ] = Wx [4*i  ] ;
	    Yx [i+  m] = Wx [4*i+1] ;
	    Yx [i+2*m] = Wx [4*i+2] ;
	    Yx [i+3*m] = Wx [4*i+3] ;
	}
	Yx += 4*m ;
	Yz += 4*m ;
#endif

	Xx += 4 ;
	Xz += 4 ;
    }

    //--------------------------------------------------------------------------
    // free workspace and return result
    //--------------------------------------------------------------------------

    mxFree (Wx) ;
    return (Y) ;
}