The Computer Language
24.09 Benchmarks Game

spectral-norm C# .NET #8 program

source code

/* The Computer Language Benchmarks Game
   https://salsa.debian.org/benchmarksgame-team/benchmarksgame/

   Naive transliteration from Sebastien Loisel's C program
   contributed by Isaac Gouy
*/

class SpectralNorm
{
  double eval_A(int i, int j) { return 1.0/((i+j)*(i+j+1)/2+i+1); }   
   
  void eval_A_times_u(int N, double[] u, double[] Au)
  {
    int i,j;
    for(i=0;i<N;i++)
      {
        Au[i]=0;
        for(j=0;j<N;j++) Au[i]+=eval_A(i,j)*u[j];
      }
  }    
  
  void eval_At_times_u(int N, double[] u, double[] Au)
  {
    int i,j;
    for(i=0;i<N;i++)
      {
        Au[i]=0;
        for(j=0;j<N;j++) Au[i]+=eval_A(j,i)*u[j];
      }
  }  
  
  void eval_AtA_times_u(int N, double[] u, double[] AtAu)
  { var v = new double[N]; eval_A_times_u(N,u,v); eval_At_times_u(N,v,AtAu); }  
  
  public static void Main(String[] args) 
  {
    int i;    
    int N = args.Length > 0 ? Int32.Parse(args[0]) : 100; 
    var nonStatic = new SpectralNorm();
    var u = new double[N];      
    var v = new double[N];  
    double vBv, vv;        
    for (i=0; i<N; i++) u[i] = 1;    
    for(i=0; i<10; i++)
    {
      nonStatic.eval_AtA_times_u(N,u,v);
      nonStatic.eval_AtA_times_u(N,v,u);
    }        
    vBv = vv = 0;
    for(i=0; i<N; i++) { vBv += u[i]*v[i]; vv += v[i]*v[i]; }          
    Console.WriteLine("{0:f9}", Math.Sqrt(vBv/vv));  
  }
}  
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
.NET SDK 8.0.301
Host Version: 8.0.6
Commit: 3b8b000a0e

<OutputType>Exe
<TargetFramework>net8.0
<ImplicitUsings>enable
<Nullable>enable
<AllowUnsafeBlocks>true
<ServerGarbageCollection>true
<ConcurrentGarbageCollection>true
<PublishAot>false



 Sun, 20 Oct 2024 21:21:21 GMT

MAKE:
cp spectralnorm.csharpcore-8.csharpcore Program.cs
cp Include/csharpcore/program.csproj .
mkdir obj
cp Include/csharpcore/project.assets.json ./obj
~/dotnet/dotnet build -c Release --use-current-runtime  	
  Determining projects to restore...
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/spectralnorm/tmp/program.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source https://api.nuget.org/v3/index.json.
  Restored /home/dunham/all-benchmarksgame/benchmarksgame_i53330/spectralnorm/tmp/program.csproj (in 5.97 sec).
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/spectralnorm/tmp/program.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source https://api.nuget.org/v3/index.json.
  program -> /home/dunham/all-benchmarksgame/benchmarksgame_i53330/spectralnorm/tmp/bin/Release/net8.0/linux-x64/program.dll

Build succeeded.

/home/dunham/all-benchmarksgame/benchmarksgame_i53330/spectralnorm/tmp/program.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source https://api.nuget.org/v3/index.json.
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/spectralnorm/tmp/program.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source https://api.nuget.org/v3/index.json.
    2 Warning(s)
    0 Error(s)

Time Elapsed 00:00:10.87

13.04s to complete and log all make actions

COMMAND LINE:
 ./bin/Release/net8.0/linux-x64/program 5500

PROGRAM OUTPUT:
1.274224153