Create a domain with matrices in the Chapel

I have a domain Dand I want to use it to index multiple matrices A. Something like form

var dom: domain(1) = {0..5};
var mats: [dom] <?>;

var a0 = [[0.0, 0.1, 0.2], [0.3, 0.4, 0.5]];
var a1 = [[1.0, 1.1, 1.2, 1.3], [1.4, 1.5, 1.6, 1.7]];

mats[0] = a0;
mats[1] = a1;

Each Awill be 2D, but has different sizes. Yes, some of them will be scarce (but not necessary for this question)

== UPDATE ==

For clarity, I have a series of layers (this is a neural network), say 1..15. I created var layerDom = {1..15} Each layer has several objects associated with it, such as an error, so I

var errors: [layerDom] real;  // Just a number

And I would like to have

var Ws: [layerDom] <matrixy thingy>;  // Weight matrices all of different shape.
+2
source share
1 answer

Chapel 1.15, , . , , , .

, /, :

record Weight {
  var D : domain(2);
  var A : [D] real;
}

var layers = 4;
var weights : [1..layers] Weight;
for i in 1..layers {
  weights[i].D = {1..i, 1..i};
  weights[i].A = i;
}

for w in weights do writeln(w.A, "\n");

// 1.0
// 
// 2.0 2.0
// 2.0 2.0
// 
// 3.0 3.0 3.0
// 3.0 3.0 3.0
// 3.0 3.0 3.0
// 
// 4.0 4.0 4.0 4.0
// 4.0 4.0 4.0 4.0
// 4.0 4.0 4.0 4.0
// 4.0 4.0 4.0 4.0
// 
+2

Source: https://habr.com/ru/post/1690578/


All Articles