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

Fix #3076 - make openstudio::Vector "Enumerable" in ruby #3989

Merged
merged 3 commits into from
Aug 7, 2020

Conversation

jmarrec
Copy link
Collaborator

@jmarrec jmarrec commented Jun 2, 2020

Pull request overview

NOTE: just because you can use the << to append to an openstudio::Vector doesn't mean you should in all cases, as it will resize the vector each time. It's much more efficient to do os_vec = OpenStudio::Vector.new(size) then fill it.

Demo:

[1] (main)> os_vec = OpenStudio::createVector([0,1,2,3,4,5,6,7,8,9])
=> #<OpenStudio::Vector:0x00005619d21645d0 @__swigtype__="_p_openstudio__Vector">
[2] (main)> os_vec << 11
=> nil
[3] (main)> os_vec.map{|x| x}
=> [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 11.0]
[4] (main)> os_vec.size
=> 11
[5] (main)> os_vec.map!{|x| x**2}
=> #<OpenStudio::Vector:0x00005619d2223d18 @__swigtype__="_p_openstudio__Vector">
[6] (main)> os_vec.map{|x| x}
=> [0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0, 81.0, 121.0]
[7] (main)> os_vec = OpenStudio::createVector([0,1,2,3,4,5,6,7,8,9])
=> #<OpenStudio::Vector:0x00005619d2284af0 @__swigtype__="_p_openstudio__Vector">
[8] (main)> os_vec.map{|x| x}
=> [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
[9] (main)> os_vec.map!{|x| x+2}
=> #<OpenStudio::Vector:0x00005619d22e8550 @__swigtype__="_p_openstudio__Vector">
[10] (main)> os_vec.size
=> 10
[11] (main)> os_vec << 0.5
=> nil
[12] (main)> os_vec.size
=> 11
[13] (main)> os_vec.map{|x| x}
=> [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 0.5]
[14] (main)> os_vec.each do |x|
[14] (main)*   puts x
[14] (main)* end  
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
11.0
0.5
=> #<OpenStudio::Vector:0x00005619d2413d08 @__swigtype__="_p_openstudio__Vector">
[15] (main)> os_vec.each_with_index {|x, i| puts x+i}
2.0
4.0
6.0
8.0
10.0
12.0
14.0
16.0
18.0
20.0
10.5

Pull Request Author

Add to this list or remove from it as applicable. This is a simple templated set of guidelines.

  • Model API Changes / Additions
  • Any new or modified fields have been implemented in the EnergyPlus ForwardTranslator (and ReverseTranslator as appropriate)
  • Model API methods are tested (in src/model/test)
  • EnergyPlus ForwardTranslator Tests (in src/energyplus/Test)
  • If a new object or method, added a test in NREL/OpenStudio-resources: Add Link
  • If needed, added VersionTranslation rules for the objects (src/osversion/VersionTranslator.cpp)
  • Checked behavior in OpenStudioApplication, adjusted policies as needed (src/openstudio_lib/library/OpenStudioPolicy.xml)
  • Verified that C# bindings built fine on Windows, partial classes used as needed, etc.
  • All new and existing tests passes
  • If methods have been deprecated, update rest of code to use the new methods

Labels:

  • If change to an IDD file, add the label IDDChange
  • If breaking existing API, add the label APIChange
  • If deemed ready, add label Pull Request - Ready for CI so that CI builds your PR

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • Code Style, strip trailing whitespace, etc.
  • All related changes have been implemented: model changes, model tests, FT changes, FT tests, VersionTranslation, OS App
  • Labeling is ok
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified

@jmarrec jmarrec added component - Utilities Other Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. labels Jun 2, 2020
@jmarrec jmarrec self-assigned this Jun 2, 2020
@jmarrec jmarrec requested review from rHorsey and tijcolem June 2, 2020 10:48
@jmarrec
Copy link
Collaborator Author

jmarrec commented Aug 4, 2020

Anyone to review.?

@ci-commercialbuildings
Copy link
Collaborator

ci-commercialbuildings commented Aug 7, 2020

@tijcolem tijcolem added this to the OpenStudio SDK 3.1.0 milestone Aug 7, 2020
Copy link
Collaborator

@tijcolem tijcolem left a comment

Choose a reason for hiding this comment

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

Looks good to me and CI is happy.

@tijcolem tijcolem merged commit a5d05d3 into develop Aug 7, 2020
@tijcolem tijcolem deleted the 3076_EnumerableVector branch August 7, 2020 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component - Utilities Other Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenStudio::Vector when SWIG'ed into ruby is not enumerable
3 participants