@@ -3,10 +3,14 @@ __precompile__()
3
3
module BandedMatrices
4
4
using Base
5
5
6
- import Base: getindex, setindex!, * , .* , + , .+ , - , . - , == , < , <= , > ,
7
- >= , ./ , / , .^ , ^ , \ , transpose, showerror
6
+ import Base: getindex, setindex!, * , + , - , == , < , <= , > ,
7
+ >= , / , ^ , \ , transpose, showerror
8
8
9
9
10
+ if VERSION < v " 0.6.0-dev"
11
+ import Base: .* , .+ , .- , ./ , .^
12
+ end
13
+
10
14
import Base: convert, size, view
11
15
12
16
import Base. BLAS: libblas
@@ -170,11 +174,11 @@ returns an unitialized `n`×`m` banded matrix of type `T` with bandwidths `(l,u)
170
174
171
175
# Use zeros to avoid unallocated entries for bigfloat
172
176
BandedMatrix {T<:BlasFloat} (:: Type{T} ,n:: Integer ,m:: Integer ,a:: Integer ,b:: Integer ) =
173
- BandedMatrix {T} (Array (T, b+ a+ 1 ,m),n,a,b)
177
+ BandedMatrix {T} (Matrix {T} ( b+ a+ 1 ,m),n,a,b)
174
178
BandedMatrix {T<:Number} (:: Type{T} ,n:: Integer ,m:: Integer ,a:: Integer ,b:: Integer ) =
175
179
BandedMatrix {T} (zeros (T,b+ a+ 1 ,m),n,a,b)
176
180
BandedMatrix {T} (:: Type{T} ,n:: Integer ,m:: Integer ,a:: Integer ,b:: Integer ) =
177
- BandedMatrix {T} (Array (T, b+ a+ 1 ,m),n,a,b)
181
+ BandedMatrix {T} (Matrix {T} ( b+ a+ 1 ,m),n,a,b)
178
182
179
183
180
184
@@ -910,7 +914,7 @@ bandwidth(A::BandedMatrix,k::Integer) = k==1?A.l:A.u
910
914
911
915
912
916
function Base. sparse (B:: BandedMatrix )
913
- i= Array ( Int, length (B. data));j= Array ( Int, length (B. data))
917
+ i= Vector { Int} ( length (B. data));j= Vector { Int} ( length (B. data))
914
918
n,m= size (B. data)
915
919
Bn= size (B,1 )
916
920
vb= copy (vec (B. data))
@@ -1015,14 +1019,14 @@ function *{T<:Number,V<:Number}(A::BLASBandedMatrix{T},B::StridedMatrix{V})
1015
1019
end
1016
1020
n,m= size (A,1 ),size (B,2 )
1017
1021
1018
- A_mul_B! (Array ( promote_type (T,V), n,m),A,B)
1022
+ A_mul_B! (Matrix { promote_type(T,V)} ( n,m),A,B)
1019
1023
end
1020
1024
1021
1025
* {T<: Number ,V<: Number }(A:: StridedMatrix{T} ,B:: BLASBandedMatrix{V} ) =
1022
1026
A* Array (B)
1023
1027
1024
1028
* {T<: BlasFloat }(A:: BLASBandedMatrix{T} ,b:: StridedVector{T} ) =
1025
- A_mul_B! (Array (T, size (A,1 )),A,b)
1029
+ A_mul_B! (Vector {T} ( size (A,1 )),A,b)
1026
1030
1027
1031
function * {T}(A:: BandedMatrix{T} ,b:: StridedVector{T} )
1028
1032
ret = zeros (T,size (A,1 ))
@@ -1072,7 +1076,7 @@ end
1072
1076
1073
1077
# # Matrix.*Matrix
1074
1078
1075
- function .* ( A:: BandedMatrix , B:: BandedMatrix )
1079
+ function broadcast ( :: typeof ( * ), A:: BandedMatrix , B:: BandedMatrix )
1076
1080
@assert size (A,1 )== size (B,1 )&& size (A,2 )== size (B,2 )
1077
1081
1078
1082
l= min (A. l,B. l);u= min (A. u,B. u)
@@ -1086,13 +1090,28 @@ function .*(A::BandedMatrix, B::BandedMatrix)
1086
1090
end
1087
1091
1088
1092
1093
+
1094
+
1089
1095
# # numbers
1090
- for OP in (:* ,:/ ,:.* ,:./ )
1091
- @eval $ OP (A:: BandedMatrix ,b:: Number ) = BandedMatrix ($ OP (A. data,b),A. m,A. l,A. u)
1096
+ for OP in (:* ,:/ )
1097
+ @eval begin
1098
+ $ OP (A:: BandedMatrix , b:: Number ) = BandedMatrix ($ OP (A. data,b),A. m,A. l,A. u)
1099
+ broadcast (:: typeof ($ OP), A:: BandedMatrix , b:: Number ) =
1100
+ BandedMatrix ($ OP .(A. data,b),A. m,A. l,A. u)
1101
+ end
1092
1102
end
1093
1103
1094
- for OP in (:* ,:.* ,:./ )
1095
- @eval $ OP (a:: Number ,B:: BandedMatrix ) = BandedMatrix ($ OP (a,B. data),B. m,B. l,B. u)
1104
+
1105
+ * (a:: Number ,B:: BandedMatrix ) = BandedMatrix (a* B. data,B. m,B. l,B. u)
1106
+ broadcast (:: typeof (* ), a:: Number , B:: BandedMatrix ) = BandedMatrix (a.* B. data,B. m,B. l,B. u)
1107
+
1108
+ if VERSION < v " 0.6.0-dev"
1109
+ @eval quote
1110
+ .* (A:: BandedMatrix , B:: BandedMatrix ) = (* ). (A,B)
1111
+ .* (A:: BandedMatrix , b:: Number ) = (* ). (A,b)
1112
+ .* (a:: Number , B:: BandedMatrix ) = (* ). (a,B)
1113
+ ./ (A:: BandedMatrix , b:: Number ) = (/ ). (A,b)
1114
+ end
1096
1115
end
1097
1116
1098
1117
@@ -1153,7 +1172,7 @@ if VERSION < v"0.5.0-rc4"
1153
1172
1154
1173
if ! isempty (B) && size (B,1 ) ≤ 1000 && size (B,2 ) ≤ 1000
1155
1174
header && println (io," :" )
1156
- M= Array ( Any, size (B)... )
1175
+ M= Array { Any} ( size (B)... )
1157
1176
fill! (M,PrintShow (" " ))
1158
1177
for j = 1 : size (B,2 ), k = colrange (B,j)
1159
1178
M[k,j]= B[k,j]
@@ -1170,7 +1189,7 @@ else
1170
1189
1171
1190
if ! isempty (B) && size (B,1 ) ≤ 1000 && size (B,2 ) ≤ 1000
1172
1191
header && println (io," :" )
1173
- M= Array ( Any, size (B)... )
1192
+ M= Array { Any} ( size (B)... )
1174
1193
fill! (M,PrintShow (" " ))
1175
1194
for j = 1 : size (B,2 ), k = colrange (B,j)
1176
1195
M[k,j]= B[k,j]
0 commit comments