Search Results

Search found 3425 results on 137 pages for 'polynomial math'.

Page 123/137 | < Previous Page | 119 120 121 122 123 124 125 126 127 128 129 130  | Next Page >

  • What is a good use case for static import of methods?

    - by Miserable Variable
    Just got a review comment that my static import of the method was not a good idea. The static import was of a method from a DA class, which has mostly static methods. So in middle of the business logic I had a da activity that apparently seemed to belong to the current class: import static some.package.DA.*; class BusinessObject { void someMethod() { .... save(this); } } The reviewer was not keen that I change the code and I didn't but I do kind of agree with him. One reason given for not static-importing was it was confusing where the method was defined, it wasn't in the current class and not in any superclass so it too some time to identify its definition (the web based review system does not have clickable links like IDE :-) I don't really think this matters, static-imports are still quite new and soon we will all get used to locating them. But the other reason, the one I agree with, is that an unqualified method call seems to belong to current object and should not jump contexts. But if it really did belong, it would make sense to extend that super class. So, when does it make sense to static import methods? When have you done it? Did/do you like the way the unqualified calls look? EDIT: The popular opinion seems to be that static-import methods if nobody is going to confuse them as methods of the current class. For example methods from java.lang.Math and java.awt.Color. But if abs and getAlpha are not ambiguous I don't see why readEmployee is. As in lot of programming choices, I think this too is a personal preference thing. Thanks for your response guys, I am closing the question.

    Read the article

  • Is it okay to rely on javascript for menu layout?

    - by Ryan
    I have a website template where I do not know the number of menu items or the size of the menu items that will be required. The js below works exactly the way I want it to, however this is the most js I've every written. Are there any disadvantages or potential problems with this method that I'm not aware of because I'm a js beginner? I'm currently manually setting the padding for each site. Thank you! var width_of_text = 0; var number_of_li = 0; // measure the width of each <li> and add it to the total with, increment li counter $('li').each(function() { width_of_text += $(this).width(); number_of_li++; }); // calculate the space between <li>'s so the space is equal var padding = Math.floor((900 - width_of_text)/(number_of_li - 1)); // add the padding the all but the first <li> $('li').each(function(index) { if (index !== 0) { $(this).css("padding-left", padding); } });

    Read the article

  • A good way to write unit tests

    - by bobobobo
    So, I previously wasn't really in the practice of writing unit tests - now I kind of am and I need to check if I'm on the right track. Say you have a class that deals with math computations. class Vector3 { public: // Yes, public. float x,y,z ; // ... ctors ... } ; Vector3 operator+( const Vector3& a, const Vector3 &b ) { return Vector3( a.x + b.y /* oops!! hence the need for unit testing.. */, a.y + b.y, a.z + b.z ) ; } There are 2 ways I can really think of to do a unit test on a Vector class: 1) Hand-solve some problems, then hard code the numbers into the unit test and pass only if equal to your hand and hard-coded result bool UnitTest_ClassVector3_operatorPlus() { Vector3 a( 2, 3, 4 ) ; Vector3 b( 5, 6, 7 ) ; Vector3 result = a + b ; // "expected" is computed outside of computer, and // hard coded here. For more complicated operations like // arbitrary axis rotation this takes a bit of paperwork, // but only the final result will ever be entered here. Vector3 expected( 7, 9, 11 ) ; if( result.isNear( expected ) ) return PASS ; else return FAIL ; } 2) Rewrite the computation code very carefully inside the unit test. bool UnitTest_ClassVector3_operatorPlus() { Vector3 a( 2, 3, 4 ) ; Vector3 b( 5, 6, 7 ) ; Vector3 result = a + b ; // "expected" is computed HERE. This // means all you've done is coded the // same thing twice, hopefully not having // repeated the same mistake again Vector3 expected( 2 + 5, 6 + 3, 4 + 7 ) ; if( result.isNear( expected ) ) return PASS ; else return FAIL ; } Or is there another way to do something like this?

    Read the article

  • How to map string keys to unique integer IDs?

    - by Marek
    I have some data that comes regularily as a dump from a data souce with a string natural key that is long (up to 60 characters) and not relevant to the end user. I am using this key in a url. This makes urls too long and user unfriendly. I would like to transform the string keys into integers with the following requirements: The source dataset will change over time. The ID should be: non negative integer unique and constant even if the set of input keys changes preferrably reversible back to key (not a strong requirement) The database is rebuilt from scratch every time so I can not remember the already assigned IDs and match the new data set to existing IDs and generate sequential IDs for the added keys. There are currently around 30000 distinct keys and the set is constantly growing. How to implement a function that will map string keys to integer IDs? What I have thought about: 1. Built-in string.GetHashCode: ID(key) = Math.Abs(key.GetHashCode()) is not guaranteed to be unique (not reversible) 1.1 "Re-hashing" the built-in GetHashCode until a unique ID is generated to prevent collisions. existing IDs may change if something colliding is added to the beginning of the input data set 2. a perfect hashing function I am not sure if this can generate constant IDs if the set of inputs changes (not reversible) 3. translate to base 36/64/?? does not shorten the long keys enough What are the other options?

    Read the article

  • Centering Divisions Around Zero

    - by Mark
    I'm trying to create something that sort of resembles a histogram. I'm trying to create buckets from an array. Suppose I have a random array doubles between -10 and 10; this is very simplified. I then want to specify a center point, in this case 0 and the number of buckets. If I want 4 buckets the division would be -10 to -5, -5 to 0, 0 to 5 and 5 to 10. Not that complicated right. Now if I change the min and max to -12 and -9 and as for 4 divisions its more complicated. I either want a division at -3 and 3; it is centered around 0 ; or one at -6 to 0 and 0 to 6. Its not that hard to find the division size = Math.Ceiling((Abs(Max) + Abs(Min)) / Divisions) Then you would basically have an if statement to determine whether you want it centered on 0 or on an edge. You then iterate out from either 0 or DivisionSize/2 depending on the situation. You may not ALWAYS end up with the specified number of divisions but it will be close. Then you iterate through the array and increment the bin count. Does this seem like a good way to go about this? This method would surely work but it does not seem to be the most elegant. I'm curious as to whether the creation of the bins and the counting from the list could be done in a clever class with linq in a more elegant way? Something like creating the bins and then having each bin be a property {get;} that returns list.Count(x=> x >= Lower && x < Upper).

    Read the article

  • Top n items in a List ( including duplicates )

    - by Krishnan
    Trying to find an efficient way to obtain the top N items in a very large list, possibly containing duplicates. I first tried sorting & slicing, which works. But this seems unnnecessary. You shouldn't need to sort a very large list if you just want the top 20 members. So I wrote a recursive routine which builds the top-n list. This also works, but is very much slower than the non-recursive one! Question: Which is my second routine (elite2) so much slower than elite, and how do I make it faster ? My code is attached below. Thanks. import scala.collection.SeqView import scala.math.min object X { def elite(s: SeqView[Int, List[Int]], k:Int):List[Int] = { s.sorted.reverse.force.slice(0,min(k,s.size)) } def elite2(s: SeqView[Int, List[Int]], k:Int, s2:List[Int]=Nil):List[Int] = { if( k == 0 || s.size == 0) s2.reverse else { val m = s.max val parts = s.force.partition(_==m) val whole = if( parts._1.size > 1) parts._1.tail:::parts._2 else parts._2 elite2( whole.view, k-1, m::s2 ) } } def main(args:Array[String]) = { val N = 1000000/3 val x = List(N to 1 by -1).flatten.map(x=>List(x,x,x)).flatten.view println(elite2(x,20)) println(elite(x,20)) } }

    Read the article

  • How do I call C++/CLI (.NET) DLLs from standard, unmanaged non-.NET applications?

    - by tronjohnson
    In the unmanaged world, I was able to write a __declspec(dllexport) or, alternatively, use a .DEF file to expose a function to be able to call a DLL. (Because of name mangling in C++ for the __stdcall, I put aliases into the .DEF file so certain applications could re-use certain exported DLL functions.) Now, I am interested in being able to expose a single entry-point function from a .NET assembly, in unmanaged-fashion, but have it enter into .NET-style functions within the DLL. Is this possible, in a simple and straight-forward fashion? What I have is a third-party program that I have extended through DLLs (plugins) that implement some complex mathematics. However, the third-party program has no means for me to visualize the calculations. I want to somehow take these pre-written math functions, compile them into a separate DLL (but using C++/CLI in .NET), but then add hooks to the functions so I can render what's going on under the hood in a .NET user control. I'm not sure how to blend the .NET stuff with the unmanaged stuff, or what to Google to accomplish this task. Specific suggestions with regard to the managed/unmanaged bridge, or alternative methods to accomplish the rendering in the manner I have described would be helpful. Thank you.

    Read the article

  • c++ expected constant expression

    - by cpp
    #include <iostream> #include <fstream> #include <cmath> #include <math.h> #include <iomanip> using std::ifstream; using namespace std; int main (void) { int count=0; float sum=0; float maximum=-1000000; float sumOfX; float sumOfY; int size; int negativeY=0; int positiveX=0; int negativeX=0; ifstream points; //the points to be imported from file //points.open( "data.dat"); //points>>size; //cout<<size<<endl; size=100; float x[size][2]; while (count<size) { points>>(x[count][0]); //cout<<"x= "<<(x[count][0])<<" ";//read in x value points>>(x[count][1]); //cout<<"y= "<<(x[count][1])<<endl;//read in y value count++; } This program is giving me expected constant expression error on the line where I declare float x[size][2]. why?

    Read the article

  • How to make paging start from 1 instead of 0 in ASP.NET MVC

    - by ssx
    I used the paging example of the Nerddinner tutorial. But I also wanted to add page Numbers, somehting like that: <<< 1 2 3 4 5 6 The code below works if i start my paging from 0, but not from 1. How can I fix this ? Here is my code: PaginatedList.cs public class PaginatedList<T> : List<T> { public int PageIndex { get; private set; } public int PageSize { get; private set; } public int TotalCount { get; private set; } public int TotalPages { get; private set; } public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize) { PageIndex = pageIndex; PageSize = pageSize; TotalCount = source.Count(); TotalPages = (int) Math.Ceiling(TotalCount / (double)PageSize); this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize)); } public bool HasPreviousPage { get { return (PageIndex > 0); } } public bool HasNextPage { get { return (PageIndex+1 < TotalPages); } } } UserController.cs public ActionResult List(int? page) { const int pageSize = 20; IUserRepository userRepository = new UserRepository(); IQueryable<User> listUsers = userRepository.GetAll(); PaginatedList<User> paginatedUsers = new PaginatedList<User>(listUsers, page ?? 0, pageSize); return View(paginatedUsers); } List.cshtml @if (Model.HasPreviousPage) { @Html.RouteLink(" Previous ", "PaginatedUsers", new { page = (Model.PageIndex - 1) }) } @for (int i = 1; i <= Model.TotalPages; i++) { @Html.RouteLink(@i.ToString(), "PaginatedUsers", new { page = (@i ) }) } @if (Model.HasNextPage) { @Html.RouteLink(" Next ", "PaginatedUsers", new { page = (Model.PageIndex + 1) }) }

    Read the article

  • Best way to import a pack or "system" of new classes??

    - by Joe Blow
    Here's an Advanced question for Advanced developers. So I've written a largish "subsystem". It is essentially a UIViewController called CleverViewController which is a UIViewController. Now, there are a large number of supporting classes (about ten) that do the hard work: perform math functions, image processing, purely logical functions, build images or what have you with thousands of lines of code. (To do this, I simply started a new XCode project / app "Scratchpad" which does little other than load and launch the CleverViewController. So currently it works as an app, which launches CleverViewController. The ten or so classes I mention that are part of the "subsystem" simply sit there in that project/app.) So now, we will use CleverViewController, the new technology generally, in various apps. (Or perhaps friends would want to use it, etc.) What's the best way to "do" this? Have I screwed everything up, and really it should just be ONE (pretty big) class rather than a dozen classes? (I could understand that then as I would simply add that new (big) class where needed, like adding any other class.) Do I have to make a "framework" like the Apple frameworks? (If so, what the hell are they, how do you do it, etc?!?) In fact, do you just have to lamely include all of the dozen classes and that's that (obviously perhaps putting them in a grouped subfolder). What about all the headers and so on? (Currently I just have the dozen includes in the pch file of the scratchpad project.) Shouldn't it be easy to "maintain" this "subsystem" separately and so on? I'm afraid I know nothing about this: if the answer is obvious, hit me over the head and let me know. Thank you for any info on this !

    Read the article

  • Do running times match with O(nlogn)?

    - by user472221
    Hi I have written a class(greedy strategy) that at first i used sort method which has O(nlogn) Collections.sort(array, new SortingObjectsWithProbabilityField()); and then i used the insert method of binary search tree which takes O(h) and h here is the tree height. for different n ,the running time will be : n,running time 17,515428 33,783340 65,540572 129,1285080 257,2052216 513,4299709 which I think is not correct because for increasing n , the running time should almost increase. This method will take the running time: Exponent = -1; for(int n = 2;n<1000;n+=Math.pow(2,exponent){ for (int j = 1; j <= 3; j++) { Random rand = new Random(); for (int i = 0; i < n; i++) { Element e = new Element(rand.nextInt(100) + 1, rand.nextInt(100) + 1, 0); for (int k = 0; k < i; k++) { if (e.getDigit() == randList.get(k).getDigit()) { e.setDigit(e.getDigit() + 1); } } randList.add(e); } double sum = 0.0; for (int i = 0; i < randList.size(); i++) { sum += randList.get(i).getProbability(); } for (Element i : randList) { i.setProbability(i.getProbability() / sum); } //Get time. long t2 = System.nanoTime(); GreedyVersion greedy = new GreedyVersion((ArrayList<Element>) randList); long t3 = System.nanoTime(); timeForGreedy = timeForGreedy + t3 - t2; } System.out.println(n + "," + "," + timeForGreedy/3 ); exponent++; } thanks

    Read the article

  • Problem with running totals in jquery

    - by rshivers
    I'm having an issue trying to get an accurate running total for my calculations. When you enter numbers into the input field I get an accurate total for that line item, but the grand total comes out to a higher number. Note that this is a dynamic form and that the id's will change depending on how many form fields I have added to the form. Also, I have it set to make the calculations onKeyUp for each input field instead of a calculate button. The code that calculates a single item is this: function calcLineItem(id) { var id = $(id).attr("id"); var Item1 = $("#Item1" + id).val(); var Item2 = $("#Item2" + id).val(); var Item3 = $("#Item3" + id).val(); function calcTotal(Item1, Item2, Item3){ var total; total = Math.round((Item1 * Item2) * Item3); return total; } $("#total" + id).text(calcTotal(Item1, Item2, Item3)); calcAllFields(); } This will give me the total of this particular input field. The function at the end, calcAllFields(), is supposed to do the calculations for all items in my form to give me the grand total of all input fields: function calcAllFields(id) { var id = $(id).attr("id"); $('#target1').text($("#total" + id).map(function() { var currentValue = parseFloat(document.getElementById("currentTotal").value); var newValue = parseFloat($("#total" + id).text()); var newTotal = currentValue + newValue; document.getElementById("currentTotal").value = newTotal; return newTotal; }).get().join()); } The variable currentTotal is getting its value from a hidden field on my form: <input type="hidden" id="currentTotal" value="0"> As I enter numbers a field the calculation for that line will be accurate, but the grand total will be inaccurate because the value for currentTotal will continue to increment with every key stroke I make in the input field. Any ideas on how to avoid this from happening?

    Read the article

  • segmentation fault when using pointer to pointer

    - by user3697730
    I had been trying to use a pointer to pointer in a function,but is seems that I am not doing the memory allocation correctly... My code is: #include<stdio.h> #include<math.h> #include<ctype.h> #include<stdlib.h> #include<string.h> struct list{ int data; struct list *next; }; void abc (struct list **l,struct list **l2) { *l2=NULL; l2=(struct list**)malloc( sizeof(struct list*)); (*l)->data=12; printf("%d",(*l)->data); (*l2)->next=*l2; } int main() { struct list *l,*l2; abc(&l,&l2); system("pause"); return(0); } This code compiles,but I cannot run thw program..I get a segmentation fault..What should I do?Any help would be appreciated!

    Read the article

  • pass variable by reference within class? in php

    - by user151841
    I'm working on a hex color class where you can change the color values of any hex code color. In my example, I haven't finished the hex math, but it's not completely relevant to what I'm explaining here. Naively, I wanted to start to do something that I don't think can be done. I wanted to pass object properties in a method call. Is this possible? class rgb { private $r; private $b; private $g; public function __construct( $hexRgb ) { $this->r = substr($hexRgb, 0, 2 ); $this->g = substr($hexRgb, 2, 2 ); $this->b = substr($hexRgb, 4, 2 ); } private function add( & $color, $amount ) { $color += amount; // $color should be a class property, $this->r, etc. } public function addRed( $amount ) { self::add( $this->r, $amount ); } public function addGreen( $amount ) { self::add( $this->g, $amount ); } public function addBlue( $amount ) { self::add( $this->b, $amount ); } } If this is not possible in PHP, what is this called and in what languages is it possible? I know I could do something like public function add( $var, $amount ) { if ( $var == "r" ) { $this->r += $amount } else if ( $var == "g" ) { $this->g += $amount } ... } But I want to do it this cool way.

    Read the article

  • How to calculate how many business days are between two dates?

    - by mystify
    A friend asked me yesterday if this was possible on the iPhone. I took a look at NSCalendar and all the related Classes but couldn't find a solution to this. So I thought about this approach: If I had two dates dateA and dateB, I would have to make a for-loop and iterate over every single day in this interval. Then I would count the business days monday until friday, and return the result. Then I went to bed, and I woke up with this probably much better idea: I need to know what day is it when I start. Lets say it's thursday. And then I must know how many days are in that interval. The last part is not hard to figure out. For the first part, I have no clue yet, but I believe there's an day of week value in NSCalendar. With that, I could do some simple math to calculate the amount of business days. Did anyone do that already on the iPhone?

    Read the article

  • Which Android hardware devices should I test on? [closed]

    - by Tchami
    Possible Duplicate: What hardware devices do you test your Android apps on? I'm trying to compile a list of Android hardware devices that it would make sense to buy and test against if you want to target an as broad audience as possible, while still not buying every single Android device out there. I know there's a lot of information regarding screen sizes and Android versions available elsewhere, but: when developing for Android it's not terribly useful to know if the screen size of a device is 480x800 or 320x240, unless you feel like doing the math to convert that into Android "units" (i.e. small, normal, large or xlarge screens, and ldpi, mdpi, hdpi or xhdpi densities). Even knowing the dimensions of a device, you cannot be sure of the actual Android units as there's some overlap, see Range of screens supported in the Android documentation Taking into account the distribution of Platform versions and Screen Sizes and Densities, below is my current list based on information from the Wikipedia article on Comparison of Android devices. I'm fairly sure the information in this list is correct, but I'd welcome any suggestions/changes. Phones | Model | Android Version | Screen Size | Density | | HTC Wildfire | 2.1/2.2 | Normal | mdpi | | HTC Tattoo | 1.6 | Normal | mdpi | | HTC Hero | 2.1 | Normal | mdpi | | HTC Legend | 2.1 | Normal | mdpi | | Sony Ericsson Xperia X8 | 1.6/2.1 | Normal | mdpi | | Motorola Droid | 2.0-2.2 | Normal | hdpi | | Samsung Galaxy S II | 2.3 | Normal | hdpi | | Samsung Galaxy Nexus | 4.0 | Normal | xhdpi | | Samsung Galaxy S III | 4.0 | Normal | xhdpi | **Tablets** | Model | Android Version | Screen Size | Density | | Samsung Galaxy Tab 7" | 2.2 | Large | hdpi | | Samsung Galaxy Tab 10" | 3.0 | X-Large | mdpi | | Asus Transformer Prime | 4.0 | X-Large | mdpi | | Motorola Xoom | 3.1/4.0 | X-Large | mdpi | N.B.: I have seen (and read) other posts on SO on this subject, e.g. Which Android devices should I test against? and What hardware devices do you test your Android apps on? but they don't seem very canonical. Maybe this should be marked community wiki?

    Read the article

  • What does the Asterisk * mean in Objective-C?

    - by Thanks
    Is it true, that the Asterisk always means "Hey, that is a pointer!" And an Pointer always holds an memory adress? (Yes I know for the exception that a * is used for math operation) For Example: NSString* myString; or SomeClass* thatClass; or (*somePointerToAStruct).myStructComponent = 5; I feel that there is more I need to know about the Asterirsk (*) than that I use it when defining an Variable that is a pointer to a class. Because sometimes I already say in the declaration of an parameter that the Parameter variable is a pointer, and still I have to use the Asterisk in front of the Variable in order to access the value. That recently happened after I wanted to pass a pointer of an struct to a method in a way like [myObj myMethod:&myStruct], I could not access a component value from that structure even though my method declaration already said that there is a parameter (DemoStruct*)myVar which indeed should be already known as a pointer to that demostruct, still I had always to say: "Man, compiler. Listen! It IIISSS a pointer:" and write: (*myVar).myStructComponentX = 5; I really really really do not understand why I have to say that twice. And only in this case. When I use the Asterisk in context of an NSString* myString then I can just access myString however I like, without telling the compiler each time that it's a pointer. i.e. like using *myString = @"yep". It just makes no sense to me.

    Read the article

  • 3x3 array = 10 numbers

    - by user1708505
    i have this code #include <math.h> #include <stdio.h> const int n = 3; const int s = 3; int getm(int mat[n][s]); int printm(int mat[n][s]); int main() { int m[n][s]; getm(m); printm(m); return 0; } int getm(int mat[n][s]) { for(int x = 0;x < n;x++) { for (int y = 0;y<s;y++) { scanf("%i ", &mat[x][y]); } } return 0; } int printm(int mat[n][s]) { for(int x = 0;x<n;x++) { for(int y = 0;y<s;y++) { printf("%i ", mat[x][y]); if(y==(s-1)) { printf("\n"); } } } } which shoud ask for 9 numbers to make a 3x3 matrix array, but it actually asks for 10 numbers, printm is working well - printing only 9 numbers. Where is error?

    Read the article

  • A loop (while/foreach) with "offset" wrapping and

    - by DarkGhostHunter
    After applying what wrapping objects using math operator, I just tought it will be over. But no. By far. <?php $faces= array( 1 => '<div class="block">happy</div>', 2 => '<div class="block">sad</div>', (sic) 21 => '<div class="block">angry</div>' ); $i = 1; foreach ($faces as $face) { echo $face; if ($i == 3) echo '<div class="block">This is and ad</div>'; if ($i % 3 == 0) { echo "<br />"; // or some other wrapping thing } $i++; } ?> In the code I have to put and ad after the second one, becoming by that the third object. And then wrap the three all in a <div class="row"> (a br after won't work out by design reasons). I thought I will going back to applying a switch, but if somebody put more elements in the array that the switch can properly wrap, the last two remaining elements are wrapped openly. Can i add the "ad" to the array in the third position? That would make things simplier, only leaving me with guessing how to wrap the first and the third, the fourth and the sixth, an so on.

    Read the article

  • Python - creating a list with 2 characteristics bug

    - by user2733911
    The goal is to create a list of 99 elements. All elements must be 1s or 0s. The first element must be a 1. There must be 7 1s in total. import random import math import time # constants determined through testing generation_constant = 0.96 def generate_candidate(): coin_vector = [] coin_vector.append(1) for i in range(0, 99): random_value = random.random() if (random_value > generation_constant): coin_vector.append(1) else: coin_vector.append(0) return coin_vector def validate_candidate(vector): vector_sum = sum(vector) sum_test = False if (vector_sum == 7): sum_test = True first_slot = vector[0] first_test = False if (first_slot == 1): first_test = True return (sum_test and first_test) vector1 = generate_candidate() while (validate_candidate(vector1) == False): vector1 = generate_candidate() print vector1, sum(vector1), validate_candidate(vector1) Most of the time, the output is correct, saying something like [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0] 7 True but sometimes, the output is: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] 2 False What exactly am I doing wrong?

    Read the article

  • C non-trivial constants

    - by user525869
    I want to make several constants in C with #define to speed up computation. Two of them are not simply trivial numbers, where one is a right shift, the other is a power. math.h in C gives the function pow() for doubles, whereas I need powers for integers, so I wrote my own function, ipow, so I wouldn't need to be casting everytime. My question is this: One of the #define constants I want to make is a power, say ipow(M, T), where M and T were also #define constants. ipow is a function in the actual code, so this actually seems to slows things down when I run the code (is it running ipow everytime the constant is mentioned?). However, when I ues the built in pow function and just do (int)pow(M,T), the code is sped up. I'm confused as to why this is, since the ipow and pow functions are just as fast. On a more general note, can I define constants using #define using functions inside the actual code? The above example has me confused on whether this speeds things up or actually slows things down.

    Read the article

  • Uncaught TypeError: Property 'dist2' of object [object Object] is not a function

    - by Radu Vlad
    I have this functions that should return me the distance from point p to segment line v-w. The problem i have is after some time i receive the following error: Uncaught TypeError: Property 'dist2' of object [object Object] is not a function. I receive it in distToSegmentSquared directly,not even calling the function dist2().Is it any other dist2() anywhere in jquery?I found none... function sqr(x) { return x * x; } function dist2(v, w) { console.log(v); console.log(w); return sqr(v.x - w.x) + sqr(v.y - w.y); } function distToSegmentSquared(p, v, w) { var l2 = dist2(v, w); if (l2 == 0) return dist2(p, v); var t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2; if (t < 0) return dist2(p, v); if (t > 1) return dist2(p, w); return dist2(p, {x: v.x + t * (w.x - v.x), y: v.y + t * (w.y - v.y)}); } function distToSegment(p, v, w) { return Math.sqrt(distToSegmentSquared(p, v, w)); } The values that are given in for that error are: p: Object x: 461 y: 333 v: Object x: 80 y: 120 w: Object x: 260 y: 120

    Read the article

  • Tigther code - javascript object array

    - by Scott Silvi
    Inside the callback of a $.getJSON call, I have the code outlined below. The first for block aggregates 'total' & assigns values to sov[i]. The map function calculates the percentage of total. I then instantiate a variable called sovData. With the jQuery Flot graph, any objects that are empty aren't added to the pie chart, so this works for up to 7 different slices/datasets. What I'd like to do is only initialize the ones I need (e.g. sovData would have up to 'howMany - 1' (kws.length -1 ) objects inside of it, likely via something similar to dashboards[i] & sov[i]. How would I do this? Code: var sov = [], howMany = kws.length, total = 0, i = 0; for ( i; i < howMany; i++) { total += sov[ i ] = +parseInt(data.sov['sov' + ( i+1 ) ],10) || 0; } var dashboards = data.dashboards; sov = $.map( sov, function(v) { var s = Math.round( ( (v / total) * 10e3 ) / 100); return s < 1 ? 1 : s; }); var sovData = [{ label : dashboards[0], data : sov[0] }, { label : dashboards[1], data : sov[1] }, { label : dashboards[2], data : sov[2] }, { label : dashboards[3], data : sov[3] }, { label : dashboards[4], data : sov[4] }, { label : dashboards[5], data : sov[5] }, { label : dashboards[6], data : sov[6] } ]

    Read the article

  • PulseAudio on Cygwin: Failed to create secure directory: Unknown error 13

    - by Nithin
    I am unable to run PulseAudio on Cygwin. Operating System: Windows 8 Pro 64 bit Cygwin Setup.exe Version: 2.831 (64 bit) PulseAudio Version: 2.1-1 When I run: pulseaudio -vv this is the output: D: [(null)] core-util.c: setpriority() worked. I: [(null)] core-util.c: Successfully gained nice level -11. I: [(null)] main.c: This is PulseAudio 2.1 D: [(null)] main.c: Compilation host: x86_64-unknown-cygwin D: [(null)] main.c: Compilation CFLAGS: -ggdb -O2 -pipe -fdebug-prefix-map=/usr/src/ports/pulseaudio/pulseaudio-2.1-1/build=/usr/src/debug/pulseaudio-2.1-1 -fdebug-prefix-map=/usr/src/ports/pulseaudio/pulseaudio-2.1-1/src/pulseaudio-2.1=/usr/src/debug/pulseaudio-2.1-1 -Wall -W -Wextra -Wno-long-long -Wvla -Wno-overlength-strings -Wunsafe-loop-optimizations -Wundef -Wformat=2 -Wlogical-op -Wsign-compare -Wformat-security -Wmissing-include-dirs -Wformat-nonliteral -Wpointer-arith -Winit-self -Wdeclaration-after-statement -Wfloat-equal -Wmissing-prototypes -Wredundant-decls -Wmissing-declarations -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-align -Wstrict-aliasing -Wwrite-strings -Wno-unused-parameter -ffast-math -Wp,-D_FORTIFY_SOURCE=2 -fno-common -fdiagnostics-show-option D: [(null)] main.c: Running on host: CYGWIN_NT-6.2 x86_64 1.7.25(0.270/5/3) 2013-08-31 20:37 D: [(null)] main.c: Found 4 CPUs. I: [(null)] main.c: Page size is 65536 bytes D: [(null)] main.c: Compiled with Valgrind support: no D: [(null)] main.c: Running in valgrind mode: no D: [(null)] main.c: Running in VM: no D: [(null)] main.c: Optimized build: yes D: [(null)] main.c: FASTPATH defined, only fast path asserts disabled. I: [(null)] main.c: Machine ID is 5d8bd07cb924c67197184e42527f2603. E: [(null)] core-util.c: Failed to create secure directory: Unknown error 13 When I instead run pulseaudio -vv --start the output is this: E: [autospawn] core-util.c: Failed to create secure directory: Unknown error 13 W: [autospawn] lock-autospawn.c: Cannot access autospawn lock. E: [(null)] main.c: Failed to acquire autospawn lock When I ran strace pulseaudio -vv, the red-colored lines in the output were: 28 1637050 [main] pulseaudio 5104 fhandler_pty_slave::write: (669): pty output_mutex(0xBC) released 26 1637076 [main] pulseaudio 5104 write: 7 = write(2, 0x3FE171079, 7) 42 1637118 [main] pulseaudio 5104 fhandler_pty_slave::write: pty0, write(0x60003BB40, 51) 27 1637145 [main] pulseaudio 5104 fhandler_pty_slave::write: (654): pty output_mutex (0xBC): waiting -1 ms 23 1637168 [main] pulseaudio 5104 fhandler_pty_slave::write: (654): pty output_mutex: acquired Failed to create secure directory: Unknown error 13 21 1637189 [main] pulseaudio 5104 fhandler_pty_slave::write: (669): pty output_mutex(0xBC) released 29 1637218 [main] pulseaudio 5104 write: 51 = write(2, 0x60003BB40, 51) 46 1637264 [main] pulseaudio 5104 fhandler_pty_slave::write: pty0, write(0x3FE17106F, 4) 24 1637288 [main] pulseaudio 5104 fhandler_pty_slave::write: (654): pty output_mutex (0xBC): waiting -1 ms 24 1637312 [main] pulseaudio 5104 fhandler_pty_slave::write: (654): pty output_mutex: acquired Please can someone help me?

    Read the article

  • SAS Expanders vs Direct Attached (SAS)?

    - by jemmille
    I have a storage unit with 2 backplanes. One backplane holds 24 disks, one backplane holds 12 disks. Each backplane is independently connected to a SFF-8087 port (4 channel/12Gbit) to the raid card. Here is where my question really comes in. Can or how easily can a backplane be overloaded? All the disks in the machine are WD RE4 WD1003FBYX (black) drives that have average writes at 115MB/sec and average read of 125 MB/sec I know things would vary based on the raid or filesystem we put on top of that but it seems to be that a 24 disk backplane with only one SFF-8087 connector should be able to overload the bus to a point that might actually slow it down? Based on my math, if I had a RAID0 across all 24 disks and asked for a large file, I should, in theory should get 24*115 MB/sec wich translates to 22.08 GBit/sec of total throughput. Either I'm confused or this backplane is horribly designed, at least in a perfomance environment. I'm looking at switching to a model where each drive has it's own channel from the backplane (and new HBA's or raid card). EDIT: more details We have used both pure linux (centos), open solaris, software raid, hardware raid, EXT3/4, ZFS. Here are some examples using bonnie++ 4 Disk RAID-0, ZFS WRITE CPU RE-WRITE CPU READ CPU RND-SEEKS 194MB/s 19% 92MB/s 11% 200MB/s 8% 310/sec 194MB/s 19% 93MB/s 11% 201MB/s 8% 312/sec --------- ---- --------- ---- --------- ---- --------- 389MB/s 19% 186MB/s 11% 402MB/s 8% 311/sec 8 Disk RAID-0, ZFS WRITE CPU RE-WRITE CPU READ CPU RND-SEEKS 324MB/s 32% 164MB/s 19% 346MB/s 13% 466/sec 324MB/s 32% 164MB/s 19% 348MB/s 14% 465/sec --------- ---- --------- ---- --------- ---- --------- 648MB/s 32% 328MB/s 19% 694MB/s 13% 465/sec 12 Disk RAID-0, ZFS WRITE CPU RE-WRITE CPU READ CPU RND-SEEKS 377MB/s 38% 191MB/s 22% 429MB/s 17% 537/sec 376MB/s 38% 191MB/s 22% 427MB/s 17% 546/sec --------- ---- --------- ---- --------- ---- --------- 753MB/s 38% 382MB/s 22% 857MB/s 17% 541/sec Now 16 Disk RAID-0, it's gets interesting WRITE CPU RE-WRITE CPU READ CPU RND-SEEKS 359MB/s 34% 186MB/s 22% 407MB/s 18% 1397/sec 358MB/s 33% 186MB/s 22% 407MB/s 18% 1340/sec --------- ---- --------- ---- --------- ---- --------- 717MB/s 33% 373MB/s 22% 814MB/s 18% 1368/sec 20 Disk RAID-0, ZFS WRITE CPU RE-WRITE CPU READ CPU RND-SEEKS 371MB/s 37% 188MB/s 22% 450MB/s 19% 775/sec 370MB/s 37% 188MB/s 22% 447MB/s 19% 797/sec --------- ---- --------- ---- --------- ---- --------- 741MB/s 37% 376MB/s 22% 898MB/s 19% 786/sec 24 Disk RAID-1, ZFS WRITE CPU RE-WRITE CPU READ CPU RND-SEEKS 347MB/s 34% 193MB/s 22% 447MB/s 19% 907/sec 347MB/s 34% 192MB/s 23% 446MB/s 19% 933/sec --------- ---- --------- ---- --------- ---- --------- 694MB/s 34% 386MB/s 22% 894MB/s 19% 920/sec 28 Disk RAID-0, ZFS 32 Disk RAID-0, ZFS 36 Disk RAID-0, ZFS More details: Here is the exact unit: http://www.supermicro.com/products/chassis/4U/847/SC847E1-R1400U.cfm

    Read the article

< Previous Page | 119 120 121 122 123 124 125 126 127 128 129 130  | Next Page >