- 
                Notifications
    
You must be signed in to change notification settings  - Fork 134
 
[Woking in Progress] Standarize code #627
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
base: master
Are you sure you want to change the base?
[Woking in Progress] Standarize code #627
Conversation
dde1123    to
    9a8c821      
    Compare
  
    9a8c821    to
    86e568d      
    Compare
  
    f44f2c7    to
    17bc088      
    Compare
  
    48ae7fd    to
    fb504a0      
    Compare
  
    | ['nmatrix_config.h', '$(archdir)'], | ||
| ['nm_memory.h' , '$(archdir)'], | ||
| ['ruby_constants.h', '$(archdir)'] | ||
| ["nmatrix.h", "$(archdir)"], | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should leave the single quote, because the double quote is use when you want to do an interpolation. WDYT? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Standard gem decides to use "double quotes" then we use "double quotes".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok 👍
| Dir.mkdir("data") unless Dir.exists?("data") | ||
| Dir.mkdir("util") unless Dir.exists?("util") | ||
| Dir.mkdir("storage") unless Dir.exists?("storage") | ||
| Dir.mkdir("data") unless Dir.exist?("data") | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
directories = %w(data util storage yale list dense)
# if a directory not exist, it is create
directories.each do |directory|
  Dir.mkdir(directory) unless Dir.exist?(directory)
endWDYT? 🤔
| raise(ArgumentError, 'Expected dense NMatrices as first two arguments.') \ | ||
| unless a.is_a?(NMatrix) and b.is_a? \ | ||
| (NMatrix) and a.stype == :dense and b.stype == :dense | ||
| raise(ArgumentError, "Expected dense NMatrices as first two arguments.") \ | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could separate these validations into multiple functions to make this function more readable:
def gemm(.....)
  ...
  validate_argument?(a)
  validate_argument?(b)
  ...
end
private
def validate_argument(matrix)
  nmatrix?(matrix) && dense_stype?(matrix)
end
def nmatrix?(matrix)
  message = 'Expected NMatrices object as first two arguments.'
  raise(ArgumentError, message) unless matrix.is_a?(NMatrix)
end
def dense_stype?(matrix)
  message = 'Expected dense NMatrices as first two arguments.'
  raise(ArgumentError, message) unless (matrix.stype == :dense) 
endWDYT? 🤔
| 
           This is why a project has to maintain maximum consistency. Ruby is very flexible but this can negatively affect productivity, It does not seem to really necessary to write code like this.  | 
    
Why this pull request?
✔️ Readability
✔️ Maintainability
✔️ Consistent syntax
✔️ More secure (because it helps to prevent usually bad practices)
Todo
standardgem (including it toRakefilealso)standard.ymltravis.ymlbundle exec rake standardin thescriptsectionbundle exec rake standard:fixFix this ones manually