ref

Fast subsetting of a matrix in R

情到浓时终转凉″ 提交于 2019-12-10 05:43:05
问题 I face the following problem: I need many subsets of a big matrix. Actually I just need views as input for another function f(), so I don't need to change the values. However it seems, that R is terribly slow for this task, or I'm doing something wrong (which seems more likely). The toy example illustrates how much time it takes just to select the columns, and then use them in another function (in this toy example the primitive function sum()). As 'benchmark' I also test the calculation time

Unsubscribe from delegate passed through ref keyword to the subscription method?

戏子无情 提交于 2019-12-08 15:59:03
问题 I've got the following class: public class Terminal : IDisposable { readonly List<IListener> _listeners; public Terminal(IEnumerable<IListener> listeners) { _listeners = new List<IListener>(listeners); } public void Subscribe(ref Action<string> source) { source += Broadcast; //Store the reference somehow? } void Broadcast(string message) { foreach (var listener in _listeners) listener.Listen(message); } public void Dispose() { //Unsubscribe from all the stored sources? } } I've searched for a

pass ref to a class component with React.cloneElement and render prop

余生颓废 提交于 2019-12-07 07:37:12
问题 I'm writing a component that handle some internal state according to a ref of it's child (a mouse event related to that child's ref for example). This component is using a render-prop to pass on the relevant piece of state to it's child, and render the child with the ref attached via React.cloneElement util. The problem is that when the child is a class component, for some reason the ref is not available, and i can't find a way to render it as it's a react element object with a type of

How can I emit a dynamic method returning a ref?

筅森魡賤 提交于 2019-12-07 03:10:00
问题 I'm navigating the ins and outs of ref returns, and am having trouble emitting a dynamic method which returns by ref. Handcrafted lambdas and existing methods work as expected: class Widget { public int Length; } delegate ref int WidgetMeasurer(Widget w); WidgetMeasurer GetMeasurerA() { return w => ref w.Length; } static ref int MeasureWidget(Widget w) => ref w.Length; WidgetMeasurer GetMeasurerB() { return MeasureWidget; } But emitting a dynamic method fails. Note : I'm using Sigil here.

Refs for dynamically generated components in React?

自古美人都是妖i 提交于 2019-12-06 11:29:26
The code below is a minimal working example to explain my problem. This code generates 3 Note components using Array.map and when you hit enter in them it empties the statically generated Note component above them using a ref to its DOM element. What I want to do is instead have the Note you hit enter in empty itself. I think this would require generating a dynamic array containing {id, ref} for each Note, so I could pass the Note id to handleKeyDown then search the refs array for that id and use the corresponding ref to change the DOM element. But I'm having trouble figuring out how to

新的bind库 (bi-bind), 对boost::bind的精简

陌路散爱 提交于 2019-12-06 10:07:25
boost中有一个bind库, 可以说是一个最为实用的tools了, 但是它与boost结合的有些紧密,而且其中的一些功能并不是很常用,就算将它bcp出独立的库也是一个不小的负担。如果在你的项目中不打算有boost库的痕迹但是又想使用bind的强大功能,那就来看看它吧。 一个一个超小型的bind库, 它实现了大部分boost::bind的功能, 只是将名字空间由boost 变换为 bi 。如果使用了一般的使用中通常可以将 boost::bind(my_fun(), _1,_2)(234, "hello world"); //形式替换为 bi::bind(my_fun(), _1, _2)(234, "hello world"); 既可完成编译,如果使用了名字空间,那就只需要将 using namespace boost 替换为 using namespafce bi 即可完成转化。 同boost::bind一样,它支持任意的函数对象,函数,函数指针,和成员函数指针,它还能将任何参数绑定为一个特定的值,或者将输入的参数发送到任意的位置。 从使用者方向看只是将bind 从boost名字空间移动到了 bi名字空间, 如果使用了 using namespace boost;的方式引入的boost::bind, 那么你很幸运!只要改成using namespace bi;就完成了。

In react how to get ref of first element that's rendered from Map

雨燕双飞 提交于 2019-12-05 18:43:39
I have a requirement to show thumbnails of videos(cards) in several rows and focus on the very first thumbnail. I did the display using Nested Map. The code basically iterates over a videos array and returns videos in several rows. How do we focus on the first element that renders? I think we need to get ref of the first element to focus. But how do we set ref here and reference it in another function? const CategoryGrid = props => { return ( <HotKeys handlers={handlers}> <div className="grid-container"> <p className="title"> {props.title.toUpperCase()} </p> <div className="grid"> { props

pass ref to a class component with React.cloneElement and render prop

試著忘記壹切 提交于 2019-12-05 11:33:16
I'm writing a component that handle some internal state according to a ref of it's child (a mouse event related to that child's ref for example). This component is using a render-prop to pass on the relevant piece of state to it's child, and render the child with the ref attached via React.cloneElement util. The problem is that when the child is a class component, for some reason the ref is not available, and i can't find a way to render it as it's a react element object with a type of function (after i clone it of course). But if the child is just a DOM node like a div for example, it is

Boxing and unboxing when using out and ref parameters

风格不统一 提交于 2019-12-05 10:33:10
问题 Does boxing/unboxing occur when a method accepts an out/ref parameter of a ValueType? 回答1: For ref Keyword Its already mentioned on MSDN that : Do not confuse the concept of passing by reference with the concept of reference types. The two concepts are not the same. A method parameter can be modified by ref regardless of whether it is a value type or a reference type. There is no boxing of a value type when it is passed by reference. As for out keyword: The out keyword causes arguments to be

Fast subsetting of a matrix in R

淺唱寂寞╮ 提交于 2019-12-05 10:27:52
I face the following problem: I need many subsets of a big matrix. Actually I just need views as input for another function f(), so I don't need to change the values. However it seems, that R is terribly slow for this task, or I'm doing something wrong (which seems more likely). The toy example illustrates how much time it takes just to select the columns, and then use them in another function (in this toy example the primitive function sum()). As 'benchmark' I also test the calculation time against summing up the whole matrix, which is surprisingly faster. I also experimented with the package