当我使用大型稀疏矩阵时,最好使用CCS,CRS等压缩矩阵.
我尝试使用ScalaNLP,la4j,colc来计算100,000*100,000稀疏矩阵.有一些问题.
微风(ScalaNLP/Scalala)
CSCMatrix类型可以有100,000*100,000大小.CSCMatrix与CSCMatrix一样csc1 :* csc2.la4j
COLC
要计算大型稀疏矩阵,我可以使用哪个库?你能告诉我这个例子吗?
我遇到路径依赖类型和模式匹配问题:
trait View[A]
trait Foo {
type Bar
def defaultBar: Bar
}
trait Baz extends Foo {
def view(init: Bar): View[Bar]
}
trait Test {
val foo: Foo
def bar: foo.Bar = foo.defaultBar
def test(): Option[View[foo.Bar]] =
foo match {
case b: Baz => Some(b.view(bar))
case _ => None
}
}
Run Code Online (Sandbox Code Playgroud)
失败的原因是scalac不识别foo用b.因此,它只适用于两个演员:
case b: Baz => Some(b.view(bar.asInstanceOf[b.Bar]).asInstanceOf[View[foo.Bar]])
Run Code Online (Sandbox Code Playgroud)
当然必须有一个干净的方法来避免演员阵容?
我对 sbt 和 Typesafe 存储库有一个奇怪的问题:
[info] Resolving com.typesafe.play#play-json_2.10;2.2.0 ...
[warn] module not found: com.typesafe.play#play-json_2.10;2.2.0
[warn] ==== local: tried
[warn] /Users/hhrutz/.ivy2/local/com.typesafe.play/play-json_2.10/2.2.0/ivys/ivy.xml
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/com/typesafe/play/play-json_2.10/2.2.0/play-json_2.10-2.2.0.pom
[warn] ==== Typesafe Releases: tried
[warn] https://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-json_2.10/2.2.0/play-json_2.10-2.2.0.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.typesafe.play#play-json_2.10;2.2.0: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
sbt.ResolveException: unresolved dependency: com.typesafe.play#play-json_2.10;2.2.0: not found
Run Code Online (Sandbox Code Playgroud)
我可以从http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-json_2.10/2.2.0/手动下载 .pom 和 .jar,所以服务器肯定在那里。
这可能是sbt问题吗?如果它肯定有正确的 URL,它为什么会失败的任何线索?
如何确保最新的测试不能并行运行?在0.12之前,我有一个sbt设置:
parallelExecution in Test := false
Run Code Online (Sandbox Code Playgroud)
较新的版本引入了一些复杂的机制.这个更简单,旧的方式仍然适用于0.13吗?
在测试期间,我不希望任何东西并行运行.
我有一个F-bounded类型Sys:
trait Sys[S <: Sys[S]]
Run Code Online (Sandbox Code Playgroud)
以及将其作为类型参数的一些特征:
trait Foo[S <: Sys[S]]
Run Code Online (Sandbox Code Playgroud)
假设我有一个方法可以调用Foo:
def invoke[S <: Sys[S]](foo: Foo[S]) = ()
Run Code Online (Sandbox Code Playgroud)
假设我有一个模型更新类型,以及一个带有以下内容的子类型Foo:
sealed trait Update
case class Opened[S <: Sys[S]](foo: Foo[S]) extends Update
Run Code Online (Sandbox Code Playgroud)
用于注册模型观察者的辅助函数:
def observe(pf: PartialFunction[Update, Unit]) = ()
Run Code Online (Sandbox Code Playgroud)
现在以下失败:
observe {
case Opened(foo) => invoke(foo)
}
Run Code Online (Sandbox Code Playgroud)
同
<console>:16: error: inferred type arguments [Any] do not conform to method invoke's
type parameter bounds [S <: Sys[S]]
case Opened(foo) => invoke(foo)
^
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决部分功能,如Sys,Foo …
scala pattern-matching existential-type type-bounds bounded-quantification
我试图了解scaladoc 宏 是如何工作的。例如
/** $DESCR
*
* @define DESCR
* A `Consumer` simplifies resource management...
*
* @define KEY
* the key type
*
* @define VALUE
* the value type
*/
object Consumer {
/** Creates a new consumer
*
* @tparam A $KEY
* @tparam B $VALUE
*/
def apply[A, B](): Consumer[A, B] = ???
}
/** $DESCR
*
* @tparam A $KEY
* @tparam B $VALUE
*/
trait Consumer[-A, +B]
Run Code Online (Sandbox Code Playgroud)
我的印象是,这应该生成一个文档,其中包含 trait 和伴随对象的描述A …
要将 Scala 嵌入为“脚本语言”,我需要能够将文本片段编译为简单的对象,例如Function0[Unit]可以序列化到磁盘和从磁盘反序列化,并且可以加载到当前运行时并执行的对象。
我该怎么办?
比如说,我的文本片段是(纯假设的):
Document.current.elements.headOption.foreach(_.open())
Run Code Online (Sandbox Code Playgroud)
这可能包含在以下完整文本中:
package myapp.userscripts
import myapp.DSL._
object UserFunction1234 extends Function0[Unit] {
def apply(): Unit = {
Document.current.elements.headOption.foreach(_.open())
}
}
Run Code Online (Sandbox Code Playgroud)
接下来是什么?我应该用它IMain来编译这段代码吗?我不想使用普通的解释器模式,因为编译应该是“上下文无关的”,而不是累积请求。
我需要阻止编译的是我猜二进制类文件?在这种情况下,序列化是直接的(字节数组)。然后我将如何将该类加载到运行时并调用该apply方法?
如果代码编译成多个辅助类会怎样?上面的例子包含一个闭包_.open()。如何确保将所有这些辅助内容“打包”到一个对象中以进行序列化和类加载?
注意:鉴于 Scala 2.11 即将发布并且编译器 API 可能已更改,我很高兴收到有关如何在 Scala 2.11 上解决此问题的提示
我需要在Swing应用程序中调试键事件调度.我认为以下就足够了:
val eventLog = PlatformLogger.getLogger("java.awt.event.Component")
eventLog.setLevel(PlatformLogger.Level.ALL)
val focusLog = PlatformLogger.getLogger("java.awt.focus.DefaultKeyboardFocusManager")
focusLog.setLevel(PlatformLogger.Level.ALL)
Run Code Online (Sandbox Code Playgroud)
但没有任何反应.(记录器报告它们已启用,但我看不到任何文本输出).我是否需要在PrintStream某处配置以查看日志消息?
在以下代码段中,
trait MyType1; trait MyType2
import scala.concurrent.Promise
val p1 = Promise[Option[MyType1]]()
val p2 = Promise[MyType2]()
Run Code Online (Sandbox Code Playgroud)
我将p1和p2传递给另一个函数,在那里我使用一个成功的Future来完成Promise.调用此函数后,我尝试读取Promise中的值:
trait Test {
// get the Future from the promise
val f1 = p1.future
val f2 = p2.future
for {
someF1Elem <- f1
f1Elem <- someF1Elem
f2Elem <- f1Elem
} yield {
// do something with f1Elem and f2Elem
"..."
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,我遇到了一些编译器问题.
Error:(52, 19) type mismatch;
found : Option[Nothing]
required: scala.concurrent.Future[?]
flElem <- someF1Elem
^
Run Code Online (Sandbox Code Playgroud)
IntelliJ没有显示任何错误,也没有显示任何错误,并且类型看起来是对齐的.但我不确定编译器为什么不开心!有线索吗?
在Scala中,我有一个Array[Int]名为的对象elem.
我想删除索引处的元素k.
我试过这个:
elem.filter(! _.equals(elem(k)))
Run Code Online (Sandbox Code Playgroud)
但是,这会删除所有等于的元素elem(k).
我怎么能只删除索引处的元素k?
scala ×9
java ×2
sbt ×2
casting ×1
compilation ×1
compression ×1
dispatch ×1
focus ×1
future ×1
interpreter ×1
ivy ×1
keyevent ×1
promise ×1
scaladoc ×1
scalatest ×1
subtyping ×1
swing ×1
type-bounds ×1
typesafe ×1