Clojure 中的可插入向量处理单元
我正在 Clojure 中开发一些模拟软件,需要处理大量矢量数据(基本上源自 Java 浮点数组的偏移量,长度通常在 10-10000 范围内)。大量的这些向量将需要经历各种处理步骤 - 例如,对向量进行归一化、将两个向量流连接在一起、计算移动平均值等。
我希望做的不是以命令式方式完成所有操作,而是创建一个更多的处理步骤函数式 Clojure 解决方案将执行以下操作:
- 允许将任何向量函数转换为可插入模块,例如 (def module-a (make-module some-function))
- 允许这些模块在管道中组合,例如(def组合模块(组合串联模块-a模块-b))会将模块a的输出馈送到模块b的输入
- 允许辅助函数来访问存储在给定模块中的状态,例如(get-moving-average some-moving-average-module),即使 some-moving-average-module 深深嵌入到一个模块中,它也需要工作组合管道
- 在幕后隐藏任何样板代码,例如为向量计算分配足够大的临时数组。
这听起来是一个明智的方法吗?
如果是这样,有任何可能有帮助的实现提示或库吗?
I'm developing some simulation software in Clojure that will need to process lots of vector data (basically originating as offsets into arrays of Java floats, length typically in 10-10000 range). Large numbers of these vectors will need to go through various processing steps - e.g. normalising the vectors, concatenating together two streams of vectors, calculating a moving average etc.
Rather than doing everything in an imperative style, I was hoping to do was create a more functional-style Clojure solution that would do the following:
- allow any vector function to be turned into a pluggable module, e.g. (def module-a (make-module some-function))
- allow these modules to be composed in pipelines, e.g. (def combined-module (combine-in-series module-a module-b)) would feed the output of module-a into the input of module-b
- allow auxillary functions to access state stored within a given module, e.g. (get-moving-average some-moving-average-module), which would need to work even if some-moving-average-module is embedded deep within a combined pipeline
- hide any boilerplate code behind the scenes, e.g. allocating sufficiently large temporary arrays for vector calculation.
Does this sound like a sensible approach?
If so, any implementation hints or libraries that might help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在函数式语言中,一切都是数据流。您可以使用函数作为模块概念。
为了解决您的每个用例:
(def module-a some-function)
为了方便模块扩展,我建议使用 Clojure 映射作为您的状态,其中一个字段是浮点数组。(def linked-module (compose module-a module-b)
:moving-average
字段,则关键字:moving-average
隐藏在函数的实现中,可以在任何地方声明,可能在另一个文件和命名空间中。In a functional language, everything is dataflow. You can use functions as your module concept.
To address each of your use-cases:
(def module-a some-function)
To allow for easy extension by modules, I suggest using a Clojure map as your state, where one field is your array of floats.(def combined-module (compose module-a module-b)
:moving-average
field, then the keyword:moving-average
is your accessor function. State is not stored in modules.结账管道。
http://intensesystems.net/tutorials/conduit-motive.html
Checkout conduit.
http://intensivesystems.net/tutorials/conduit-motive.html