infinite

Replace Inf in R data.table / Show number of Inf in colums

点点圈 提交于 2019-12-11 04:09:06
问题 I can't figure out how to use an is.na(x) like function for infinite numbers in R with a data table or show per column how many Inf's there are: colSums(is.infinite(x)) I use the following example data set: DT <- data.table(a=c(1/0,1,2/0),b=c("a","b","c"),c=c(1/0,5,NA)) DT a b c 1: Inf a Inf 2: 1 b 5 3: Inf c NA colSums(is.na(DT)) a b c 0 0 1 colSums(is.infinite(DT)) Error in is.infinite(DT) : default method not implemented for type 'list' DT[is.na(DT)] <- 100 DT a b c 1: Inf a Inf 2: 1 b 5 3

Is it possible to construct an “infinite” string?

爱⌒轻易说出口 提交于 2019-12-10 21:29:24
问题 Is there any real sequence of characters that always compares greater than any other string? My first thought was that a string constructed like so: std::basic_string<T>(std::string::max_size(), std::numeric_limits<T>::max()) Would do the trick, provided that the fact that it would almost definitely fail to work isn't such a big issue. So I presume this kind of hackery could only be accomplished in Unicode, if it can be accomplished at all. I've never heard of anything that would indicate

Infinite self-referencing list

蓝咒 提交于 2019-12-10 18:46:57
问题 Problem I'm trying to implement the modified Dragon Curve from AoC Day 16 as an infinite list in Haskell. The list is composed of True and False . We start with some list s0 : s1 = s0 ++ [False] ++ (map not . reverse) s0 s2 = s1 ++ [False] ++ (map not . reverse) s1 s3 = s2 ++ [False] ++ (map not . reverse) s2 Generally sn = s(n-1) ++ [0] ++ (map not . reverse) s(n-1) = s0 ++ [0] ++ (f s0) ++ [0] ++ (f (s0 ++ [0] ++ (f s0))) ++ ... where f = (map not . reverse) Attempted Implementation I can

How do make an infinite jscrollpane?

我怕爱的太早我们不能终老 提交于 2019-12-10 10:49:36
问题 I've implemented drag scroll before, but what's the best way to go about creating an infinite scroll pane? Of course there won't be any scrollbars and I will implement drag scroll. What I am trying to do is implement dynamic loading on an infinite surface. EDIT Of course it wouldn't actually be infinite. I am asking how to fake it. 回答1: You could use JScrollPane.getViewport() to get the JViewport and add a ChangeListener to it. The JViewport will alert your listener when the size or, more

Rare infinite loop in code, don't want to wait for it to happen again

为君一笑 提交于 2019-12-10 09:52:54
问题 Ok, so I've got a genetic algorithm running in netbeans, and its been running for like 5 hours and seems to have entered an infinite loop. Is there any way that I can attach a debugger to it? or at least get some clue as to where it is in the code? I'd rather not sit around for another 5 hours while I wait for it to happen again. 回答1: A simple way to get some basic information from your running program is to run jstack on it, it will print stack traces of all threads in your code. Do that

Passing variable through URL with angular js

余生长醉 提交于 2019-12-10 03:47:16
问题 I am using angular to make an e-commerce, and I'm setting an infinite scroll to the products list page. Everything worked fine, but I want to use the URL to set the page, so the user can access an specific page through URL. how do I set a variable like "pageNumber" in the URL with angular? like "www.page.com/page/2/"(I want to get the number 2 and pass it to the store controller) Here's the code I have now (function() { var app = angular.module('concurseirosUnidos', ['store-directives',

Is equality testing possible between two infinite data structure in Haskell?

Deadly 提交于 2019-12-10 03:43:59
问题 In a project I'm working on, data of a certain type may sometimes contain themselves in it. For example, data Example = Apple Int | Pear Int Example a = Pear 10 a b = Pear 10 b As a programmer I know that a and b are equal, but when I actually test equality between them it would infinite loop because their values need to be evaluated for comparison. Is there any other way to do equality testing between data like these? Or is there a way to avoid problems like these? 回答1: In general: no. This

Deliberately defining infinite type in haskell

笑着哭i 提交于 2019-12-09 15:25:22
问题 I want to define what seems to require an infinite type. Required : a function "eat" that eats all it's arguments except "3" for which it returns 3 eat 3 = 3 eat x = eat So basically an arbitrary expression like "eat (+) foldl (Just 5) 3" evaluates to 3. But the problem here is the type of eat. What should that be? The closest i got to a running code was : newtype Rec = MakeRec (Int -> Rec) eat :: Int -> Rec eat x = MakeRec eat instance Show Rec where show _ = "EAT" This works okay for "eat 6

why does an infinite loop of the unintended kind increase the CPU use?

我怕爱的太早我们不能终老 提交于 2019-12-09 15:12:18
问题 I know an infinite loop to the unintended kind usually causes a high CPU usage. But, I don't quite understand why. Can anyone explain that to me? 回答1: The CPU cannot do anything else while it's executing that loop (which never ends). Even if you're using a pre-emptive multi-tasking system (so that infinite loop will only clog forever its own process or thread), the loop will "eat" its time slice each time the OS's pre-emptive scheduler hands it the CPU for the next slice -- doing nothing, but

How can I use the Haskell timeout function (in System.Timeout) to halt runaway computations?

坚强是说给别人听的谎言 提交于 2019-12-08 17:34:48
问题 The timeout function in System.Timeout sometimes fails to halt an infinite computation. For example, timeout 1000 $ print $ length [0..] returns Nothing as expected because the timeout interrupts the infinite computation. But timeout 1000 $ print $ length $ cycle [1,2,3] loops forever. This is on a Mac, using ghc or ghci 8.6.4. I expect the second example to behave like the first, interrupting the infinite computation after 1 millisecond and returning Nothing . Instead, the second example