@@ -280,10 +280,10 @@ diag(A::AbstractVector) = throw(ArgumentError("use diagm instead of diag to cons
280
280
function generic_vecnormMinusInf (x)
281
281
s = start (x)
282
282
(v, s) = next (x, s)
283
- minabs = norm (v)
283
+ minabs = vecnormMinusInf (v)
284
284
while ! done (x, s)
285
285
(v, s) = next (x, s)
286
- vnorm = norm (v)
286
+ vnorm = vecnormMinusInf (v)
287
287
minabs = ifelse (isnan (minabs) | (minabs < vnorm), minabs, vnorm)
288
288
end
289
289
return float (minabs)
@@ -292,10 +292,10 @@ end
292
292
function generic_vecnormInf (x)
293
293
s = start (x)
294
294
(v, s) = next (x, s)
295
- maxabs = norm (v)
295
+ maxabs = vecnormInf (v)
296
296
while ! done (x, s)
297
297
(v, s) = next (x, s)
298
- vnorm = norm (v)
298
+ vnorm = vecnormInf (v)
299
299
maxabs = ifelse (isnan (maxabs) | (maxabs > vnorm), maxabs, vnorm)
300
300
end
301
301
return float (maxabs)
@@ -304,20 +304,20 @@ end
304
304
function generic_vecnorm1 (x)
305
305
s = start (x)
306
306
(v, s) = next (x, s)
307
- av = float (norm (v))
307
+ av = float (vecnorm1 (v))
308
308
T = typeof (av)
309
309
sum:: promote_type (Float64, T) = av
310
310
while ! done (x, s)
311
311
(v, s) = next (x, s)
312
- sum += norm (v)
312
+ sum += vecnorm1 (v)
313
313
end
314
314
return convert (T, sum)
315
315
end
316
316
317
317
# faster computation of norm(x)^2, avoiding overflow for integers
318
- norm_sqr (x) = norm (x)^ 2
319
- norm_sqr (x:: Number ) = abs2 (x)
320
- norm_sqr (x:: Union{T,Complex{T},Rational{T}} ) where {T<: Integer } = abs2 (float (x))
318
+ vecnorm_sqr (x) = vecnorm (x)^ 2
319
+ vecnorm_sqr (x:: Number ) = abs2 (x)
320
+ vecnorm_sqr (x:: Union{T,Complex{T},Rational{T}} ) where {T<: Integer } = abs2 (float (x))
321
321
322
322
function generic_vecnorm2 (x)
323
323
maxabs = vecnormInf (x)
@@ -326,17 +326,17 @@ function generic_vecnorm2(x)
326
326
(v, s) = next (x, s)
327
327
T = typeof (maxabs)
328
328
if isfinite (_length (x)* maxabs* maxabs) && maxabs* maxabs != 0 # Scaling not necessary
329
- sum:: promote_type (Float64, T) = norm_sqr (v)
329
+ sum:: promote_type (Float64, T) = vecnorm_sqr (v)
330
330
while ! done (x, s)
331
331
(v, s) = next (x, s)
332
- sum += norm_sqr (v)
332
+ sum += vecnorm_sqr (v)
333
333
end
334
334
return convert (T, sqrt (sum))
335
335
else
336
- sum = abs2 (norm (v)/ maxabs)
336
+ sum = abs2 (vecnorm (v)/ maxabs)
337
337
while ! done (x, s)
338
338
(v, s) = next (x, s)
339
- sum += (norm (v)/ maxabs)^ 2
339
+ sum += (vecnorm (v)/ maxabs)^ 2
340
340
end
341
341
return convert (T, maxabs* sqrt (sum))
342
342
end
@@ -352,21 +352,21 @@ function generic_vecnormp(x, p)
352
352
(maxabs == 0 || isinf (maxabs)) && return maxabs
353
353
T = typeof (maxabs)
354
354
else
355
- T = typeof (float (norm (v)))
355
+ T = typeof (float (vecnorm (v)))
356
356
end
357
357
spp:: promote_type (Float64, T) = p
358
358
if - 1 <= p <= 1 || (isfinite (_length (x)* maxabs^ spp) && maxabs^ spp != 0 ) # scaling not necessary
359
- sum:: promote_type (Float64, T) = norm (v )^ spp
359
+ sum:: promote_type (Float64, T) = vecnormp (v, p )^ spp
360
360
while ! done (x, s)
361
361
(v, s) = next (x, s)
362
- sum += norm (v )^ spp
362
+ sum += vecnormp (v, p )^ spp
363
363
end
364
364
return convert (T, sum^ inv (spp))
365
365
else # rescaling
366
- sum = (norm (v )/ maxabs)^ spp
366
+ sum = (vecnormp (v, p )/ maxabs)^ spp
367
367
while ! done (x, s)
368
368
(v, s) = next (x, s)
369
- sum += (norm (v )/ maxabs)^ spp
369
+ sum += (vecnorm (v, p )/ maxabs)^ spp
370
370
end
371
371
return convert (T, maxabs* sum^ inv (spp))
372
372
end
@@ -449,6 +449,11 @@ julia> vecnorm(-2, Inf)
449
449
```
450
450
"""
451
451
@inline vecnorm (x:: Number , p:: Real = 2 ) = p == 0 ? (x== 0 ? zero (abs (x)) : oneunit (abs (x))) : abs (x)
452
+ @inline vecnormMinusInf (x:: Number ) = abs (x)
453
+ @inline vecnormInf (x:: Number ) = abs (x)
454
+ @inline vecnorm1 (x:: Number ) = abs (x)
455
+ @inline vecnorm2 (x:: Number ) = abs (x)
456
+ @inline vecnormp (x:: Number , p) = p == 0 ? (x== 0 ? zero (abs (x)) : oneunit (abs (x))) : abs (x)
452
457
453
458
function norm1 (A:: AbstractMatrix{T} ) where T
454
459
m, n = size (A)
@@ -621,11 +626,11 @@ function vecdot(x::AbstractArray, y::AbstractArray)
621
626
throw (DimensionMismatch (" first array has length $(lx) which does not match the length of the second, $(_length (y)) ." ))
622
627
end
623
628
if lx == 0
624
- return dot (zero (eltype (x)), zero (eltype (y)))
629
+ return vecdot (zero (eltype (x)), zero (eltype (y)))
625
630
end
626
- s = zero (dot (first (x), first (y)))
631
+ s = zero (vecdot (first (x), first (y)))
627
632
for (Ix, Iy) in zip (eachindex (x), eachindex (y))
628
- @inbounds s += dot (x[Ix], y[Iy])
633
+ @inbounds s += vecdot (x[Ix], y[Iy])
629
634
end
630
635
s
631
636
end
@@ -656,22 +661,22 @@ function vecdot(x, y) # arbitrary iterables
656
661
if ! isempty (y)
657
662
throw (DimensionMismatch (" x and y are of different lengths!" ))
658
663
end
659
- return dot (zero (eltype (x)), zero (eltype (y)))
664
+ return vecdot (zero (eltype (x)), zero (eltype (y)))
660
665
end
661
666
iy = start (y)
662
667
if done (y, iy)
663
668
throw (DimensionMismatch (" x and y are of different lengths!" ))
664
669
end
665
670
(vx, ix) = next (x, ix)
666
671
(vy, iy) = next (y, iy)
667
- s = dot (vx, vy)
672
+ s = vecdot (vx, vy)
668
673
while ! done (x, ix)
669
674
if done (y, iy)
670
675
throw (DimensionMismatch (" x and y are of different lengths!" ))
671
676
end
672
677
(vx, ix) = next (x, ix)
673
678
(vy, iy) = next (y, iy)
674
- s += dot (vx, vy)
679
+ s += vecdot (vx, vy)
675
680
end
676
681
if ! done (y, iy)
677
682
throw (DimensionMismatch (" x and y are of different lengths!" ))
0 commit comments