chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.78k stars 418 forks source link

Support shared domains for multiple series with push_back() #7144

Open buddha314 opened 7 years ago

buddha314 commented 7 years ago

Here is the use case.

I have a domain. Here, just integers but think dates.

var dates: domain(1) = {Jan 1 1970, Jan 2 1970... May 24, 2006}  // as integers
var tea_price: [dates] real;
var temperature: [dates] int;

If I only have tea_price then I can do tea_price.push_back(4.5) and it expands dates by one. However, with both tea_price and temperature I can't use push_back(). I think this would be useful

var today = dates.add(new_date) // <-- have it return the new date so I can do
// OR
var today = dates.push_back(new_date);
tea_price[today] = 4.8;
temperature[today] = 75 and Sunny.  // Wait, not an int... :)

At the moment, I can only think of

dates = {1..dates.size+1};  // U G L Y you ain't got no alibi...

This could be extremely helpful for time series analysis. In this way, a domain is a sort of external index to multiple collections rather than an array of things. I am probably thinking of this the wrong way, but I figured I'd ask...

benharsh commented 7 years ago

Some historical context: Our original thinking with push_back was to restrict the functionality to domains with only one array because it might be surprising to users if calling push_back on one array changed the elements of some unrelated array elsewhere.

@bradcray : do you have any thoughts on how we could make this pattern more elegant?

buddha314 commented 7 years ago

Honestly, that makes sense to me. I'm wondering if we can't (a) create an operator on the domain itself that increases it by a given amount and (b) returns the new indices for quick population.

To illustrate (a)

tea_prices.push_back(4.8);  // affects temperature and causes a surprise, so ERROR (?)
dates.push_back("2006-04-24"); // affects both tea_prices and temperature as an index, 
                                                       // but both are in sync so no surprise, operating at index

To illustrate (b), now I want to use that new date for the price/temp.

var today = dates.push_back("2006-04-24");
tea_price[today] = 4.8;

I don't know if this breaks thinking, but it seems useful.

bradcray commented 7 years ago

@bradcray : do you have any thoughts on how we could make this pattern more elegant?

The main thing that comes to mind for me would be a variation on push_back and friends that could be called on a tuple of arrays, providing a new element per array. So imagine:

(dates, tea_price).push_back(("2006-04-24", 4.8));