Deconvolution/2D+: Difference between revisions
m
→{{header|Raku}}: sync rref/trim-system with other tasks, general tidying
m (→{{header|Phix}}: added syntax colouring the hard way) |
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: sync rref/trim-system with other tasks, general tidying) |
||
Line 1,748:
=={{header|Raku}}==
(formerly Perl 6)
Translation of Tcl.
Line 1,764 ⟶ 1,763:
@h.AT-POS(|$_) = $v;
}
}
Line 1,775 ⟶ 1,774:
for ^@hc -> $i {
my $window = @gcoord[$i] - @hc[$i];
@fcoord.push($window) and next if 0
last;
}
Line 1,781 ⟶ 1,780:
}
@row.push: @g.AT-POS(|@gcoord);
}
# Constructs an AoA of coordinates to all elements of N dimensional array
sub coords ( @dim ) {
@[reverse $_ for [X] ([^$_] for reverse @dim)]
}
Line 1,792 ⟶ 1,791:
# Can handle over-specified systems (N unknowns in N + M equations)
sub rref (@m) {
my ($lead, $rows, $cols) = 0,
}▼
for ^$rows -> $r {
return @m unless $lead < $cols
my $i = $r;
until @m[$i;$lead] {
next unless ++$i == $rows
$i = $r;
return @m if ++$lead == $cols
}
@m[$i, $r] = @m[$r, $i] if $r != $i;
for ^$rows -> $n {
next if $n == $r;
@m[$n] »-=» @m[$r] »
}
++$lead;
}
}
return @m
my (\vars, @t) =
for
@t.append: @m.splice(row, 1) and last if @m[row;lead];
}
while (+@t < $vars) and +$m { @t.push: $m.splice(0, 1) };▼
}
}
# Pretty printer for N dimensional arrays
# Assumes if first element in level is an array, then all are
sub
if @array[0] ~~ Array {
say ' ' x $indent,"[";
say ' ' x $indent, "]{$indent??','!!''}";
} else {
Line 1,892 ⟶ 1,884:
my @h = deconvolve-N( @g, @f );
say "h =";
my @h-shaped[2;3;4] = @(deconvolve-N( @g, @f ));
my @ff = deconvolve-N( @g, @h-shaped );
say "\nff =";
Output:
|