heterogeneous

Filter usage in shapeless, Scala

你。 提交于 2019-12-04 19:58:21
问题 It is easy to filter HList in shapeless by type: val hlist = 1 :: 2 :: "3" :: true :: false :: HNil hlist.filter[Int] But how can I make my custom type filter? I want smth like that: for example I got list of some functions: def function1(s: String) = s.toInt def function2(s: String) = s.toDouble def function3(i: Int) = i.toDouble val hflist = function1 _ :: function3 _ :: function2 _ :: HNil hflist customFilter[String] //> function1 _ :: function2 _ :: HNil So after usage of this filter,

Why are aggregate and fold two different APIs in Spark?

允我心安 提交于 2019-12-04 04:43:47
When using the Scala standard lib, I can do somthing like this: scala> val scalaList = List(1,2,3) scalaList: List[Int] = List(1, 2, 3) scala> scalaList.foldLeft(0)((acc,n)=>acc+n) res0: Int = 6 Making one Int out of many Ints. And I can do something like this: scala> scalaList.foldLeft("")((acc,n)=>acc+n.toString) res1: String = 123 Making one String out of many Ints. So, foldLeft could be either homogeneous or heterogeneous, whichever we want, it's in one API. While in Spark, if I want one Int out of many Ints, I can do this: scala> val rdd = sc.parallelize(List(1,2,3)) rdd: org.apache.spark

Using CUDA Profiler nvprof for memory accesses

感情迁移 提交于 2019-12-02 13:20:53
I'm using nvprof to get the number of global memory accesses for the following CUDA code. The number of loads in the kernel is 36 (accessing d_In array) and the number of stores in the kernel is 36+36 (for accessing d_Out array and d_rows array). So, the total number of global memory loads is 36 and the number of global memory stores is 72. However, when I profile the code with nvprof CUDA profiler, it reports the following: (Basically I want to compute the Compute to Global Memory Access (CGMA) ratio) 1 gld_transactions Global Load Transactions 6 6 6 1 gst_transactions Global Store

Extend ANTLR3 AST's

こ雲淡風輕ζ 提交于 2019-11-30 23:24:42
With ANTLR2, you could define something like this in grammar definition file: options { language = "CSharp"; namespace = "Extended.Tokens"; } tokens { TOKEN<AST=Extended.Tokens.TokenNode>; } And then, you could create a class: public class TokenNode: antlr.BaseAST { ... } Any ideea if something like this can be used (delegate class creation to AST factory instead of me doing the tree replication manually)? It's not working just by simple grammar definition copy from old to new format, and I tried to search their site and samples for somthing similar. Any hints? EDIT I'm not trying to create

Heterogeneous arguments in a Scala function

与世无争的帅哥 提交于 2019-11-30 14:01:01
How can I pass some HList as an argument? So I can make in a such way: def HFunc[F, S, T](hlist: F :: S :: T :: HNil) { // here is some code } HFunc(HList(1, true, "String")) // it works perfect But if I have a long list, and I dunno nothing about it, how can I make some operations on it? How can I pass argument and not to loose its type? It depends on your use-case. HList is useful for type-level code, so you should pass to your method not only HList , but also all necessary information like this: def hFunc[L <: HList](hlist: L)(implicit h1: Helper1[L], h2: Helper2[L]) { // here is some code

C++ How to create a heterogeneous container

此生再无相见时 提交于 2019-11-30 09:49:00
I need to store a series of data-points in the form of (name, value), where the value could take different types. I am trying to use a class template for each data-point. Then for each data-point I see, I want to create a new object and push it back into a vector. For each new type, I need to create a new class from the template first. But I can not store the objects created in any vector, since vectors expect the same type for all entries. The types I need to store can not be fitted in a inheritance hierarchy. They are unrelated. Also there can be more types created in future, and I do not

Heterogeneous arguments in a Scala function

孤街浪徒 提交于 2019-11-29 19:22:35
问题 How can I pass some HList as an argument? So I can make in a such way: def HFunc[F, S, T](hlist: F :: S :: T :: HNil) { // here is some code } HFunc(HList(1, true, "String")) // it works perfect But if I have a long list, and I dunno nothing about it, how can I make some operations on it? How can I pass argument and not to loose its type? 回答1: It depends on your use-case. HList is useful for type-level code, so you should pass to your method not only HList , but also all necessary information

C++ How to create a heterogeneous container

不问归期 提交于 2019-11-29 15:26:51
问题 I need to store a series of data-points in the form of (name, value), where the value could take different types. I am trying to use a class template for each data-point. Then for each data-point I see, I want to create a new object and push it back into a vector. For each new type, I need to create a new class from the template first. But I can not store the objects created in any vector, since vectors expect the same type for all entries. The types I need to store can not be fitted in a

Creating heterogeneous arrays in Fortran

a 夏天 提交于 2019-11-29 11:02:24
I am trying to create heterogeneous arrays that contain variables of different types, for example, [ 1.0, 7, "hi" ] . I tried to include class(*) or type(*) in the array constructor (please see the end of the following code), but gfortran5.2 simply regards it as syntax error. Is there any way to make such an array with array constructor, or is it necessary to use a different approach (e.g., define a type that contains each element separately)? More details: The following code is an example why I want to create such an array. The checktype_multi routine receives multiple arguments with the

Ad hoc polymorphism and heterogeneous containers with value semantics

三世轮回 提交于 2019-11-27 11:21:23
I have a number of unrelated types that all support the same operations through overloaded free functions (ad hoc polymorphism): struct A {}; void use(int x) { std::cout << "int = " << x << std::endl; } void use(const std::string& x) { std::cout << "string = " << x << std::endl; } void use(const A&) { std::cout << "class A" << std::endl; } As the title of the question implies, I want to store instances of those types in an heterogeneous container so that I can use() them no matter what concrete type they are. The container must have value semantics (ie. an assignment between two containers