Skip to content

Handle INCX=0 in ?NRM2 #5116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion interface/nrm2.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,37 @@ FLOATRET NAME(blasint *N, FLOAT *x, blasint *INCX){
#else
return fabsf(x[0]);
#endif
#endif

if (incx == 0)
#ifndef COMPLEX
#ifdef DOUBLE
return (sqrt((double)n)*fabs(x[0]));
#else
return (sqrt((float)n)*fabsf(x[0]));
#endif
#else
#ifdef DOUBLE
{
double fr=fabs(x[0]);
double fi=fabs(x[1]);
double fmin=MIN(fr,fi);
double fmax=MAX(fr,fi);
if (fmax==0.) return(fmax);
if (fmax==fmin) return(sqrt((double)n)*sqrt(2.)*fmax);
return (sqrt((double)n) * fmax * sqrt (1. + (fmin/fmax)*(fmin/fmax)));
}
#else
{
float fr=fabs(x[0]);
float fi=fabs(x[1]);
float fmin=MIN(fr,fi);
float fmax=MAX(fr,fi);
if (fmax==0.) return(fmax);
if (fmax==fmin) return(sqrt((float)n)*sqrt(2.)*fmax);
return (sqrt((float)n) * fmax * sqrt (1. + (fmin/fmax)*(fmin/fmax)));
}
#endif
#endif

if (incx < 0)
Expand Down Expand Up @@ -97,13 +128,44 @@ FLOAT CNAME(blasint n, FLOAT *x, blasint incx){

if (n <= 0) return 0.;

#ifndef COMPLEX
#ifndef COMPLEX
if (n == 1)
#ifdef DOUBLE
return fabs(x[0]);
#else
return fabsf(x[0]);
#endif
#endif

if (incx == 0)
#ifndef COMPLEX
#ifdef DOUBLE
return (sqrt((double)n)*fabs(x[0]));
#else
return (sqrt((float)n)*fabsf(x[0]));
#endif
#else
#ifdef DOUBLE
{
double fr=fabs(x[0]);
double fi=fabs(x[1]);
double fmin=MIN(fr,fi);
double fmax=MAX(fr,fi);
if (fmax==0.) return(fmax);
if (fmax==fmin) return(sqrt((double)n)*sqrt(2.)*fmax);
return (sqrt((double)n) * fmax * sqrt (1. + (fmin/fmax)*(fmin/fmax)));
}
#else
{
float fr=fabs(x[0]);
float fi=fabs(x[1]);
float fmin=MIN(fr,fi);
float fmax=MAX(fr,fi);
if (fmax==0.) return(fmax);
if (fmax==fmin) return(sqrt((float)n)*sqrt(2.)*fmax);
return (sqrt((float)n) * fmax * sqrt (1. + (fmin/fmax)*(fmin/fmax)));
}
#endif
#endif

if (incx < 0)
Expand Down
Loading