As I understand it, you asked 'in language independent way, how do you do matrix creation and transforms given a list or one dimensional arrays as inputs' essentially.
In general, most languages implement arrays and n dimension arrays as easy-to-use substitutes for pointers. You create the matrix by stepping through the pointers represented by the arrays, create a new element that is the result of the desired transform (multiplication as your example) and create a new n dimensional matrix that is the result of that transform. Some languages (C, Pascal) you have to manage the memory allocated to the matrix. Others (Perl, Python, Awk, C++ somewhat) will create and manage the matrix memory on the fly.
If I use an array in Perl, for example:
$i=4;
$array[$i] = 100; # human readable form for ${$ref_to_array}[offset].
$ref_to_array = \@array # ref to the array
print "${$ref_to_array}[$i]\n" # that array, element $i
In C, the same is:
#include <stdio.h>
int array[] = {1,2,3,4,100}; /* const array to avoid malloc for memory */
int *ptr;
int main(void)
{
ptr = &array[0]; /* point to the first element of the array */
int i=4; /* the offset of 100 */
printf("array[%d]=%d\n", i, array[i]); /* prints 100 */
printf("ptr+%d=%d\n", i, *(ptr+i)) ; /* prints 100 */
return 0;
}
Each language would be different for how you build a matrix from those inputs, even though C and Perl are similar.
In Perl, here is a matrix multiply:
#!/usr/bin/perl
use strict;
use warnings;
sub foo {
my @rtr;
my ($refa, $refb)=@_;
for(my $i=0; $i<=$#{$refa}; $i++) {
for(my $j=0; $j<=$#{$refb}; $j++) {
$rtr[$i][$j]=$refa->[$i] * $refb->[$j];
}
}
return \@rtr;
}
my @onea = (1, 2, 3);
my @oneb = (4, 5, 6);
my $rtr_ref=foo(\@onea,\@oneb);
for(my $i=0; $i<=$#{$rtr_ref}; $i++) {
for(my $j=0; $j<=$#{@{$rtr_ref}[$i]}; $j++) {
print "$rtr_ref->[$i][$j] ";
}
print "\n";
}
Output:
4 5 6
8 10 12
12 15 18
In C, the algorithm is nearly the same, but all the pointer reference and dereferences are different.
In conclusion -- there are problems doing this in a "language independent way" The pointer reference and dereference is different. The memory management is different.
So choose your language then focus on the matrix. For Perl, look at PDL, for C look at GSL