Open Side Menu Go to the Top

12-13-2015 , 06:13 PM
I understand how it works. It just seems unnecessarily obtuse to me, and error prone if someone else gets their hand on the code.

If this is a very standard pattern then fine. But I really try to avoid code that does non-obvious things, for better maintainability.
Programming homework and newbie help thread Quote
Programming homework and newbie help thread
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
Programming homework and newbie help thread
12-13-2015 , 06:51 PM
To my knowledge there aren't any modern languages that don't have short-circuiting operators, and using the non-short-circuit ones is really bad practice. That evaluation will short-circuit falls into the category of "obvious" for me, like it's as obvious that that will happen as it is that code after a return statement will not execute.
Programming homework and newbie help thread Quote
12-13-2015 , 06:57 PM
By the way Noodle Wazlib, many languages, including Ruby, have non-short-circuiting (or "eager") versions of boolean operators, like this:

Code:
if x == true | y == true
With the single-pipe OR, both expressions will be evaluated. HOWEVER, actually using this for any purpose would be a death penalty offence in a just world.

The | and & operators are more usually encountered for performing bitwise OR or AND operations on integers/chars/bytes etc.
Programming homework and newbie help thread Quote
12-14-2015 , 03:51 AM
Quote:
Originally Posted by Wolfram
I understand how it works. It just seems unnecessarily obtuse to me, and error prone if someone else gets their hand on the code.

If this is a very standard pattern then fine. But I really try to avoid code that does non-obvious things, for better maintainability.
I'm completely with you regarding the latter part.

It's just the opinion on whether that is maintainable/obvious/readable or not that our opinions differ. And that is perfectly fine, too. I've hardly ever had the urge to smack someone for having their code be too obvious.
Programming homework and newbie help thread Quote
12-14-2015 , 01:40 PM
[IMG][/IMG]

Hi friends,
suppose if i want to do distributed programming(C and OpenMPI) to speed up the d2Q9 lbm which simulates fluid dynamics, and my input looks like the above(where the coloured bits do a lot of work and the black bit does little to 0 work), what is a sensible way to partition my problem?

since i'm doing stencil stuff i guess i can't get around doing a halo exchange,and i know i can get away with chopping off the top and bottom section of the grid(i.e i don't have to do computation on the black parts) but how should I divide the work load in the middle?(in to 4 pieces), neither row-wise nor column wise seem to be able to achieve a balanced work load, is there something clever that i can do?
Programming homework and newbie help thread Quote
12-14-2015 , 06:24 PM
Quote:
Originally Posted by kazana
To use your example, look at something like this:


Code:
if ( myThing == null || myThing->isNotValid() )
    return ERR;
Sure, you could split that up into 4 lines instead of two to remove relying on eval order, but seems bloaty for a pretty simple check.
So, if the exit/continuation would look the same, it is fine to rely on evaluation order.
Well in C++ if myThing is a an input parameter it should be defined as a reference since references can't be NULL by definition. The preferred way to do the above if it is a pointer:

Code:
if (!myThing || myThing->isNotValid() )
    return ERR;
Programming homework and newbie help thread Quote
12-14-2015 , 06:37 PM
Quote:
Originally Posted by CyberShark93
[IMG][/IMG]

Hi friends,
suppose if i want to do distributed programming(C and OpenMPI) to speed up the d2Q9 lbm which simulates fluid dynamics, and my input looks like the above(where the coloured bits do a lot of work and the black bit does little to 0 work), what is a sensible way to partition my problem?

since i'm doing stencil stuff i guess i can't get around doing a halo exchange,and i know i can get away with chopping off the top and bottom section of the grid(i.e i don't have to do computation on the black parts) but how should I divide the work load in the middle?(in to 4 pieces), neither row-wise nor column wise seem to be able to achieve a balanced work load, is there something clever that i can do?
I don't know the math behind this so hard to say other than you probably can do calculations in parallel. Interesting problem.
Programming homework and newbie help thread Quote
12-16-2015 , 12:59 AM
Quote:
Originally Posted by CyberShark93
[IMG][/IMG]

Hi friends,
suppose if i want to do distributed programming(C and OpenMPI) to speed up the d2Q9 lbm which simulates fluid dynamics, and my input looks like the above(where the coloured bits do a lot of work and the black bit does little to 0 work), what is a sensible way to partition my problem?

since i'm doing stencil stuff i guess i can't get around doing a halo exchange,and i know i can get away with chopping off the top and bottom section of the grid(i.e i don't have to do computation on the black parts) but how should I divide the work load in the middle?(in to 4 pieces), neither row-wise nor column wise seem to be able to achieve a balanced work load, is there something clever that i can do?
Hi friends,
I now have implemented a version which works and its correct, however its really slow, I have a few ideas to improve performance but i want to check it through u guys and see if it makes sense before commiting to anything

in my implementation i divided the work among processes by column, would a row-wise decomposition work better? its more of a memory coalescence thing, since i'm performing computation on each cell row by row.

also, say I have to do 8000 time steps, is it worth the effort to make my halo twice as big, so that I only have to communicate with other processes once per 2 iterations. what about 4 times as big? 8? since I don't really see people taking this approach, i imagine there is a significant draw back?

oh and final question:
what are some general guidelines to go through when you are looking for performance gain in MPI?
I mean there is work load balancing, try to reduce synchronisation cost,memory coalensence, is there anything else? or any good articles i should read?
Programming homework and newbie help thread Quote
12-17-2015 , 10:32 AM
Anyone here know anything about cryptography?

I'm confused what is meant by the parity of permutation for a block cipher. I checkout out wikipedia, https://en.wikipedia.org/wiki/Parity_of_a_permutation, but don't see how a series of bits fits into the picture. Are the inversions literally just swapping single bits, ie 100 to 010 would be 1 swap and therefore odd? Would this mean a block cipher will never map 100 to 111?

edit:

or is it when you flip bits you consider that a swap?

so 100 to 010 would be 2 swaps and even
100 to 111 would also be 2 swaps and even?
Programming homework and newbie help thread Quote
12-17-2015 , 03:55 PM
Quote:
Originally Posted by fruit snacks
Anyone here know anything about cryptography?

I'm confused what is meant by the parity of permutation for a block cipher. I checkout out wikipedia, https://en.wikipedia.org/wiki/Parity_of_a_permutation, but don't see how a series of bits fits into the picture. Are the inversions literally just swapping single bits, ie 100 to 010 would be 1 swap and therefore odd? Would this mean a block cipher will never map 100 to 111?

edit:

or is it when you flip bits you consider that a swap?

so 100 to 010 would be 2 swaps and even
100 to 111 would also be 2 swaps and even?
Never have worked with this, not sure if this link helps or not Block Cypher and Parity of Permutations
Programming homework and newbie help thread Quote
12-17-2015 , 05:10 PM
To answer my own question, I found that I can achieve the best performance by preprocessing, I kept a record of how many cells are inside the pipe in each row, and I allocate work at run time to try and make sure that each slice of of my grid has roughly the same amount of work, by giving some process more rows to do if the rows they have don't contain enough cells inside the pipe

Made the readability of my code like aids, but was able to speed up my algorithm 1.4times when running 4 processes
Programming homework and newbie help thread Quote
12-17-2015 , 05:47 PM
Quote:
Originally Posted by adios
Never have worked with this, not sure if this link helps or not Block Cypher and Parity of Permutations
I read this before posting here. His answer makes 0 sense to me.

Quote:
they view the n bit cipher (with a specific key) as a permutation on 2^n objects; that is, it can be review as a way of rearranging that set of 2^n objects onto itself.
Like wtf? so 010 is a representation of 8 objects but how do you swap from 010 -> 101? What counts as a swap? It seems arbitrary and weird to even use the word permutation for this.
Programming homework and newbie help thread Quote
12-17-2015 , 06:01 PM
ok, digging a bit deeper I'm pretty sure my initial read of swapping bits was right and it doesn't mean flipping bits. So 010 will never be mapped to 101 but only 100 and 001.

Just seems weird since even a theoretical perfect one of this kind would seem to leak some info about the original contents but I guess thats just how they work.
Programming homework and newbie help thread Quote
12-23-2015 , 05:59 PM
The following is from section 6.4 of the rails' getting started guide

Quote:
Code:
class CommentsController < ApplicationController
  def create
    @article = Article.find(params[:article_id])
    @comment = @article.comments.create(comment_params)
    redirect_to article_path(@article)
  end
 
  private
    def comment_params
      params.require(:comment).permit(:commenter, :body)
    end
end
You'll see a bit more complexity here than you did in the controller for articles. That's a side-effect of the nesting that you've set up. Each request for a comment has to keep track of the article to which the comment is attached, thus the initial call to the find method of the Article model to get the article in question.
If I'm understanding this correctly, it's a lot more of what some of my professors refer to as actual object oriented programming: in other words, objects interacting with other objects. Yes?

I'm one semester away from a 2 year diploma and it seems like this is really the first sort of thing I've come across that actually had objects interacting in any meaningful way.

Not sure I have a point, just wanting to check to make sure I'm looking at this correctly, or understanding it properly. I'm on like day 2 of rails training but it's starting to make a bit of sense, hopefully. The way the rails mvc/routes all interact on an automagic level still spins my head a bit, but i'm no longer pulling out my hair and screeching, "What the hell is that?!"
Programming homework and newbie help thread Quote
12-23-2015 , 10:44 PM
Quote:
Originally Posted by fruit snacks
ok, digging a bit deeper I'm pretty sure my initial read of swapping bits was right and it doesn't mean flipping bits. So 010 will never be mapped to 101 but only 100 and 001.

Just seems weird since even a theoretical perfect one of this kind would seem to leak some info about the original contents but I guess thats just how they work.
I didnt read any of what you linked nor am some crypto expert so no idea if this is what they are talking about. But basically crypto is just a bunch of XORing bits together, so maybe thats what they are talking about in regards to "flipping bits"

https://en.wikipedia.org/wiki/Exclusive_or
Programming homework and newbie help thread Quote
12-24-2015 , 12:16 AM
Quote:
Originally Posted by fruit snacks
ok, digging a bit deeper I'm pretty sure my initial read of swapping bits was right and it doesn't mean flipping bits. So 010 will never be mapped to 101 but only 100 and 001.

Just seems weird since even a theoretical perfect one of this kind would seem to leak some info about the original contents but I guess thats just how they work.
I think you're basically right. They're talking about permutations of a set number of bits so it's not necessarily about flipping the way I read it. To me it seems to be how you can rearrange your existing bits. It just so happens you use a vector to arrange the bits differently, which flips some bits from 1 to 0.
Programming homework and newbie help thread Quote
01-05-2016 , 08:51 PM
Code:
  for (let i = 1; i<10; i++) {
    for (let j = 0; j<10; j++) {
    
      let positions = ['top'];
      if (j !== 0) positions.push('left');
      if (j !== 9) positions.push('right');
      let siblings = siblingCoords(i,j,positions);

      //now I can access data in sibling cells by looping through
      //siblings as cell and checking someMatrix[cell.i][cell.j]

    }   
  }

function siblingCoords(i,j,positions) {
  let coords = {
    top: {
      i: i-1,
      j: j
    },
    left: {
      i: i,
      j: j-1
    },
    right: {
      i: i,
      j: j+1
    }
  }
  return positions.map((pos) => coords[pos]);

}
I didn't go to school for cs and only recently began attempting various code challenges. Alot of problems involve matrices where you have to check sibling cells (here only directly above and left/right). I've found myself writing code like above to make sure I'm not getting index errors. Just want to check if going about it this way is stupid or if there is some better approach. I kind of just want to avoid having to put checks for negative or out of bounds indices throughout all the other functions I need.
Programming homework and newbie help thread Quote
01-06-2016 , 03:18 PM
ever trying to make connections between what I know and what I'm learning, in Ruby, this article is talking about mix ins via Enumerable:

Quote:
"Enumerable" is actually a "module", which means it is just a bunch of methods packaged together that can (and do) get "mixed in", or included, with other classes (like Array and Hash. That means that Ruby programmers don't have to write all those methods many different times - they just write them once, package them up as Enumerable, and tell Array and Hash to include them. As long as the class that wants to include Enumerable has its own #each method that Enumerable can use, it can get access to all the magic and joy of using the Enumerable methods by simply mixing it in.
Is this essentially like Java's interfaces then? Or maybe like a more fleshed-out version of interfaces? I'm just trying to figure out if the code goes in the class itself or if it gets pushed into Enumerable somehow.

I'll finish the article in case it gets mentioned there.
Programming homework and newbie help thread Quote
01-06-2016 , 04:32 PM
There's no direct equivalent in Java. This bit is the problem:

Quote:
As long as the class that wants to include Enumerable has its own #each method that Enumerable can use
That's OK in Ruby, which is dynamically typed. If the each method doesn't exist, it will fail at runtime. Statically typed languages like Java require a compile-time assurance that the method is there. So what you would do in Java is create an interface IEnumerable providing the each method, then put the mixin code in a static method somewhere which takes an IEnumerable as a parameter.

In both cases the code is put outside the class, in a module in Ruby and probably in a static class in Java.
Programming homework and newbie help thread Quote
01-06-2016 , 06:18 PM
Quote:
Originally Posted by fruit snacks
Code:
  for (let i = 1; i<10; i++) {
    for (let j = 0; j<10; j++) {
    
      let positions = ['top'];
      if (j !== 0) positions.push('left');
      if (j !== 9) positions.push('right');
      let siblings = siblingCoords(i,j,positions);

      //now I can access data in sibling cells by looping through
      //siblings as cell and checking someMatrix[cell.i][cell.j]

    }   
  }

function siblingCoords(i,j,positions) {
  let coords = {
    top: {
      i: i-1,
      j: j
    },
    left: {
      i: i,
      j: j-1
    },
    right: {
      i: i,
      j: j+1
    }
  }
  return positions.map((pos) => coords[pos]);

}
I didn't go to school for cs and only recently began attempting various code challenges. Alot of problems involve matrices where you have to check sibling cells (here only directly above and left/right). I've found myself writing code like above to make sure I'm not getting index errors. Just want to check if going about it this way is stupid or if there is some better approach. I kind of just want to avoid having to put checks for negative or out of bounds indices throughout all the other functions I need.
I prefer a solution that avoids such check, for sure. One method I use is to pretend that the boundary conditions don't matter. Just get each cell's neighbors, all of them, including the negative index ones and the too large ones. Then just run the all through "filter()" call, where the filter function encapsulates the logic for invalid cells (ie, negative or too big).

The logic will be much more natural, too, if you create a cell object that knows its own coords. Your matrix can then just be a flat array of cell objects, and you get rid of all your nested loops that way. Ultimately you're left with a solution much closer to the way you naturally think about problem, rather than one dictated by implementation details.
Programming homework and newbie help thread Quote
01-06-2016 , 09:39 PM
Great advice, thanks.
Programming homework and newbie help thread Quote
01-07-2016 , 12:19 PM
Rails code:
Code:
Carrierwave/MiniMagick

process :watermark   

def watermark
   second_image = MiniMagick::Image.open("https://s3.amazonaws.com/....logo.png")
   manipulate! do |img|
   result = img.composite(second_image) do |c|
     c.compose "Over"    # OverCompositeOp
     c.gravity "Southeast" 
   end
    result
   end
 end
Users upload images. I want those images to have my logo placed on the bottom corner. The code above results in the logo being placed on the photos surrounded by a square white background.

I have been attempting to try to code white/#FFFFFF to be converted to transparent but have not been able to find the correct code.
Programming homework and newbie help thread Quote
01-14-2016 , 05:26 PM
Hi friends,

quick cryptography questions
[IMG][/IMG]

its the second question that I don't understand, why deterministic encryption algorithms can not be IND-CPA secure, my guess is that, if you know the encryption process u can choose a plaintext to encrypt and reverse engineer to get the private key I can kind of see how this applies in public key cryptography, but I don't understand why this applies in private key crypto
doesn't the secrecy of the message depend on the secrecy of the key? so if the adversary can encrypt anything doesn't that mean he knows what the key is already??

please help me clear up this confusion
Programming homework and newbie help thread Quote
01-14-2016 , 06:04 PM
Quote:
Originally Posted by CyberShark93
but I don't understand why this applies in private key crypto
doesn't the secrecy of the message depend on the secrecy of the key? so if the adversary can encrypt anything doesn't that mean he knows what the key is already??

please help me clear up this confusion
There are a lot of private key crypto algorithms (block ciphers, stream ciphers, shift ciphers) that can be attacked without knowing the private key. The only one that 100% can't is the one time pad. So you seem to have some fundamental misunderstandings.

Also the adversary being able to encrypt anything without knowing the key is part of how cryptographers define security ("semantic security"). Basically it's a game where the adversary can encrypt any text he wants and then compare with the cipher text. Crypto is only secure when the adversary can't figure out the private key (or a relationship between input and output) even given this ability. From a practical pov this makes sense since so much data is structured in known ways like with http/email headers and such.
Programming homework and newbie help thread Quote
01-14-2016 , 06:45 PM
Quote:
Originally Posted by fruit snacks
There are a lot of private key crypto algorithms (block ciphers, stream ciphers, shift ciphers) that can be attacked without knowing the private key. The only one that 100% can't is the one time pad. So you seem to have some fundamental misunderstandings.

Also the adversary being able to encrypt anything without knowing the key is part of how cryptographers define security ("semantic security"). Basically it's a game where the adversary can encrypt any text he wants and then compare with the cipher text. Crypto is only secure when the adversary can't figure out the private key (or a relationship between input and output) even given this ability. From a practical pov this makes sense since so much data is structured in known ways like with http/email headers and such.
hi! thank you for your reply,

i'm finding it really hard to produce semantic security proofs. so i'm guessing for the indistinguishable chosen plaintext attack part, i suppose if the adversary wants to distinguish between m1 and m2, he can simply call the encrytion function on m1 and compare it with the ciphertext, therefore all deterministic schemes can not be CPA secure.

and in the very next lecture, my lecturer went on about all deterministic schemes are malleable to prove they can not be chosen cipher text secure, my question is, isn't CCA a stronger notion than CPA? therefore if we proved that we can break any deterministic scheme with CPA why do we need another prove for CCA?(this makes me think my thoughts on why deterministic schemes can not be CPA secure is wrong)
Programming homework and newbie help thread Quote
Programming homework and newbie help thread
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
Programming homework and newbie help thread

      
m