### ----------------------------------------------------
### -- Math::Libgsl::LinearAlgebra
### -- Licenses: Artistic-2.0
### -- Authors: Fernando Santagata
### -- File: t/03-complex-linalg.rakutest
### ----------------------------------------------------
### -- Chunk 1 of 2
#!/usr/bin/env raku

use Test;
use lib 'lib';
use Math::Libgsl::LinearAlgebra::Complex64;
use Math::Libgsl::Vector::Complex64;
use Math::Libgsl::Matrix::Complex64;
use Math::Libgsl::Complex;
use Math::Libgsl::Permutation;
use Math::Libgsl::Random;
use Math::Libgsl::Constants;
use NativeCall;

sub create-random-matrix(Math::Libgsl::Matrix::Complex64 $m, Math::Libgsl::Random $r --> Int)
{
  for ^$m.matrix.size1 X ^$m.matrix.size2 -> ($i, $j) {
    $m[$i;$j] = $r.get-uniform-pos + $r.get-uniform-pos * i;
  }
  return GSL_SUCCESS;
}

sub create-random-vector(Math::Libgsl::Vector::Complex64 $v, Math::Libgsl::Random $r --> Int)
{
  for ^$v.vector.size -> $i {
    $v[$i] = $r.get-uniform-pos + $r.get-uniform-pos * i;
  }
  return GSL_SUCCESS;
}

subtest 'LU decomposition' => {
  my $*TOLERANCE = 1e-12;
  my Math::Libgsl::Random $r            .= new;
  my Math::Libgsl::Matrix::Complex64 $m .= new(10, 10);
  my Math::Libgsl::Matrix::Complex64 $A .= new(10, 10);
  my Math::Libgsl::Vector::Complex64 $b .= new(10);
  my Complex @res;
  if $gsl-version > v2.5 {
    @res = 0.6138245570473373+0.965768184280023i, 0.49709826125763357+0.529885402880609i,
    0.4616075318772346+0.7130337005946785i, 0.5799597676377743+0.6828025553841144i,
    0.9539215140976012+0.023655203636735678i, 0.2801101468503475+0.8695263534318656i,
    0.29933327389881015+0.3195536034181714i, 0.30095170880667865+0.9411114864051342i,
    0.8481270638294518+0.7533461293205619i, 0.5382440872490406+0.408481381367892i,
    0.5887787867093579-0.660960757815612i, -0.36029656328916926+0.963778240883897i,
    -0.5114154749013582+0.37025896130087566i, 0.1647032537618629+0.7256163305336503i,
    -0.03724025466428371+1.3565299862299818i, 0.02029808827189561+0.3318197579960815i,
    -0.07181585214293751+0.8141041793603297i, -0.27955962811207113-0.18661678772092527i,
    -0.5217617218300746+0.5093384808406901i, -0.36522917685067036+0.32844350663054095i,
    0.260210011816573+0.13397427368029974i, 0.6267564229246986-0.37519845129898827i,
    0.7369572906310078+0.22697834001925243i, 0.23065162426498842-0.1497497298527941i,
    -0.17004986367516567-0.8158579849493026i, 0.2029120112669369-0.3467324361186862i,
    -0.23259946770080817-0.012318650035863854i, 1.018426730929398+0.3639976714803736i,
    0.7300374107735879-0.7250745236655695i, 0.719614929717264-0.4134768347715249i,
    0.49329142723409747-0.5467339399605644i, 0.6936358511065944-0.47633289122280664i,
    -0.051116905110818775+0.045827640102868834i, -0.7676525209763408-0.41665232004416697i,
    -0.5368380298584668+0.08465866573545916i, -0.2923353191235311+0.20050160621691862i,
    -0.528243661007627-0.5405445339805213i, -0.0006631948102430174-0.20984557192770456i,
    -0.4647972727571371-0.19920763818627185i, 0.06601013441354946+0.23666707738026352i,
    0.5375964757100722+0.21560836214896117i, 0.04072690048720611+0.11467543542070203i,
    0.9281534686233366-0.4968271390471315i, -0.3572346931715783+0.25975442699167306i,
    0.4535598664490146+1.2507925864882699i, 0.8528238693574728+0.6757607826602274i,
    -0.021464400081336876-0.3004353517899412i, -0.6705400289454452+0.3400558666106742i,
    -0.2770231755354577+1.4798195766698024i, 0.4546237750240897+0.8361064337176354i,
    0.3478515541672757+0.011236549779313959i, 0.28307450698291703-0.6106930747802171i,
    0.24830168453044288-0.850493682541428i, -0.4921351300592569-0.5406510200328339i,
    -0.3730592867704049+0.2502069815912417i, 1.1442921293504216+0.27425683577274285i,
    -0.22398131803840643-1.2416724960378627i, 0.35343634203242713+0.5218938513502169i,
    0.29721261443806146+0.3503939910433213i, 0.7829355812218507+1.3308390194385715i,
    0.621213716587266-0.2725896586002249i, 0.4413147630166774-0.2715634197889963i,
    0.38027441549049606-0.02705270326662565i, 1.0027909774775638-0.08123635630389253i,
    0.3771548185532088+0.357258007512661i, -0.3967189509026927-0.7228876162028949i,
    1.0900316913163461-0.38946420592397674i, 0.15290187053202078+0.862384344127862i,
    0.27277336291589394+0.1852636282707339i, -0.28135071139705137+1.077920217651145i,
    0.43111270343794184+0.1401835504081087i, -0.03144796768972364-0.05854578489410745i,
    -0.16658970023999065-0.30458824598696405i, -0.32480330251498696+0.4571173337254274i,
    0.5884423395073838+0.3028238946775348i, -0.04395613439714352-0.3597949673373309i,
    -0.15435403158171335+0.20464611648959743i, 1.1793124517690599+0.2583843085229872i,
    0.8131465882086126-0.855316325721859i, 0.19966911352474379+0.3750560769911181i,
    0.4623993173835938+0.10501610829363456i, -0.1302183840605556-0.5391899849671723i,
    -0.3579794380861887-0.08732899261163692i, -0.40440391420335997-0.36775165687935407i,
    -0.14500368757568105+0.5186950444395798i, 0.11333964943133586-0.47792028207619025i,
    -0.04491447105156655-0.11851619534248728i, 0.5718200105099125+0.2777504755186013i,
    0.14587134634934185+0.2893791755960358i, 0.4076161555442558-0.14040444875112623i,
    0.41863381273182443+0.1305569507667894i, 0.4785033203048611-0.42347463110349964i,
    0.17844143310647945-0.15384191401552333i, -0.28761714205481276-0.3738681841610698i,
    -0.1753678080508539+0.3700335539552852i, 0.875251451526503-0.35381127133725565i,
    0.20626820779175656+0.6446561454377433i, 0.4540308531119-0.500517757891799i,
    1.024370829775503+0.07437272777123383i, -0.8418168621318789-0.18635345290657496i;
  } else {
    @res = 0.6138245570473373+0.965768184280023i, 0.49709826125763357+0.529885402880609i,
    0.4616075318772346+0.7130337005946785i, 0.5799597676377743+0.6828025553841144i,
    0.9539215140976012+0.023655203636735678i, 0.2801101468503475+0.8695263534318656i,
    0.29933327389881015+0.3195536034181714i, 0.30095170880667865+0.9411114864051342i,
    0.8481270638294518+0.7533461293205619i, 0.5382440872490406+0.408481381367892i,
    0.5887787867093578-0.660960757815612i, -0.36029656328916926+0.9637782408838971i,
    -0.5114154749013582+0.3702589613008757i, 0.1647032537618629+0.7256163305336504i,
    -0.0372402546642836+1.3565299862299818i, 0.02029808827189561+0.3318197579960816i,
    -0.07181585214293751+0.8141041793603297i, -0.27955962811207113-0.18661678772092516i,
    -0.5217617218300745+0.5093384808406902i, -0.36522917685067036+0.328443506630541i,
    0.5375964757100721+0.21560836214896115i, 0.04072690048720614+0.114675435420702i,
    0.7967784648238585-0.1554696487128928i, 0.5221397726905066-0.304143194793145i,
    0.06017381278019468+0.4083474878070691i, 0.921242410385053+0.10556615227072769i,
    0.08564315536545733-0.14041959020272143i, 0.5103054281341836+0.24671137962231474i,
    0.2581136553399429+0.3945674745797587i, 0.8320539240463634+0.02741298245049776i,
    0.621213716587266-0.2725896586002249i, 0.44131476301667744-0.27156341978899634i,
    0.3305887657815168+0.14781258927062543i, -0.9375522977562067-0.395272142887653i,
    -0.8535230127941226+0.3127469078910712i, -0.6735092107539964-0.46005644718649563i,
    -0.3309459858645592-0.3197054561902982i, 0.2627549150900881+0.0320431799410025i,
    -0.476284580813855-0.33551727405233783i, 0.31971890430338423+0.384948803703922i,
    0.34785155416727565+0.011236549779313973i, 0.28307450698291703-0.6106930747802172i,
    0.5891968221034155-0.6009401784679198i, -0.297453561245923-0.8128937127117087i,
    -1.697259926291797-0.9677419868954813i, 0.2322249623432409-0.15667613528951274i,
    -0.045944674457310375-0.6185010240361966i, 0.5710116955513285-0.06046962474378073i,
    -0.542186892449857-1.286915397579707i, -0.39791317898343914+1.1240810877040661i,
    0.26021001181657305+0.13397427368029977i, 0.6267564229246987-0.37519845129898827i,
    0.8374523030368848+0.4482761158274526i, 0.3598873038744608-0.01402196516500675i,
    0.21393666141794063+0.6494528131393139i, -0.4238586627504376-0.8092858569742589i,
    -0.6355400962590033+0.3394606419544073i, 0.44522112387310664-0.43712515252598194i,
    0.14707092420029233-0.4296990032180824i, 0.729803368538648-0.9255352226347188i,
    0.49329142723409747-0.5467339399605644i, 0.6936358511065944-0.47633289122280675i,
    -0.0633514064120256+0.015463975070694549i, 0.8365425670641328+0.10144249060397746i,
    -0.10987955609136442+0.08123032922515674i, -0.7714808496088469-0.03000449865554901i,
    -0.8238982873294294-0.08118547589965613i, 0.1646112383984672-0.60440463820563i,
    -0.11979252062771331-0.20314869925686316i, 0.5112882028548895-0.6111075312621986i,
    0.43111270343794184+0.14018355040810873i, -0.031447967689723653-0.05854578489410748i,
    -0.002971292290471487-0.32975631184019105i, -0.3802070423447102+0.25587297977108986i,
    -0.03485210068777844-0.6556518740565489i, -0.4197014665296831-0.3255642996284732i,
    0.1398316927646295-0.1556622110172615i, 1.1793124517690596+0.2583843085229873i,
    0.8131465882086126-0.8553163257218589i, 0.19966911352474365+0.3750560769911183i,
    0.41863381273182443+0.1305569507667894i, 0.4785033203048612-0.42347463110349964i,
    0.21839984477856325-0.04884423266024565i, -0.15215660127940006-0.40148889612465993i,
    0.4513197332272998-0.03584753519141067i, -0.07252945391698302+0.725100936280662i,
    -0.2840618560169887-0.7759997871294216i, 0.4540308531118998-0.5005177578917994