Picture of Problem :
Given the problem above I have a few questions. First, proc0 takes the place of a hole that is bigger than it, what happens to the remaining space?
For example in Q1 i: after bringing in Proc0 it's a. 10->15->15->25->30. Having the 15 replace the 20, theres 5 left, so what happens to it, and how would I depict what happens to it? Would it be a. 10->5->15->15->25->30 or a. 10->15->5->15->25->30?
Given, sizes of the proc
sz(proc 0) -> 15
sz(proc 1) -> 5
From what I am able to understand, the change in the Free List (10 -> 20 -> 15 -> 25 -> 30) is described below :
Q1 : First Fit (The size of the free-list would start decreasing)
When proc 0 (size=15) is brought to the list,
Free List converts to (10 -> 5 -> 15 -> 25 -> 30)
// the freelist size would decrease wherever the first biggest hole is found,
// so, hole of size 20 is replaced by a hole of size 5 to allocate memory to proc 0
When proc 1 (size=5) is brought to the list,
Free List converts to (5 -> 5 -> 15 -> 25 -> 30)
// the freelist size would decrease wherever the first biggest hole is found,
// so, hole of size 10 is replaced by a hole of size 5 to allocate memory to proc 1
Assuming the FreeList is again the same(10 -> 20 -> 15 -> 25 -> 30) before performing the First Fit allocation :
Q2 : Next Fit (The size of the free-list would start decreasing)
When proc 0 (size=15) is brought to the list,
Free List converts to (10 -> 5 -> 15 -> 25 -> 30)
// the freelist size would decrease wherever the next biggest hole is found,
// so, hole of size 20 is replaced by a hole of size 5 to allocate memory to proc 0
When proc 1 (size=5) is brought to the list,
Free List converts to (10 -> 0 -> 15 -> 25 -> 30), or better
Free List converts to (10 -> 15 -> 25 -> 30) // the size of the freelist decreases.
// the freelist size would decrease wherever the next biggest hole is found,
// so, hole of size 5 is replaced by a hole of size 0
// (or, rather no hole left, so list becomes continuous) to allocate memory to proc 1
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
How do I calculate the output size in a convolution layer?
For example, I have a 2D convolution layer that takes a 3x128x128 input and has 40 filters of size 5x5.
you can use this formula [(W−K+2P)/S]+1.
W is the input volume - in your case 128
K is the Kernel size - in your case 5
P is the padding - in your case 0 i believe
S is the stride - which you have not provided.
So, we input into the formula:
Output_Shape = (128-5+0)/1+1
Output_Shape = (124,124,40)
NOTE: Stride defaults to 1 if not provided and the 40 in (124, 124, 40) is the number of filters provided by the user.
You can find it in two ways:
simple method: input_size - (filter_size - 1)
W - (K-1)
Here W = Input size
K = Filter size
S = Stride
P = Padding
But the second method is the standard to find the output size.
Second method: (((W - K + 2P)/S) + 1)
Here W = Input size
K = Filter size
S = Stride
P = Padding
Let me start simple; since you have square matrices for both input and filter let me get one dimension. Then you can apply the same for other dimension(s). Imagine your are building fences between trees, if there are N trees, you have to build N-1 fences. Now apply that analogy to convolution layers.
Your output size will be: input size - filter size + 1
Because your filter can only have n-1 steps as fences I mentioned.
Let's calculate your output with that idea.
128 - 5 + 1 = 124
Same for other dimension too. So now you have a 124 x 124 image.
That is for one filter.
If you apply this 40 times you will have another dimension: 124 x 124 x 40
Here is a great guide if you want to know more about advanced convolution arithmetic: https://arxiv.org/pdf/1603.07285.pdf
Formula : n[i]=(n[i-1]−f[i]+2p[i])/s[i]+1
where,
n[i-1]=128
f[i]=5
p[i]=0
s[i]=1
so,
n[i]=(128-5+0)/1+1 =124
so the size of the output layer is: 124x124x40
Where '40' is the number of filters
(124*124*3)*40 = 1845120 width = 124 height = 124 depth = 3 no. of filters = 40 stride = 1 padding = 0
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
How can I print to POS printer if the output format should be like this?
paper size 3 inches
line 1 = ITEM DESCRIPTION
line 2 = QTY UNIT x UNIT PRICE_ _ _ _ _ _ _ TOTAL PRICE
Total PRICE is right align
sample format
BOND PAPER
1 REAM x 100.00 --------------- 100.00
BOND PAPER 2
2 REAM X 100.00 --------------- 200.00
BOND PAPER 3
1 REAM X 1,354.00 ----------- 1,354.00
POS printers typically use fixed width fonts, so right aligning the value of TotalPrice is simply a matter of calculating the amount of Padding to insert into the line after the ItemDescription.
In your example, you are using a 38 character line, so if the length of ItemDescription is 15 characters long, and the length of the TotalPrice is 6 characters long, then Padding needs to be 38 - (ItemDescription + TotalPrice) = 38 - (15 + 6) = 17 characters long. But since you seem to add a space immediately after ItemDescription and before TotalPrice your Padding needs to subtract these 2 additional characters... so, in that case Padding needs to be 15 characters long.
Applying this to your last line:
Length(ItemDescription) = 17
Length(TotalPrice) = 8
Padding = 38 - (17 + 8 + 2) = 11
So the final line that you will send to your fixed width font POS will be:
PrintLine = Concat(ItemDescription,' ',StringOfChar('-',Padding),' ', TotalPrice)
This should always right align TotalPrice for the given fixed width character paper size (change the 38 to whatever the number of characters your POS printer is rated at), and all long as the total length of ItemDescription, TotalPrice and your single character spaces does not exceed the total character width of the printer (you should probably check this before calculating Padding).
I have a sample pdf (attached), and it includes a text object and a rectangle object that have almost the same height. Then I checked the content of the pdf by using itextrup as below:
1 1 1 RG
1 1 1 rg
0.12 0 0 0.12 16 50 cm
q
0 0 m
2926 0 l
2926 5759 l
0 5759 l
0 0 l
W
n
Q
1 1 1 RG
1 1 1 rg
q
0 0 m
2926 0 l
2926 5759 l
0 5759 l
0 0 l
W
n
/F1 205.252 Tf
BT
0 0 0 RG
0 0 0 rg
/DeviceGray CS
/OC /oc1 BDC
0 -1 1 0 1648 5330 Tm
0 Tc
100 Tz
(Hello World) Tj
ET
Q
q
0 0 m
2926 0 l
2926 5759 l
0 5759 l
0 0 l
W
n
0 0 0 RG
0 0 0 rg
/DeviceGray CS
6 w
1 j
1 J
1649 5324 m
1649 4277 l
1800 4277 l
1800 5324 l
1649 5324 l
S
EMC
Q
Obviously the user space matrix is determined by [0.12 0 0 0.12 16 50], and the height for the rectangle is (1800-1649)*0.12*1=18.12, and for the font size I use 205.252*0.12=24.63024. Since the two values are not close, my problem is how to get the height/size of the font?
sample.pdf
OK - I took a look at your file and you're basically hosed. That's the scientific answer, now let me clarify :)
Bad PDF!
The PDF you have up there as a sample contains a font that is not embedded. That "/F1 Tf" command you have there points to the font "ArialMT" in the resources dict for that page. Because the font has not been embedded, you only have two options:
Try to find the actual font on the system and extract the necessary information from there.
Live with the information in the PDF. Let's start with that.
Font Descriptor
Here is an image from pdfToolbox examining the font in the PDF file (caution: I'm associated with this tool):
I've cut off some of the "Widths" table, but other than that this is all of the information you have in the PDF document for this font. And this means you can access the widths for each glyph, but you don't have access to the heights of each glyph. The only information you have regarding heights is the font bounding box which is the union of all glyph bounding boxes. In other words, the font bounding box is guaranteed to be big enough to contain any glyph from the font (both horizontally and vertically).
System Information
You don't say why you need this information so it becomes a little harder to advise further. But if you can't get the information from the PDF, you're only option is to live with the inaccurate information from the PDF or to turn to the system your code is running on to get you more.
If you have the ArialMT font installed, you could basically try to find the font file and then parse the TrueType font file to find the bounding boxes for each glyph. I've done that, it's not funny.
Or you can see if your system can't provide you with the information in a better way. Many operating systems / languages have text calls that can get accurate measurements for you. If not, you can brute force it by rendering the text you want in black on a white image and then examining the pixels to see where you hit and thus how big the largest glyph in your text string was.
Wasteful though that last option sounds, it's probably the quickest and easiest to implement and it - depending on your needs - may actually be the best option all around.
I have a sample pdf (attached), and it includes a text object and a rectangle object that have almost the same height.
Indeed, your PDF is displayed like this:
But looking at this one quickly realizes that the glyphs in your text "Hello World" do not extend beneath the base line like a 'g', 'j' or some other glyphs would:
(The base line is the line through the glyph origins)
Since the two values are not close, my problem is how to get the height/size of the font
Obviously the space required for such descenders beneath the base line must also be part of the font size.
Thus, it is completely correct and not a problem that the height of the box (18.12) is considerably smaller than the font size (24.63024).
BTW, this corresponds with the specification which describes a font size of 1 to be arranged so that the nominal height of tightly spaced lines of text is 1 unit, cf. section 9.2.2 "Basics of Showing Text" of ISO 32000-1. Tightly spaced lines obviously need to include not only glyph parts above the base line but also those below. Additionally it furthermore includes a small gap between such lines as even tightly spaced lines are not expected to touch each other.
I set up a group in my WatchApp Storyboard which has a width relative to container 1 and height relative to container 0.5.
Inside this group I have 20 horizontal aligned groups with a width relative to container 0,05. The spacing of the group is set to 0 but when i set a background color to all groups I end up like this.
As you can see, some spacings are really zero but sometimes there is a small gap of about 1 px. Is this some sort of bug? Is it possibile to perfectly align the groups so that it looks like it is one solid background?
Please don't tell me, that I can set the background color of the first group. Obviously I know that, i need it to work like this!
Thanks!
I believe the problem is that the width of the screen isn't evenly divisible by 20. The width of the 42mm screen is 312 pixels, which divided by 20 is 15.6 pixels. Apple is probably truncating this to an integer value for performance, which results in the gaps.
I reproduced your problem and then, to test my theory, I created 8 groups instead of 20 and set them to a width of 0.125. This resulted in no gaps, which makes sense since 312 is divisible by 8.
The 32mm watch has a width of 272 pixels and, doing factorization of the two I got:
272 = 2 * 2 * 2 * 2 * 17
312 = 2 * 2 * 2 * 3 * 13
Which shows that eight columns is the maximum by which you can evenly divide both sizes.
If you have to have 20 columns, then I would set each to a fixed width, some at 15 and some at 16 pixels for the 42 mm, and 13/14 pixels for the 32 mm to get the layout you want.
I am creating a football simulation game and I would like to make a 2D view of match. My match is 90 minutes long and there are 22 players on the field. How could I save a movements/path for players so that it wouldn't take lots of space. I know I could save it something like
Minute: min,
Player: id,
X: xCoord,
Y: yCoord
and then just move objects with jQuery from point A to point B, but I am sure it isn't the best solution, because it would require lots of space and database entries.
I am using MongoDB, but all suggestions are welcome.
How do the players move? They move a little in each step of the main loop? Or they go in long straight lines and then make sudden turns and go in other straight lines? In the first case you would probably need to save each milisecond or so (each step of the main loop), or you could save their positions every ten steps or every second, etc. And the replay could interpolate the saved points (thought the replay would look "gross" like that, it could save a lot of space in your db). In the second case (straight lines), you could just save the points where the players turn in another direction. In this case you'll save their position, angle and speed (along with time, obviously).
The first table could be (the intervals could be more than 1ms, depending on the power of the machine):
PLAYER TIME(ms) X Y
1 0 0 0
1 1 0 2
1 2 0 4
1 3 0 7
1 4 0 10
1 5 4 13
While the second table would be:
PLAYER TIME(ms) X Y Dir Speed
1 0 0 0 90 2
1 2 0 4 90 3
1 4 0 10 60 5
or something like that. Dir is the direction in degrees. Hope that helps!