1
1
const FillVector{F,A} = Fill{F,1 ,A}
2
2
const FillMatrix{F,A} = Fill{F,2 ,A}
3
+ const OnesVector{F,A} = Ones{F,1 ,A}
4
+ const OnesMatrix{F,A} = Ones{F,2 ,A}
5
+ const ZerosVector{F,A} = Zeros{F,1 ,A}
6
+ const ZerosMatrix{F,A} = Zeros{F,2 ,A}
7
+
3
8
4
9
# # vec
5
10
vec (a:: Ones{T} ) where T = Ones {T} (length (a))
@@ -17,6 +22,13 @@ adjoint(a::Zeros{T,2}) where T = Zeros{T}(reverse(a.axes))
17
22
transpose (a:: Fill{T,2} ) where T = Fill {T} (transpose (a. value), reverse (a. axes))
18
23
adjoint (a:: Fill{T,2} ) where T = Fill {T} (adjoint (a. value), reverse (a. axes))
19
24
25
+ fillsimilar (a:: Ones{T} , axes) where T = Ones {T} (axes)
26
+ fillsimilar (a:: Zeros{T} , axes) where T = Zeros {T} (axes)
27
+ fillsimilar (a:: AbstractFill , axes) = Fill (getindex_value (a), axes)
28
+ fillsimilar (a:: Ones , :: Type{T} , axes) where T = Ones {T} (axes)
29
+ fillsimilar (a:: Zeros , :: Type{T} , axes) where T = Zeros {T} (axes)
30
+ fillsimilar (a:: AbstractFill , :: Type{T} , axes) where T = Fill {T} (getindex_value (a), axes)
31
+
20
32
permutedims (a:: AbstractFill{<:Any,1} ) = fillsimilar (a, (1 , length (a)))
21
33
permutedims (a:: AbstractFill{<:Any,2} ) = fillsimilar (a, reverse (a. axes))
22
34
34
46
function mult_fill (a:: AbstractFill , b:: AbstractFill{<:Any,2} )
35
47
axes (a, 2 ) ≠ axes (b, 1 ) &&
36
48
throw (DimensionMismatch (" Incompatible matrix multiplication dimensions" ))
37
- return Fill (getindex_value (a)* getindex_value (b)* size (a, 2 ) , (axes (a, 1 ), axes (b, 2 )))
49
+ return Fill (getindex_value (a)* getindex_value (b), (axes (a, 1 ), axes (b, 2 )))
38
50
end
39
51
40
52
function mult_fill (a:: AbstractFill , b:: AbstractFill{<:Any,1} )
41
53
axes (a, 2 ) ≠ axes (b, 1 ) &&
42
54
throw (DimensionMismatch (" Incompatible matrix multiplication dimensions" ))
43
- return Fill (getindex_value (a)* getindex_value (b)* size (a, 2 ) , (axes (a, 1 ),))
55
+ return Fill (getindex_value (a)* getindex_value (b), (axes (a, 1 ),))
44
56
end
45
57
46
- function mult_ones (a:: AbstractVector , b:: AbstractMatrix )
58
+ function mult_ones (a, b:: AbstractMatrix )
47
59
axes (a, 2 ) ≠ axes (b, 1 ) &&
48
60
throw (DimensionMismatch (" Incompatible matrix multiplication dimensions" ))
49
61
return Ones {promote_type(eltype(a), eltype(b))} ((axes (a, 1 ), axes (b, 2 )))
50
62
end
63
+ function mult_ones (a, b:: AbstractVector )
64
+ axes (a, 2 ) ≠ axes (b, 1 ) &&
65
+ throw (DimensionMismatch (" Incompatible matrix multiplication dimensions" ))
66
+ return Ones {promote_type(eltype(a), eltype(b))} ((axes (a, 1 ),))
67
+ end
51
68
52
69
function mult_zeros (a, b:: AbstractMatrix )
53
70
axes (a, 2 ) ≠ axes (b, 1 ) &&
65
82
* (a:: AbstractFill{<:Any,2} , b:: AbstractFill{<:Any,1} ) = mult_fill (a,b)
66
83
67
84
* (a:: Ones{<:Any,1} , b:: Ones{<:Any,2} ) = mult_ones (a, b)
85
+ * (a:: Ones{<:Any,2} , b:: Ones{<:Any,2} ) = mult_ones (a, b)
86
+ * (a:: Ones{<:Any,2} , b:: Ones{<:Any,1} ) = mult_ones (a, b)
68
87
69
88
* (a:: Zeros{<:Any,1} , b:: Zeros{<:Any,2} ) = mult_zeros (a, b)
70
89
* (a:: Zeros{<:Any,2} , b:: Zeros{<:Any,2} ) = mult_zeros (a, b)
89
108
* (a:: Zeros{<:Any,2} , b:: Diagonal ) = mult_zeros (a, b)
90
109
* (a:: Diagonal , b:: Zeros{<:Any,1} ) = mult_zeros (a, b)
91
110
* (a:: Diagonal , b:: Zeros{<:Any,2} ) = mult_zeros (a, b)
92
- function * (a:: Diagonal , b:: AbstractFill{<:Any,2} )
93
- size (a,2 ) == size (b,1 ) || throw (DimensionMismatch (" A has dimensions $(size (a)) but B has dimensions $(size (b)) " ))
94
- a. diag .* b # use special broadcast
95
- end
96
- function * (a:: AbstractFill{<:Any,2} , b:: Diagonal )
97
- size (a,2 ) == size (b,1 ) || throw (DimensionMismatch (" A has dimensions $(size (a)) but B has dimensions $(size (b)) " ))
98
- a .* permutedims (b. diag) # use special broadcast
99
- end
100
111
101
112
* (a:: Adjoint{T, <:StridedMatrix{T}} , b:: Fill{T, 1} ) where T = reshape (sum (conj .(parent (a)); dims= 1 ) .* b. value, size (parent (a), 2 ))
102
113
* (a:: Transpose{T, <:StridedMatrix{T}} , b:: Fill{T, 1} ) where T = reshape (sum (parent (a); dims= 1 ) .* b. value, size (parent (a), 2 ))
@@ -116,30 +127,29 @@ function *(f::FillMatrix, x::AbstractMatrix)
116
127
repeat (sum (x, dims= 1 ) * f. value, m, 1 )
117
128
end
118
129
119
- function * (x:: AbstractMatrix , f:: Ones )
130
+ function * (x:: AbstractMatrix , f:: OnesMatrix )
120
131
axes (x, 2 ) ≠ axes (f, 1 ) &&
121
132
throw (DimensionMismatch (" Incompatible matrix multiplication dimensions" ))
122
133
m = size (f, 2 )
123
134
repeat (sum (x, dims= 2 ) * one (eltype (f)), 1 , m)
124
135
end
125
136
126
- function * (f:: Ones , x:: AbstractMatrix )
137
+ function * (f:: OnesMatrix , x:: AbstractMatrix )
127
138
axes (f, 2 ) ≠ axes (x, 1 ) &&
128
139
throw (DimensionMismatch (" Incompatible matrix multiplication dimensions" ))
129
140
m = size (f, 1 )
130
141
repeat (sum (x, dims= 1 ) * one (eltype (f)), m, 1 )
131
142
end
132
143
133
- function _adjvec_mul_zeros (a:: Adjoint{T} , b:: Zeros{S, 1} ) where {T, S}
144
+
145
+
146
+ function * (a:: Adjoint{T, <:AbstractVector{T}} , b:: Zeros{S, 1} ) where {T, S}
134
147
la, lb = length (a), length (b)
135
148
if la ≠ lb
136
149
throw (DimensionMismatch (" dot product arguments have lengths $la and $lb " ))
137
150
end
138
- return zero (Base . promote_op ( * , T, S))
151
+ return zero (promote_type ( T, S))
139
152
end
140
-
141
- * (a:: AdjointAbsVec , b:: Zeros{<:Any, 1} ) = _adjvec_mul_zeros (a, b)
142
- * (a:: AdjointAbsVec{<:Number} , b:: Zeros{<:Number, 1} ) = _adjvec_mul_zeros (a, b)
143
153
* (a:: Adjoint{T, <:AbstractMatrix{T}} where T, b:: Zeros{<:Any, 1} ) = mult_zeros (a, b)
144
154
145
155
function * (a:: Transpose{T, <:AbstractVector{T}} , b:: Zeros{T, 1} ) where T<: Real
@@ -161,7 +171,6 @@ function +(a::Zeros{T}, b::Zeros{V}) where {T, V}
161
171
return Zeros {promote_type(T,V)} (size (a)... )
162
172
end
163
173
- (a:: Zeros , b:: Zeros ) = - (a + b)
164
- - (a:: Ones , b:: Ones ) = Zeros (a)+ Zeros (b)
165
174
166
175
# Zeros +/- Fill and Fill +/- Zeros
167
176
function + (a:: AbstractFill{T} , b:: Zeros{V} ) where {T, V}
241
250
242
251
function rmul! (z:: AbstractFill , x:: Number )
243
252
λ = getindex_value (z)
244
- # Following check ensures consistency w/ lmul!(x, Array(z))
253
+ # Following check ensures consistency w/ lmul!(x, Array(z))
245
254
# for, e.g., lmul!(NaN, z)
246
255
λ* x == λ || throw (ArgumentError (" Cannot scale by $x " ))
247
256
z
248
- end
249
-
250
- fillzero (:: Type{Fill{T,N,AXIS}} , n, m) where {T,N,AXIS} = Fill {T,N,AXIS} (zero (T), (n, m))
251
- fillzero (:: Type{Zeros{T,N,AXIS}} , n, m) where {T,N,AXIS} = Zeros {T,N,AXIS} ((n, m))
252
- fillzero (:: Type{F} , n, m) where F = throw (ArgumentError (" Cannot create a zero array of type $F " ))
253
-
254
- diagzero (D:: Diagonal{F} , i, j) where F<: AbstractFill = fillzero (F, axes (D. diag[i], 1 ), axes (D. diag[j], 2 ))
257
+ end
0 commit comments