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

Add reverse for vectors. #479

Closed
wants to merge 3 commits into from
Closed

Conversation

ghost
Copy link

@ghost ghost commented Jan 25, 2017

Submisison Checklist

  • Run unit tests: ./runTests.py test/unit
  • Run cpplint: make cpplint
  • Declare copyright holder and open-source license: see below

Summary:

Just a quick resolution of #344 adding a reverse utility for std::vectors. Like our sort functions, it mutates its argument. We ok with that?

Intended Effect:

Add a missing minor feature.

How to Verify:

Code is short and there's a unit test.

Side Effects:

None, adds a function.

Documentation:

doxygen

Reviewer Suggestions:

Copyright and Licensing

Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company): Columbia University

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:

@bob-carpenter
Copy link
Contributor

Three things:

  1. It needs to be a constant reference, which is how arguments are passed in from the Stan language. So it needs a copy.

  2. It also needs tests for reverse, forward, and mixed modes. That'll just test that the appropriate comparisons are defined for std::reverse to apply to the iterators.

  3. It should be implemented for row vectors and column vector types, too. If you take an ordered vector, it's an Eigen vector, and that's the kind of thing we'll have users reversing.

@ghost
Copy link
Author

ghost commented Jan 26, 2017

@bob-carpenter I hopefully fixed the const issue and am proceeding to the rest, I'm curious whether there are any good examples of of functions from vector to vector already in the language? I'm looking at fun/sum (in prim, rev, fwd), the autodiff paper, and a few other places but if there's an idiom it'd be nice to match

Also: I'm intending to put a little bit of noise on this pull request. Is there a nice way to avoid triggering CI builds on intermediate pushes?

@syclik
Copy link
Member

syclik commented Jan 27, 2017 via email

@jgabry
Copy link
Member

jgabry commented Jan 27, 2017 via email

@seantalts
Copy link
Member

I've just been killing off the builds that I know I've triggered if I have updates to the PR that makes running those tests obsolete.

@bob-carpenter
Copy link
Contributor

bob-carpenter commented Jan 27, 2017 via email

@bob-carpenter
Copy link
Contributor

bob-carpenter commented Jan 27, 2017 via email

@bob-carpenter
Copy link
Contributor

jenkins, retest this please

@bob-carpenter
Copy link
Contributor

I shouldn't have just kicked off retesting. Looks like the reverse file isn't including the header for std::begin and std::end.

@ghost
Copy link
Author

ghost commented Jan 27, 2017

@bob-carpenter it wasn't using it because I shouldn't have had it there. pushing a micro-change this time just to see the [ci skip] in action

EXPECT_FLOAT_EQ(y[0], 3.3);
EXPECT_FLOAT_EQ(y[1], 2.2);
EXPECT_FLOAT_EQ(y[2], 9);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reverse function looks good now. But the pull request still needs rev and fwd autodiff tests just to make sure that everything needed by std::reverse_copy is available for the autodiff classes.

@bob-carpenter
Copy link
Contributor

Was this all ready for final review?

@bob-carpenter
Copy link
Contributor

@thelseraphim Would you mind adding the autodiff tests for this? Just one for fwd, one for rev, and one for rev nested in fwd (three test files in rev, fwd, and mix directories).

@syclik
Copy link
Member

syclik commented Apr 20, 2017

@thelseraphim mind finishing out this pull request?

@syclik syclik deleted the feature/issue-344-reverse-vectors branch September 15, 2022 14:13
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

Successfully merging this pull request may close these issues.

None yet

4 participants