Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seq(from, to, numberOfPoints) #1

Closed
arcolombo opened this issue May 28, 2016 · 6 comments
Closed

seq(from, to, numberOfPoints) #1

arcolombo opened this issue May 28, 2016 · 6 comments

Comments

@arcolombo
Copy link

arcolombo commented May 28, 2016

Here is a handy function that doesn't restrict itself to integers, but is very similar to the R base::seq function, which is seq(from, to, numberofPoints). In this case, this is used to create sequences from -x0 to x1 by 2*x0/(numberofPoints)

arma::vec seq_cpp(double a, double np){
  double inc  = (2*a)/np;

  arma::vec s(np);

  for(unsigned int i = 0; i < np; i++){
    s(i) = -a + i*inc;
  }

  return s;
}
@arcolombo
Copy link
Author

If it is preferable to submit a formal Pull Request, then I could....

@coatless
Copy link
Collaborator

Hi @arcolombo, please do so! This will be a great addition. Thanks.

@arcolombo
Copy link
Author

ok to close this out.

@arcolombo
Copy link
Author

arcolombo commented May 29, 2016

I'm honestly way too lazy to send a pull request, but here it is with armadillo library

arma::vec seq_by(long double a, long double np){

arma::vec s(np);
s = arma::linspace(-a,a,np); 


  return s;
  }

@arcolombo
Copy link
Author

prolly not even needed after reading through Arma docs...

@coatless
Copy link
Collaborator

@arcolombo

You would be amazed.

This is actual a great example of using linspace in Armadillo's API.

I'll bring it into the seq set of functions later today. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants