Sparse Slicing of Sparse Arrays in Chapel
Given some A: [sps]
over a sparse subdomain of a dom: domain(2)
, a slice A[A.domain.dim(1), k]
yields the kth column as a dense 1Darray. How do I retrieve the kth n−1 dimensional slice of a sparse nDarray as a sparse (n1)Darray?
var nv: int = 8,
D: domain(2) = {1..nv, 1..nv},
SD: sparse subdomain(D),
X: [SD] real;
SD += (1,2); X[1,2] = 1;
SD += (2,3); X[2,3] = 1;
SD += (3,1); X[3,1] = 1;
SD += (3,4); X[3,4] = 1;
SD += (4,5); X[4,5] = 1;
SD += (3,6); X[3,6] = 1;
SD += (6,8); X[6,8] = 1;
writeln(X);
writeln(X[X.domain.dim(1),2]);
returns
1.0
1.0
1.0 1.0 1.0
1.0
1.0
1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
The expectation in the case that I succeed in sparse slicing would be a single 1.0
returned with the ability to retrieve this position of that entry by calling writeln()
on slice.domain
.
1 answer

I think that, unfortunately, you are doing the right sort of thing and that you're just running afoul of the current (as of Chapel 1.16) limitations with respect to slicing sparse domains.
See also questions close to this topic

cannot access php json decoded multi dimensional array values curl
when i execute the below code to access koinex ticker api , I am getting an array but how can i display only certain values :
echo $response[0][0][1]; echo $response['prices']['BTC'][0];
code :
<?php $getCurrency = "inr"; $displayArrayOutput = true; // Get cURL resource $curl = curl_init(); // Set some options  we are passing in a useragent too here curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => 'https://koinex.in/api/ticker', CURLOPT_USERAGENT => 'Something here' )); // Send the request & save response to $resp $response = curl_exec($curl); // Close request to clear up some resources $err = curl_error($curl); curl_close($curl); if ($err) { } else { if($displayArrayOutput){ $response = json_decode($response, true); print_r($response); } else{ header("Contenttype:application/json"); echo 'touine'; } } echo $response[0][0][1]; echo $response['prices']['BTC'][0]; ?>
sorry a little new to php , open to any other kind of approach for decoding json

How to do a subtraction between &ndarray::Array1<f64> and &mut Array1<f64>?
I find it impossible to do a subtraction between an immutable array reference and a mutable one using the ndarray crate:
let a: &Array1<f64> = &array![3.0, 2.0, 1.0]; let b: &mut Array1<f64> = &mut array![1.0, 1.0, 1.0]; let c = a  &b.view(); // This compiles let d = a  b; // This fails to compile
The error message I get is:
let c = a  b; ^ no implementation for `f64  &mut ndarray::ArrayBase<ndarray::OwnedRepr<f64>, ndarray::Dim<[usize; 1]>>`
I don't understand what these two types mean, but is there any special reason why this is not implemented?

I do not know why it is showing error in passing multidimensional array
I had been trying to find out the reason why this error is happening but found out nothing. This is the code for nqueen problem from backtracking. But this doesn't matter. I want to find out why this error is occurring and how to resolve it.
#include <iostream> using namespace std; bool attack_checking(int arr[][s], int s, int i, int j) { for(int x = 0; x < s; x++) if(arr[i][x] == 1) return true; for(int x = 0; x < s; x++) if(arr[x][j] == 1) return true; for(int x = 0; x < s; x++) { for(int y = 0; y < s; y++) { if(x == i && y == j) continue; if((x + y) == (i + j)) { if(arr[x][y] == 1) return true; } if((x  y) == (i  j)) { if(arr[x][y] == 1) return true; } } } return false; } bool queen(int arr[][s], int s, int n) { if(n == 0) return true; for(int i = 0; i < s; i++) { for(int j = 0; j < s; j++) { if(attack_checking(arr, s, i, j)) continue; arr[i][j] = 1; if(queen(arr, s, n  1)) return true; arr[i][j] = 0; } } return false; } int main() { int n, s; cin>>n; s = n; int arr[s][s]; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) arr[i][j] = 0; bool ans = queen(arr, s, n); if(ans) { cout<<"YES\n"; for(int i = 0; i<n; i++){ for(int j = 0; j<n; j++){ cout<<arr[i][j]<<" "; } cout<<"\n"; } } cout<<"NO"; return 0; }
new.C:5:32: error: use of undeclared identifier 's' bool attack_checking(int arr[][s], int s, int i, int j) { ^
new.C:32:22: error: use of undeclared identifier 's'
bool queen(int arr[][s], int l) { ^
2 errors generated.

Is there a way to get slice as result of Find()?
Now I'm doing:
sess := mongodb.DB("mybase").C("mycollection") var users []struct { Username string `bson:"username"` } err = sess.Find(nil).Select(bson.M{"username": 1, "_id": 0}).All(&users) if err != nil { fmt.Println(err) } var myUsers []string for _, user := range users{ myUsers = append(myUsers, user.Username) }
Is there a more effective way to get slice with usernames from Find (or another search function) directly, without struct and range loop?

How to slice a np.array using a list of unknown length?
I am probably using the wrong names/notation (and an answer probably exists on SO, but I can't find it). Please help me clarify so that I can update the post, and help people like me in the future.
I have an array
A
of unknown dimensionn
, and a list of indexes of unknown lengthl
, wherel<=n
.I want to be able to select the slice of
A
that correspond to the indexes inl
. I.e I want:A = np.zeros([3,4,5]) idx = [1,3] B = # general command I am looking for B_bad = A[idx] # shape = (2,4,5), not what I want! B_manual = A[idx[0], idx[1]] # shape = (5), what I want, but as a general expression. # it is okay that the indexes are in order i.e. 0, 1, 2, ...

How can I slice a list till end with negative indexes
I learned that Python lists can also be traversed using negative index, so I tried to slice/sublist a list using negative index, but I cannot slice it till end.
My list is:
areas = ["hallway", 11.25, "kitchen", 18.0, "living room", 20.0, "bedroom", 10.75, "bathroom", 9.50]
Knowing that slicing syntax is
[start:end]
and end index is not calculated, I didupstairs = areas[4:0]
but this doesn't give me last element of the list. 
Calculating RMSE and MAE of Matrix Factorization recommender
I have a Pandas Dataframe that contains the predictions of user ratings for movies. I am using the MovieLens 1m dataset. I want to know how I can get the accuracy of my predictions using RMSE and MAE. I've tried splitting the original dataset and using 80% to perform my predictions and 20% to compare using RMSE however I get a value of around .62. This seems very low.

Python 3.6.x: Efficient construction of matrix entries
Using Python 3.6.x, I would like to construct a sparse matrix in the most efficient way possible. I currently do this using two nested loops, but I wonder if there is a more efficient way to do it? Small efficiency gains mean a lot to me because I will need to construct matrices containing a subset of the rows of the full matrix millions of times.
Inputs
 Take as given input set Beta = [beta_1, beta_2, ..., beta_{N_Beta}], which has N_B entries.
 Take as given input set Theta = [theta_1, theta_2, ..., theta_{N_Theta}], which has N_T entries.
 Take as given input scalar d.
 Define N = N_Beta*N_Theta as the total number of combinations between entries in sets Beta and Theta, and assign to each i = 1, 2, ..., N_Theta, N_Theta + 1, N_Theta + 2, ..., N the combination (beta_1,theta_1), (beta_1,theta_2), ..., (beta_1,theta_{N_Theta}), (beta_2,theta_1), (beta_2,theta_2), ..., (beta_{N_Beta},theta_{N_Theta}).
Desired output
In words, here is how the matrix can be constructed:
 Start with a zero matrix
 Fix first an item in Beta and rotate through all items in Theta, then switch to the next item in Beta etc.
 For each (beta_i, theta_j) combination, insert a new row with the vector [1, beta_i*delta, theta_j] in entries (3(i  1) + 1, 3(i  1) + 2, 3(i  1) + 3); and the vector [1, beta_i delta, theta_j] in entries (3(j  1) + 1, 3(j  1) + 2, 3(j  1) + 3).
I am currently building this matrix through two nested loops, following closely the description in the above "pseudo code" bullets. Can you think of a more efficient method for constructing this matrix? Thank you very much in advance.
PS: If you can find an easy way to drop the zero row entries of the matrix, that would be ideal. I have done this so far in my two nested loops.

Fill scipy sparse.coo_matrix by for loop
I want to iteratively fill a scipy sparse coo_matrix
# Constructing an empty matrix import numpy as np from scipy.sparse import coo_matrix m = coo_matrix((3, 4), dtype=np.int8)
by a for loop and some rules, e.g. all ones (I know there's a constructor with data but I can't use it since the rule is more complex). How can I do that? I haven't found any documentation about it.

Sparse Iteration in Chapel
Given an array
M:[sps]
over asps = sparse subdomain(dom)
wheredom: domain(n)
, I know I can iterate densely over the kth dimension withfor j in M.domain.dim(k) {...}
. How would I define an analogous loop that visits only populated locations in k such that ifM.domain.dim(k) = {1..N}
, but there are only m populated indices in k, the loop only formally generates m iterations rather than N?Would the way to do this be to iterate over the whole sparse domain with an iterand that only references one index? (i.e.
for (i,j) in spsDom { var idx = i }
) 
How to prevent multiple executables from running at the same time on cluster
I have submitted a job to a multicore cluster with LSF platform. It looks like the code at the end. The two executables, exec1 and exec2, start at the same time. In my intention they are separated by a column comma and the second should start after the first has finished. Of course, this caused several problems with the job that couldn't terminate correctly. Now that I have figured out this behavior, I am writing separated jobsubmission files for each executable. Can anybody explain why these executables are running at the same time?
#!/bin/bash l # # Batch script for bash users # #BSUB L /bin/bash #BSUB n 10 #BSUB J jobname #BSUB oo output.log #BSUB eo error.log #BSUB q queue #BSUB P project #BSUB R "span[hosts=1]" #BSUB W 4:0 source /etc/profile.d/modules.sh module purge module load intel_comp/c4/2013.0.028 module load hdf5/1.8.9 module load platform_mpi/8.2.1 export OMP_NUM_THREADS=1 export MP_TASK_AFFINITY=core:$OMP_NUM_THREADS OPT="aff=automatic:latency" mpirun $OPT exec1; mpirun $OPT exec2

How to use the `writeThis()` construct in Chapel
I have a class in Chapel, and I want to let it control it's own print statement. So for instance
class Noob { var name: string, experience:int; // constructor }
Later, I want to do something like
me = new Noob('brian', 0) writeln(me) > Hi, my name is Brian and I have 0 years experience
It looks like this should help, but I can't quite get the
readThis()
method to work. 
How do I format strings output in Chapel?
When I'm printing numbers with Chapel's Formatted I/O I can set the length of numbers with something like
writeln("my number is %{#.###}", 3.14159)
I want to something similar with strings, but I don't see an example on the page. Basically, I'd like the string to line up in nice columns.

On the Subtleties of Sparseness in Chapel
Given a dense domain
dom: domain(n);
where n < 3, the declarationsps1: sparse subdomain(dom);
yields a sparse subdomainsps1
ofdom
. Withsps1
the usual array/matrix slicing is possible. That is, given a matrixA: [sps1]
one can take n  1 dimensional slices ofA
. However, the usual matrix operationtranspose()
is not applicable.Defining a second matrix
B:[sps2]
over another sparse subdomainsps2 = CSRDomain(dom)
enables one to taketranspose()
s ofB
, but the ability to slice intoB
is forfeit.Both of these abilities would seem to be that which one should always have access to. Is there a better way to declare sparse subdomains that preserves the two?