1
- function Base. copy (D:: Adjoint{T,<:DArray{T,2}} ) where T
1
+ function Base. copy (Dadj:: Adjoint{T,<:DArray{T,2}} ) where T
2
+ D = parent (Dadj)
2
3
DArray (reverse (size (D)), procs (D)) do I
3
4
lp = Array {T} (undef, map (length, I))
4
5
rp = convert (Array, D[reverse (I)... ])
5
6
adjoint! (lp, rp)
6
7
end
7
8
end
8
9
9
- function Base. copy (D:: Transpose{T,<:DArray{T,2}} ) where T
10
+ function Base. copy (Dtr:: Transpose{T,<:DArray{T,2}} ) where T
11
+ D = parent (Dtr)
10
12
DArray (reverse (size (D)), procs (D)) do I
11
13
lp = Array {T} (undef, map (length, I))
12
14
rp = convert (Array, D[reverse (I)... ])
@@ -49,7 +51,7 @@ function dot(x::DVector, y::DVector)
49
51
return reduce (+ , results)
50
52
end
51
53
52
- function norm (x:: DVector , p:: Real = 2 )
54
+ function norm (x:: DArray , p:: Real = 2 )
53
55
results = []
54
56
@sync begin
55
57
for pp in procs (x)
@@ -83,7 +85,7 @@ function add!(dest, src, scale = one(dest[1]))
83
85
return dest
84
86
end
85
87
86
- function A_mul_B! (α :: Number , A:: DMatrix , x:: AbstractVector , β :: Number , y :: DVector )
88
+ function mul! (y :: DVector , A:: DMatrix , x:: AbstractVector , α :: Number = 1 , β :: Number = 0 )
87
89
88
90
# error checks
89
91
if size (A, 2 ) != length (x)
@@ -106,11 +108,14 @@ function A_mul_B!(α::Number, A::DMatrix, x::AbstractVector, β::Number, y::DVec
106
108
107
109
# Scale y if necessary
108
110
if β != one (β)
109
- @sync for p in y. pids
110
- if β != zero (β)
111
- @async remotecall_fetch (y -> (rmul! (localpart (y), β); nothing ), p, y)
112
- else
113
- @async remotecall_fetch (y -> (fill! (localpart (y), 0 ); nothing ), p, y)
111
+ asyncmap (procs (y)) do p
112
+ remotecall_fetch (p) do
113
+ if ! iszero (β)
114
+ rmul! (localpart (y), β)
115
+ else
116
+ fill! (localpart (y), 0 )
117
+ end
118
+ return nothing
114
119
end
115
120
end
116
121
end
@@ -127,7 +132,9 @@ function A_mul_B!(α::Number, A::DMatrix, x::AbstractVector, β::Number, y::DVec
127
132
return y
128
133
end
129
134
130
- function Ac_mul_B! (α:: Number , A:: DMatrix , x:: AbstractVector , β:: Number , y:: DVector )
135
+ function mul! (y:: DVector , adjA:: Adjoint{<:Number,<:DMatrix} , x:: AbstractVector , α:: Number = 1 , β:: Number = 0 )
136
+
137
+ A = parent (adjA)
131
138
132
139
# error checks
133
140
if size (A, 1 ) != length (x)
@@ -148,11 +155,14 @@ function Ac_mul_B!(α::Number, A::DMatrix, x::AbstractVector, β::Number, y::DVe
148
155
149
156
# Scale y if necessary
150
157
if β != one (β)
151
- @sync for p in y. pids
152
- if β != zero (β)
153
- @async remotecall_fetch (() -> (rmul! (localpart (y), β); nothing ), p)
154
- else
155
- @async remotecall_fetch (() -> (fill! (localpart (y), 0 ); nothing ), p)
158
+ asyncmap (procs (y)) do p
159
+ remotecall_fetch (p) do
160
+ if ! iszero (β)
161
+ rmul! (localpart (y), β)
162
+ else
163
+ fill! (localpart (y), 0 )
164
+ end
165
+ return nothing
156
166
end
157
167
end
158
168
end
@@ -189,7 +199,7 @@ function LinearAlgebra.rmul!(DA::DMatrix, D::Diagonal)
189
199
end
190
200
191
201
# Level 3
192
- function _matmatmul! (α :: Number , A:: DMatrix , B:: AbstractMatrix , β :: Number , C :: DMatrix , tA)
202
+ function _matmatmul! (C :: DMatrix , A:: DMatrix , B:: AbstractMatrix , α :: Number , β :: Number , tA)
193
203
# error checks
194
204
Ad1, Ad2 = (tA == ' N' ) ? (1 ,2 ) : (2 ,1 )
195
205
mA, nA = (size (A, Ad1), size (A, Ad2))
@@ -254,40 +264,60 @@ function _matmatmul!(α::Number, A::DMatrix, B::AbstractMatrix, β::Number, C::D
254
264
return C
255
265
end
256
266
257
- A_mul_B! (α:: Number , A:: DMatrix , B:: AbstractMatrix , β:: Number , C:: DMatrix ) = _matmatmul! (α, A, B, β, C, ' N' )
258
- Ac_mul_B! (α:: Number , A:: DMatrix , B:: AbstractMatrix , β:: Number , C:: DMatrix ) = _matmatmul! (α, A, B, β, C, ' C' )
259
- At_mul_B! (α:: Number , A:: DMatrix , B:: AbstractMatrix , β:: Number , C:: DMatrix ) = _matmatmul! (α, A, B, β, C, ' T' )
260
- At_mul_B! (C:: DMatrix , A:: DMatrix , B:: AbstractMatrix ) = At_mul_B! (one (eltype (C)), A, B, zero (eltype (C)), C)
267
+ mul! (C:: DMatrix , A:: DMatrix , B:: AbstractMatrix , α:: Number = 1 , β:: Number = 0 ) = _matmatmul! (C, A, B, α, β, ' N' )
268
+ mul! (C:: DMatrix , A:: Adjoint{<:Number,<:DMatrix} , B:: AbstractMatrix , α:: Number = 1 , β:: Number = 0 ) = _matmatmul! (C, parent (A), B, α, β, ' C' )
269
+ mul! (C:: DMatrix , A:: Transpose{<:Number,<:DMatrix} , B:: AbstractMatrix , α:: Number = 1 , β:: Number = 0 ) = _matmatmul! (C, parent (A), B, α, β, ' T' )
261
270
262
271
_matmul_op = (t,s) -> t* s + t* s
263
272
264
273
function Base.:* (A:: DMatrix , x:: AbstractVector )
265
274
T = Base. promote_op (_matmul_op, eltype (A), eltype (x))
266
275
y = DArray (I -> Array {T} (undef, map (length, I)), (size (A, 1 ),), procs (A)[:,1 ], (size (procs (A), 1 ),))
267
- return A_mul_B! ( one (T) , A, x, zero (T), y )
276
+ return mul! (y , A, x)
268
277
end
269
278
function Base.:* (A:: DMatrix , B:: AbstractMatrix )
270
279
T = Base. promote_op (_matmul_op, eltype (A), eltype (B))
271
280
C = DArray (I -> Array {T} (undef, map (length, I)),
272
281
(size (A, 1 ), size (B, 2 )),
273
282
procs (A)[:,1 : min (size (procs (A), 2 ), size (procs (B), 2 ))],
274
283
(size (procs (A), 1 ), min (size (procs (A), 2 ), size (procs (B), 2 ))))
275
- return A_mul_B! (one (T), A, B, zero (T), C)
284
+ return mul! (C, A, B)
285
+ end
286
+
287
+ function Base.:* (adjA:: Adjoint{<:Any,<:DMatrix} , x:: AbstractVector )
288
+ A = parent (adjA)
289
+ T = Base. promote_op (_matmul_op, eltype (A), eltype (x))
290
+ y = DArray (I -> Array {T} (undef, map (length, I)),
291
+ (size (A, 2 ),),
292
+ procs (A)[1 ,:],
293
+ (size (procs (A), 2 ),))
294
+ return mul! (y, adjA, x)
295
+ end
296
+ function Base.:* (adjA:: Adjoint{<:Any,<:DMatrix} , B:: AbstractMatrix )
297
+ A = parent (adjA)
298
+ T = Base. promote_op (_matmul_op, eltype (A), eltype (B))
299
+ C = DArray (I -> Array {T} (undef, map (length, I)), (size (A, 2 ),
300
+ size (B, 2 )),
301
+ procs (A)[1 : min (size (procs (A), 1 ), size (procs (B), 2 )),:],
302
+ (size (procs (A), 2 ), min (size (procs (A), 1 ), size (procs (B), 2 ))))
303
+ return mul! (C, adjA, B)
276
304
end
277
305
278
- function Ac_mul_B (A:: DMatrix , x:: AbstractVector )
306
+ function Base.:* (trA:: Transpose{<:Any,<:DMatrix} , x:: AbstractVector )
307
+ A = parent (trA)
279
308
T = Base. promote_op (_matmul_op, eltype (A), eltype (x))
280
309
y = DArray (I -> Array {T} (undef, map (length, I)),
281
310
(size (A, 2 ),),
282
311
procs (A)[1 ,:],
283
312
(size (procs (A), 2 ),))
284
- return Ac_mul_B! ( one (T), A , x, zero (T), y )
313
+ return mul! (y, trA , x)
285
314
end
286
- function Ac_mul_B (A:: DMatrix , B:: AbstractMatrix )
315
+ function Base.:* (trA:: Transpose{<:Any,<:DMatrix} , B:: AbstractMatrix )
316
+ A = parent (trA)
287
317
T = Base. promote_op (_matmul_op, eltype (A), eltype (B))
288
318
C = DArray (I -> Array {T} (undef, map (length, I)), (size (A, 2 ),
289
319
size (B, 2 )),
290
320
procs (A)[1 : min (size (procs (A), 1 ), size (procs (B), 2 )),:],
291
321
(size (procs (A), 2 ), min (size (procs (A), 1 ), size (procs (B), 2 ))))
292
- return Ac_mul_B! ( one (T), A , B, zero (T), C )
322
+ return mul! (C, trA , B)
293
323
end
0 commit comments