Search Results

Search found 4022 results on 161 pages for 'float dublin'.

Page 86/161 | < Previous Page | 82 83 84 85 86 87 88 89 90 91 92 93  | Next Page >

  • Updating entity fields in app engine development server

    - by Joey
    I recently tried updating a field in one of my entities on the app engine local dev server via the sdk console. It appeared to have updated just fine (a simple float). However, when I followed up with a query on the entity, I received an exception: "Items in the mSomeList list must all be Key instances". mSomeList is just another list field I have in that entity, not the one I modified. Is there any reason manually changing a field would adversely throw something off such that the server gets confused? Is this a known bug? I wrote an http handler to alter the field through server code and it works fine if I take that approach. Update: (adding details) I am using the python google app engine server. Basically if I go into the Google App Engine Launcher and press the SDK Console button, then go into one of my entities and edit a field that is a float (i.e. change it from 0 to 3.5, for instance), I get the "Items in the mMyList list must all be Key instance" suddenly when I query the entity like this: query = DataModels.RegionData.gql("WHERE mRegion = :1", region) entry = query.get() the RegionData entity is what has the mMyList member. As mentioned previously, if I do not manually change the field but rather do so through server code, i.e. query = DataModels.RegionData.gql("WHERE mRegion = :1", region) entry = query.get() entry.mMyFloat = 3.5 entry.put() Then it works.

    Read the article

  • What is the fastest way to do division in C for 8bit MCUs?

    - by Jordan S
    I am working on the firmware for a device that uses an 8bit mcu (8051 architecture). I am using SDCC (Small Device C Compiler). I have a function that I use to set the speed of a stepper motor that my circuit is driving. The speed is set by loading a desired value into the reload register for a timer. I have a variable, MotorSpeed that is in the range of 0 to 1200 which represents pulses per second to the motor. My function to convert MotorSpeed to the correct 16bit reload value is shown below. I know that float point operations are pretty slow and I am wondering if there is a faster way of doing this... void SetSpeed() { float t = MotorSpeed; unsigned int j = 0; t = 1/t ; t = t / 0.000001; j = MaxInt - t; TMR3RL = j; // Set reload register for desired freq return; }

    Read the article

  • How to maintain an ordered table with Core Data (or SQL) with insertions/deletions?

    - by Jean-Denis Muys
    This question is in the context of Core Data, but if I am not mistaken, it applies equally well to a more general SQL case. I want to maintain an ordered table using Core Data, with the possibility for the user to: reorder rows insert new lines anywhere delete any existing line What's the best data model to do that? I can see two ways: 1) Model it as an array: I add an int position property to my entity 2) Model it as a linked list: I add two one-to-one relations, next and previous from my entity to itself 1) makes it easy to sort, but painful to insert or delete as you then have to update the position of all objects that come after 2) makes it easy to insert or delete, but very difficult to sort. In fact, I don't think I know how to express a Sort Descriptor (SQL ORDER BY clause) for that case. Now I can imagine a variation on 1): 3) add an int ordering property to the entity, but instead of having it count one-by-one, have it count 100 by 100 (for example). Then inserting is as simple as finding any number between the ordering of the previous and next existing objects. The expensive renumbering only has to occur when the 100 holes have been filled. Making that property a float rather than an int makes it even better: it's almost always possible to find a new float midway between two floats. Am I on the right track with solution 3), or is there something smarter?

    Read the article

  • vlcj not displaying the video

    - by Cássio Eudardo
    I'm using vlcj to play video, but the video doesn't display on some computers(i tested in 4 and worked on 2, all windows), on 1 it displays the button but not the video and on the other it just display a gray background without the button. I tested .wmv and .avi files. I'm using the following code: public class Video extends JFrame implements WindowListener{ private JPanel contentPane; private JButton btnClose; private Dimension size; private float aspectRatio; private EmbeddedMediaPlayer mediaPlayer; public Video() { try { size = Toolkit.getDefaultToolkit().getScreenSize(); aspectRatio = (float)size.width/size.height; String file = "..."; btnClose = new JButton("X"); btnClose.addActionListener(new ActionListener() {...}); btnClose.setBounds(640 - 50, 10, 40, 40); setBounds(size.width/2 - 320, (int)(size.height - 40*aspectRatio) - 250, 640, 200); contentPane = new JPanel(); contentPane.setLayout(null); setContentPane(contentPane); WindowsCanvas surface = new WindowsCanvas(); contentPane.setBounds(0, 0, 640, 200); surface.setBounds(0, 0, 640, 200); MediaPlayerFactory factory = new MediaPlayerFactory(new String("--no-video-title-show")); mediaPlayer = factory.newEmbeddedMediaPlayer(); surface.addMouseListener(new MouseListener() {...}); contentPane.add(btnClose); contentPane.add(surface); setVisible(true); mediaPlayer.setVideoSurface(factory.newVideoSurface(surface)); mediaPlayer.setRepeat(true); mediaPlayer.playMedia(file); } catch(Exception e) { } }}

    Read the article

  • css caption issue

    - by Moode Osman
    i have problem with caption to make caption appear under each photo when hover over it but thr problem here they appear all on one side one place the left bottom side here the code for HTML <div id="content2"> <ul style="width: 5020px; height: 600px;"> <li class="image" style="width: 392px;"><img src="images/pr1x.jpg" ><p class="caption">1st caption</p></li> <li class="image" style="width: 392px;"><img src="images/pr2x.jpg" ><p class="caption">2st caption</p></li> </ul></div> here the code for CSS li.image p.caption { position:absolute; display: none; font-size: 28px; color: red; } li.image:hover p.caption { display: list-item; }? #content2{ width: 150%; height: 600px; float:left; overflow:hidden; } #content2 p{ width: 150%; } .scrollbar-hor{ background-color: #e5e2de; height: 24px; width: 150%; float:left; } .handle-hor{ height: 25px; width: 400px; background: url(http://brafitting.info/images/bar.jpg) no-repeat; } plz help ty

    Read the article

  • MySQL query puzzle - finding what WOULD have been the most recent date

    - by Hank
    I've looked all over and haven't yet found an intelligent way to handle this, though I feel sure one is possible: One table of historical data has quarterly information: CREATE TABLE Quarterly ( unique_ID INT UNSIGNED NOT NULL, date_posted DATE NOT NULL, datasource TINYINT UNSIGNED NOT NULL, data FLOAT NOT NULL, PRIMARY KEY (unique_ID)); Another table of historical data (which is very large) contains daily information: CREATE TABLE Daily ( unique_ID INT UNSIGNED NOT NULL, date_posted DATE NOT NULL, datasource TINYINT UNSIGNED NOT NULL, data FLOAT NOT NULL, qtr_ID INT UNSIGNED, PRIMARY KEY (unique_ID)); The qtr_ID field is not part of the feed of daily data that populated the database - instead, I need to retroactively populate the qtr_ID field in the Daily table with the Quarterly.unique_ID row ID, using what would have been the most recent quarterly data on that Daily.date_posted for that data source. For example, if the quarterly data is 101 2009-03-31 1 4.5 102 2009-06-30 1 4.4 103 2009-03-31 2 7.6 104 2009-06-30 2 7.7 105 2009-09-30 1 4.7 and the daily data is 1001 2009-07-14 1 3.5 ?? 1002 2009-07-15 1 3.4 && 1003 2009-07-14 2 2.3 ^^ then we would want the ?? qtr_ID field to be assigned '102' as the most recent quarter for that data source on that date, and && would also be '102', and ^^ would be '104'. The challenges include that both tables (particularly the daily table) are actually very large, they can't be normalized to get rid of the repetitive dates or otherwise optimized, and for certain daily entries there is no preceding quarterly entry. I have tried a variety of joins, using datediff (where the challenge is finding the minimum value of datediff greater than zero), and other attempts but nothing is working for me - usually my syntax is breaking somewhere. Any ideas welcome - I'll execute any basic ideas or concepts and report back.

    Read the article

  • c program pointer

    - by sandy101
    Hello , I am trying some programs in c face a problem with this program #include<stdio.h> int main() { int a=9,*x; float b=3.6,*y; char c='a',*z; printf("the value is %d\n",a); printf("the value is %f\n",b); printf("the value is %c\n",c); x=&a; y=&b; z=&c; printf("%u\n",a); printf("%u\n",b); printf("%u\n",c); x++; y++; z++; printf("%u\n",a); printf("%u\n",b); printf("%u\n",c); return 0; } can any one tell me what is the problem with this and i also want to know that when in the above case if the pointer value is incremented then will it over write the previous value address as suppose that the value we got in the above program (without the increment in the pointer value )is 65524 65520 65519 and after the increment the value of the pointer is 65526(as 2 increment for the int ) 65524(as 4 increment for the float ) 65520(as 1 increment for the char variable ) then if in that case will the new pointer address overwrite the content of the previous address and what value be contained at the new address ......plz help

    Read the article

  • How to convert between different currencies?

    - by sil3nt
    Hey there, this is part of a question i got in class, im at the final stretch but this has become a major problem. In it im given a certain value which is called the "gold value" and it is 40.5, this value changes in input. and i have these constants const int RUBIES_PER_DIAMOND = 5; // relative values. * const int EMERALDS_PER_RUBY = 2; const int GOLDS_PER_EMERALDS = 5; const int SILVERS_PER_GOLD = 4; const int COPPERS_PER_SILVER = 5; const int DIAMOND_VALUE = 50; // gold values. * const int RUBY_VALUE = 10; const int EMERALD_VALUE = 5; const float SILVER_VALUE = 0.25; const float COPPER_VALUE = 0.05; which means that basically for every diamond there are 5 rubies, and for every ruby there are 2 emeralds. So on and so forth. and the "gold value" for every diamond for example is 50 (diamond value = 50) this is how much one diamond is worth in golds. my problem is converting 40.5 into these diamonds and ruby values. I know the answer is 4rubies and 2silvers but how do i write the algorithm for this so that it gives the best estimate for every goldvalue that comes along?? please help!, im at my wits end

    Read the article

  • get_by_id method on Model classes in Google App Engine Datastore

    - by tarn
    I'm unable to workout how you can get objects from the Google App Engine Datastore using get_by_id. Here is the model from google.appengine.ext import db class Address(db.Model): description = db.StringProperty(multiline=True) latitude = db.FloatProperty() longitdue = db.FloatProperty() date = db.DateTimeProperty(auto_now_add=True) I can create them, put them, and retrieve them with gql. address = Address() address.description = self.request.get('name') address.latitude = float(self.request.get('latitude')) address.longitude = float(self.request.get('longitude')) address.put() A saved address has values for >> address.key() aglndWVzdGJvb2tyDQsSB0FkZHJlc3MYDQw >> address.key().id() 14 I can find them using the key from google.appengine.ext import db address = db.get('aglndWVzdGJvb2tyDQsSB0FkZHJlc3MYDQw') But can't find them by id >> from google.appengine.ext import db >> address = db.Model.get_by_id(14) The address is None, when I try >> Address.get_by_id(14) AttributeError: type object 'Address' has no attribute 'get_by_id' How can I find by id? EDIT: It turns out I'm an idiot and was trying find an Address Model in a function called Address. Thanks for your answers, I've marked Brandon as the correct answer as he got in first and demonstrated it should all work.

    Read the article

  • Which fieldtype is best for storing PRICE values?

    - by BerggreenDK
    Hi there I am wondering whats the best "price field" in MSSQL for a shoplike structure? Looking at this overview: http://www.teratrax.com/sql_guide/data_types/sql_server_data_types.html We have datatypes called money, smallmoney, then we have decimal/numeric and lastly float and real Name, memory/disk-usage and value ranges: Money: 8 bytes (values: -922,337,203,685,477.5808 to +922,337,203,685,477.5807) Smallmoney: 4 bytes (values: -214,748.3648 to +214,748.3647) Decimal: 9 [default, min. 5] bytes (values: -10^38 +1 to 10^38 -1 ) Float: 8 bytes (values: -1.79E+308 to 1.79E+308 ) Real: 4 bytes (values: -3.40E+38 to 3.40E+38 ) My question is: is it really wise to store pricevalues in those types? what about eg. INT? Int: 4 bytes (values: -2,147,483,648 to 2,147,483,647) Lets say a shop uses dollars, they have cents, but I dont see prices being $49.2142342 so the use of a lot of decimals showing cents seems waste of SQL bandwidth. Secondly, most shops wouldn't show any prices near 200.000.000 (not in normal webshops at least... unless someone is trying to sell me a famous tower in Paris) So why not go for an int? An int is fast, its only 4 bytes and you can easily make decimals, by saving values in cents instead of dollars and then divide when you present the values. The other approach would be to use smallmoney which is 4 bytes too, but this will require the math part of the CPU to do the calc, where as Int is integer power... on the downside you will need to divide every single outcome. Are there any "currency" related problems with regionalsettings when using smallmoney/money fields? what will these transfer too in C#/.NET ? Any pros/cons? Go for integer prices or smallmoney or some other? Whats does your experience tell?

    Read the article

  • Rendering blocks side-by-side with FOP

    - by Rolf
    I need to generate a PDF from XML data using Apache FOP. The problem is that FOP doesn't support fo:float, and I really need to have items (boxes of rendered data) side-by-side in the PDF. More precisely, I need them in a 4x4 grid on each page, like so: In HTML, I would simply render these as left-floated divs with appropriate widths and heights. My data looks something like this: <item id="1"> <a>foo</a> <b>bar</b> <c>baz</c> </item> <item id="2">...</item> ... <item id="n">...</item> I considered using a two-column region-body, but then the order of items would be 1, 3, 2, 4 (reading from left to right) since they would be rendered tb-lr instead of lr-tb, and I need them to be in the correct order (id in above xml). I suppose I could try using a table, but I'm not quite sure how to group the items into table rows. So, some kind of workaround for the lack of fo:float would be greatly appreciated.

    Read the article

  • Slope requires a real as parameter 2?

    - by Dave Jarvis
    Question How do you pass the correct value to udf_slope's second parameter type? Attempts CAST(Y.YEAR AS FLOAT), but that failed (SQL error). Y.YEAR + 0.0, but that failed, too (see error message). slope(D.AMOUNT, 1.0), failed as well Error Message Using udf_slope fails due to: Can't initialize function 'slope'; slope() requires a real as parameter 2 Code SELECT D.AMOUNT, Y.YEAR, slope(D.AMOUNT, Y.YEAR + 0.0) as SLOPE, intercept(D.AMOUNT, Y.YEAR + 0.0) as INTERCEPT FROM YEAR_REF Y, DAILY D Here, D.AMOUNT is a FLOAT and Y.YEAR is an INTEGER. Create Function The slope function was created as follows: CREATE AGGREGATE FUNCTION slope RETURNS REAL SONAME 'udf_slope.so'; Function Signature From udf_slope.cc: double slope( UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* is_error ) Example Usages Reading the fine manual reveals: UDF intercept() Calculates the intercept of the linear regression of two sets of variables. Function name intercept Input parameter(s) 2 (dependent variable: REAL, independent variable: REAL) Examples SELECT intercept(income,age) FROM customers UDF slope() Calculates the slope of the linear regression of two sets of variables. Function name slope Input parameter(s) 2 (dependent variable: REAL, independent variable: REAL) Examples SELECT slope(income,age) FROM customers Thoughts? Thank you!

    Read the article

  • Invert the 1bbp color under a rectangle.

    - by Scott Chamberlain
    I am working with GDI+, the image I am working with is a 1bbp image. What i would like to do is draw a rectangle on the image and everything under that rectangle will be inverted (white pixels will become black and black pixels become white). All of the sample code I have seen is for 8 bit RGB color scale images, and I don't think the techniques they use will work for me. Here is the code I have so far. This is the parent control, one of the Epl2.IDrawableCommand's will be the command that does the inverting. protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (Label != null) { using (Bitmap drawnLabel = new Bitmap((int)((float)Label.LabelHeight * _ImageScaleFactor), (int)((float)Label.LableLength *(int) _ImageScaleFactor), System.Drawing.Imaging.PixelFormat.Format1bppIndexed)) { using (Graphics drawBuffer = Graphics.FromImage(drawnLabel)) { drawBuffer.ScaleTransform(_ImageScaleFactor, _ImageScaleFactor); foreach (Epl2.IDrawableCommand cmd in Label.Collection) { cmd.Paint(drawBuffer); } drawBuffer.ResetTransform(); } drawnLabel.RotateFlip(Rotation); pbLabelDrawArea.Size = drawnLabel.Size; using (Graphics drawArea = pbLabelDrawArea.CreateGraphics()) { drawArea.Clear(Color.White); drawArea.DrawImage(drawnLabel, new Point(0, 0)); } } } } What should I put in the Paint(Graphic g) for this command?

    Read the article

  • How to bring the parent element with floated child elements to the center of the document?

    - by Starx
    I have organized a menu. Its HTML is as follows: <ul class="topmenu"> <li><a href="sample.html">Text 1</a></li> <li><a href="sample.html">Text 2</a></li> <li><a href="sample.html">Text 3</a></li> <li><a href="sample.html">Text 4</a></li> <ul> This is a horizontal menu, so I have floated the list items to left to appear them in a horizontal line. I could have used display:inline to appear them in a single line, but since IE does not support it and I don't know any other way to do so, I used float:left;. It's css is: .topmenu { list-style:none; margin:0; padding:0; } .topmenu li { float:left; } This brings the menu in a perfect horizontal line, but the entire list is floated to the left. I want to bring the .topmenu to appear in the center of the document and keep the listitem inside it floated towards the left. I found that this is achievable by defining width property of the .topmenu, but I dont want to fix its width as the list-items are dynamically generated and thus could increase and decrease. Any one know of any solution?

    Read the article

  • Why do I get errors when using unsigned integers in an expression with C++?

    - by neuviemeporte
    Given the following piece of (pseudo-C++) code: float x=100, a=0.1; unsigned int height = 63, width = 63; unsigned int hw=31; for (int row=0; row < height; ++row) { for (int col=0; col < width; ++col) { float foo = x + col - hw + a * (col - hw); cout << foo << " "; } cout << endl; } The values of foo are screwed up for half of the array, in places where (col - hw) is negative. I figured because col is int and comes first, that this part of the expression is converted to int and becomes negative. Unfortunately, apparently it doesn't, I get an overflow of an unsigned value and I've no idea why. How should I resolve this problem? Use casts for the whole or part of the expression? What type of casts (C-style or static_cast<...)? Is there any overhead to using casts (I need this to work fast!)? EDIT: I changed all my unsigned ints to regular ones, but I'm still wondering why I got that overflow in this situation.

    Read the article

  • C# Changing Objects within a List

    - by kwong22
    Hi, I'm having a little problem changing members of an object in a list using a found index. So this is the method I am currently working with: static void addToInventory(ref List<baseItem> myArray, baseItem item, float maxAmount, ref float currentAmount) { if (currentAmount + item.getWeight() <= maxAmount) { Console.WriteLine("item.Quantity = {0}", item.Quantity); if (myArray.Contains(item)) { Console.WriteLine("Item ({0}) already exists", item.Name); int id = myArray.IndexOf(item); myArray[id].Quantity += item.Quantity;//Change occurs in this line, item.Quantity becomes the same as myArray[id].Quantity } else { Console.WriteLine("Adding new item ({0})", item.Name); myArray.Add(item); } currentAmount += item.getWeight(); } else { Console.WriteLine("Inventory full"); } myArray.Sort(); } This method takes several parameters including the inventory/list. I check if the item fits in and if it does, I see if there is another item of the same name in the list, find the index, and add more of the item. However, the quantity of the item added suddenly becomes the same as the quantity of the item in the list. For some reason, this also changes the quantity of the item outside of the list. So therefore, instead of quantities adding up like this: 1, 2, 3, 4, they add up like this: 1, 2, 4, 8. I've just started to learn how to use lists so if there is anything I'm missing, don't hesitate to criticize. Thanks in advance.

    Read the article

  • Submit to open up a popup window and carry through input data

    - by zac
    Hi, I have a input box on one page that on submit opens a new page with a longer form and the first field is populated with what was entered from the previous pages input box. So on page 1 there is this code: <form action="sign-up.php"> <input type="text" name="email" value="sign up for email" onFocus="clearText(this)" onBlur="clearText(this)" style="float: left;"> <input value='Submit' /> </form> Then on the sign-up page the receiving form grabs the string out of the url //<!-- Begin function getParams() { var idx = document.URL.indexOf('?'); if (idx != -1) { var tempParams = new Object(); var pairs = document.URL.substring(idx+1,document.URL.length).split('&'); for (var i=0; i<pairs.length; i++) { nameVal = pairs[i].split('='); tempParams[nameVal[0]] = nameVal[1]; } return tempParams; } } var params = getParams(); // End --> I would like to keep all of this functionality but it have it occur in a popup. I added this function to the submit: function myPopup() { window.open( "sign-up.php", "myWindow", "status = 1, height = 300, width = 300, resizable = 0" ) and the form becomes <form> <input type="text" name="email" value="sign up for email" onFocus="clearText(this)" onBlur="clearText(this)" style="float: left;"> <input onClick="myPopup()" value='Submit' /> </form> But it no longer appends the input data to the url string. Anyone have any ideas on how I can accomplish this?

    Read the article

  • Android ArrayList<Location> passing between activities

    - by squixy
    I have simple class Track, which stores information about route: import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import android.location.Location; public class Track implements Serializable { private static final long serialVersionUID = -5317697499269650204L; private Date date; private String name; private int time; private double distance, speed; private ArrayList<Location> route; public Track(String name, int time, double distance, ArrayList<Location> route) { this.date = new Date(); this.name = name; this.time = time; this.distance = distance; this.speed = distance / (time / 3600.); this.route = route; } public String getDate() { return String.format("Date: %1$td-%1$tb-%1$tY%nTime: %1$tH:%1$tM:%1$tS", date); } public String getName() { return name; } public int getTime() { return time; } public double getDistance() { return distance; } public float getSpeed() { return (float) speed; } public ArrayList<Location> getRoute() { return route; } @Override public String toString() { return String.format("Name: %s%nDate: %2$td-%2$tb-%2$tY%nTime: %2$tH:%2$tM:%2$tS", name, date); } } And I'm passing it from one activity to another: Intent showTrackIntent = new Intent(TabSavedActivity.this, ShowTrackActivity.class); showTrackIntent.putExtra("track", adapter.getItem(position)); startActivity(showTrackIntent); Where (Track object is element on ListView). I get error during passing Track object: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = classes.Track) What is happening?

    Read the article

  • Z-Index: Divs still overlap in the wrong order (browserwide)

    - by BeatMe
    Hi, I can't select one of those dropdrown-links, although the #header div has a higher z-index than the rest. All relevant divs are in the same level but do not align properly: http://img32.imageshack.us/img32/4245/zindex.png <div id="header"> <div id="navigation"> </div> </div> <div id="sidebar"></div> <div id="content"> ... </div> #header { width: 915px; height: 76px; z-index: 5; } #content { width: 677px; height: 412px; margin-left: 202px; z-index:1; } #sidebar { float: left; width: 200px; height: 448px; z-index: 2; } #navigation { height: 28px; width: 915px; float: right; }

    Read the article

  • Seeking C Union clarity

    - by mustISignUp
    typedef union { float flts[4]; struct { GLfloat r; GLfloat theta; GLfloat phi; GLfloat w; }; struct { GLfloat x; GLfloat y; GLfloat z; GLfloat w; }; } FltVector; Ok, so i think i get how to use this, (or, this is how i have seen it used) ie. FltVector fltVec1 = {{1.0f, 1.0f, 1.0f, 1.0f}}; float aaa = fltVec1.x; etc. But i'm not really groking how much storage has been declared by the union (4 floats? 8 floats? 12 floats?), how? and why? Also why two sets of curly braces when using FltVector {{}}? Any pointers much appreciated (sorry for the pun)

    Read the article

  • CUDA - multiple kernels to compute a single value

    - by Roger
    Hey, I'm trying to write a kernel to essentially do the following in C float sum = 0.0; for(int i = 0; i < N; i++){ sum += valueArray[i]*valueArray[i]; } sum += sum / N; At the moment I have this inside my kernel, but it is not giving correct values. int i0 = blockIdx.x * blockDim.x + threadIdx.x; for(int i=i0; i<N; i += blockDim.x*gridDim.x){ *d_sum += d_valueArray[i]*d_valueArray[i]; } *d_sum= __fdividef(*d_sum, N); The code used to call the kernel is kernelName<<<64,128>>>(N, d_valueArray, d_sum); cudaMemcpy(&sum, d_sum, sizeof(float) , cudaMemcpyDeviceToHost); I think that each kernel is calculating a partial sum, but the final divide statement is not taking into account the accumulated value from each of the threads. Every kernel is producing it's own final value for d_sum? Does anyone know how could I go about doing this in an efficient way? Maybe using shared memory between threads? I'm very new to GPU programming. Cheers

    Read the article

  • How to refresh/redraw the screen (not the program window)

    - by mohrphium
    I'm having a bit of a hard time figuring out, how to remove a drawn ellipse after it has been drawn somewhere else. I need a circle to follow my mouse all the time and this is all the program should do. I get the mousepositions and draw my circle but how can I remove the last one? #include <Windows.h> #include <iostream> void drawRect(int a1, int a2){ HDC screenDC = ::GetDC(0); //Draw circle at mouse position ::Ellipse(screenDC, a1, a2+5, a1+9, a2+14); ::ReleaseDC(0, screenDC); //::InvalidateRect(0, NULL, TRUE); //<- I tried that but then everything flickers //Also, the refresh rate is not fast enough... still some circles left } int main(void) { int a1; int a2; bool exit=false; while (exit!=true) { POINT cursorPos; GetCursorPos(&cursorPos); float x = 0; x = cursorPos.x; float y = 0; y = cursorPos.y; a1=(int)cursorPos.x; a2=(int)cursorPos.y; drawRect(a1, a2); } } I am working with graphics and all that stuff for the first time. Im kinda stuck here... once again. Thanks.

    Read the article

  • How can I split a LINESTRING into two LINESTRINGs at a given point?

    - by sabbour
    Hello, I'm trying to write a function that will split a LINESTRING into two LINESTRINGs given the split point. What I'm trying to achieve is a function that given a LINESTRING and a distance, it will return N LINESTRINGS for the original linestring splitted at multiples of that distance. This is what I have so far (I'm using SQL Server Spatial Tools from CodePlex): DECLARE @testLine geography; DECLARE @slicePoint geography; SET @testLine = geography::STGeomFromText('LINESTRING (34.5157942 28.5039665, 34.5157079 28.504725, 34.5156881 28.5049565, 34.5156773 28.505082, 34.5155642 28.5054437, 34.5155498 28.5054899, 34.5154937 28.5058826, 34.5154643 28.5060218, 34.5153968 28.5063415, 34.5153322 28.5065338, 34.5152031 28.5069178, 34.5150603 28.5072288, 34.5148716 28.5075501, 34.5146106 28.5079974, 34.5143617 28.5083813, 34.5141373 28.5086414, 34.5139954 28.5088441, 34.5138874 28.5089983, 34.5138311 28.5091054, 34.5136783 28.5093961, 34.5134336 28.5097531, 34.51325 28.5100794, 34.5130256 28.5105078, 34.5128754 28.5107957, 34.5126258 28.5113222, 34.5123984 28.5117673)', 4326) DECLARE @pointOne geography; declare @result table (segment geography) DECLARE @sliceDistance float DECLARE @nextSliceAt float SET @sliceDistance = 100 -- slice every 100 meters SET @nextSliceAt = @sliceDistance SELECT @pointOne = @testLine.STStartPoint() WHILE(@nextSliceAt < @testLine.STLength()) BEGIN SELECT @slicePoint = dbo.LocateAlongGeog(@testLine,@nextSliceAt) DECLARE @subLineString geography; SET @subLineString = geography::STGeomFromText('LINESTRING (' + dbo.FloatToVarchar(@pointOne.Long) + ' ' + dbo.FloatToVarchar(@pointOne.Lat) + ',' + dbo.FloatToVarchar(@slicePoint.Long) + ' ' + dbo.FloatToVarchar(@slicePoint.Lat) +')', 4326) insert into @result SELECT @subLineString SET @pointOne = @slicePoint set @nextSliceAt = @nextSliceAt + @sliceDistance END SET @subLineString = geography::STGeomFromText('LINESTRING (' + dbo.FloatToVarchar(@pointOne.Long) + ' ' + dbo.FloatToVarchar(@pointOne.Lat) + ',' + dbo.FloatToVarchar(@testLine.STEndPoint().Long) + ' ' + dbo.FloatToVarchar(@testLine.STEndPoint().Lat) +')', 4326) insert into @result SELECT @subLineString select * from @result I know it is not the best looking code, but there is another problem. The above code approximates the resulting LINESTRING because it does not follow the curvature of the original LINESTRING as it only takes into consideration the start and end points when creating the new segment. Is there a way take a substring out of the original LINESTRING given the start and end points?

    Read the article

  • Casting Type array to Generic array?

    - by George R
    The short version of the question - why can't I do this? I'm restricted to .NET 3.5. T[] genericArray; // Obviously T should be float! genericArray = new T[3]{ 1.0f, 2.0f, 0.0f }; // Can't do this either, why the hell not genericArray = new float[3]{ 1.0f, 2.0f, 0.0f }; Longer version - I'm working with the Unity engine here, although that's not important. What is - I'm trying to throw conversion between its fixed Vector2 (2 floats) and Vector3 (3 floats) and my generic Vector< class. I can't cast types directly to a generic array. using UnityEngine; public struct Vector { private readonly T[] _axes; #region Constructors public Vector(int axisCount) { this._axes = new T[axisCount]; } public Vector(T x, T y) { this._axes = new T[2] { x, y }; } public Vector(T x, T y, T z) { this._axes = new T[3]{x, y, z}; } public Vector(Vector2 vector2) { // This doesn't work this._axes = new T[2] { vector2.x, vector2.y }; } public Vector(Vector3 vector3) { // Nor does this this._axes = new T[3] { vector3.x, vector3.y, vector3.z }; } #endregion #region Properties public T this[int i] { get { return _axes[i]; } set { _axes[i] = value; } } public T X { get { return _axes[0];} set { _axes[0] = value; } } public T Y { get { return _axes[1]; } set { _axes[1] = value; } } public T Z { get { return this._axes.Length (Vector2 vector2) { Vector vector = new Vector(vector2); return vector; } public static explicit operator Vector(Vector3 vector3) { Vector vector = new Vector(vector3); return vector; } #endregion }

    Read the article

  • Is There a Better Way to Feed Different Parameters into Functions with If-Statements?

    - by FlowofSoul
    I've been teaching myself Python for a little while now, and I've never programmed before. I just wrote a basic backup program that writes out the progress of each individual file while it is copying. I wrote a function that determines buffer size so that smaller files are copied with a smaller buffer, and bigger files are copied with a bigger buffer. The way I have the code set up now doesn't seem very efficient, as there is an if loop that then leads to another if loops, creating four options, and they all just call the same function with different parameters. import os import sys def smartcopy(filestocopy, dest_path, show_progress = False): """Determines what buffer size to use with copy() Setting show_progress to True calls back display_progress()""" #filestocopy is a list of dictionaries for the files needed to be copied #dictionaries are used as the fullpath, st_mtime, and size are needed if len(filestocopy.keys()) == 0: return None #Determines average file size for which buffer to use average_size = 0 for key in filestocopy.keys(): average_size += int(filestocopy[key]['size']) average_size = average_size/len(filestocopy.keys()) #Smaller buffer for smaller files if average_size < 1024*10000: #Buffer sizes determined by informal tests on my laptop if show_progress: for key in filestocopy.keys(): #dest_path+key is the destination path, as the key is the relative path #and the dest_path is the top level folder copy(filestocopy[key]['fullpath'], dest_path+key, callback = lambda pos, total: display_progress(pos, total, key)) else: for key in filestocopy.keys(): copy(filestocopy[key]['fullpath'], dest_path+key, callback = None) #Bigger buffer for bigger files else: if show_progress: for key in filestocopy.keys(): copy(filestocopy[key]['fullpath'], dest_path+key, 1024*2600, callback = lambda pos, total: display_progress(pos, total, key)) else: for key in filestocopy.keys(): copy(filestocopy[key]['fullpath'], dest_path+key, 1024*2600) def display_progress(pos, total, filename): percent = round(float(pos)/float(total)*100,2) if percent <= 100: sys.stdout.write(filename + ' - ' + str(percent)+'% \r') else: percent = 100 sys.stdout.write(filename + ' - Completed \n') Is there a better way to accomplish what I'm doing? Sorry if the code is commented poorly or hard to follow. I didn't want to ask someone to read through all 120 lines of my poorly written code, so I just isolated the two functions. Thanks for any help.

    Read the article

< Previous Page | 82 83 84 85 86 87 88 89 90 91 92 93  | Next Page >