Code Monkey home page Code Monkey logo

comonad's Introduction

Comonads

Some examples of Comonad usage in programs

See this blog post for the full details: https://justinhj.github.io/2019/06/20/comonads-for-life.html

Image Processor

Comonad operations are nice fit for image processing methods where the value of a pixel is modified based on the values of other pixels in the image. Some examples are included such as box filtering and mirroring.

Conway's game of life

Conway's game of life involves running a rule on each cell in a grid to determine the future state of that cell, which is nicely encoded in a function that can be run with coFlatMap

Running

This is an sbt project; build and run as follows, then choose which program to run.

sbt run

fp-starter-pack

This project was created by https://github.com/justinhj/fp-starter-pack.g8

Benchmarks

There are performed on a 2017 Macbook Pro under non-ideal conditions (bunch of Apps running)

CPU 2.5 GHz Dual-Core Intel Core i7 RAM 16 GB 2133 MHz LPDDR3

Initial benchmark

[info] Benchmark                         Mode  Cnt       Score        Error  Units
[info] FocusedGridBench.withMap2Large    avgt    5  120145.615 ±  14792.890  us/op
[info] FocusedGridBench.withMap2Small    avgt    5      52.240 ±      3.186  us/op
[info] FocusedGridBench.withSlowApLarge  avgt    5  442488.978 ± 226548.518  us/op
[info] FocusedGridBench.withSlowApSmall  avgt    5     119.935 ±      7.673  us/op
[success] Total time: 410 s, completed 27-Mar-2020 8:10:42 PM

Implemented and benchmarked array version

[info] Benchmark                            Mode  Cnt       Score        Error  Units
[info] FocusedGridArrayBench.withMap2Large  avgt    5  171099.587 ±  65471.687  us/op
[info] FocusedGridArrayBench.withMap2Small  avgt    5      54.418 ±     25.669  us/op
[info] FocusedGridBench.withMap2Large       avgt    5  152831.655 ±  40709.521  us/op
[info] FocusedGridBench.withMap2Small       avgt    5      59.168 ±     15.346  us/op
[info] FocusedGridBench.withSlowApLarge     avgt    5  649442.291 ± 215248.298  us/op
[info] FocusedGridBench.withSlowApSmall     avgt    5     141.025 ±     78.928  us/op

Notable that optimized map2 is 4x faster on the large image than slowAp and
the array version is actually slower than the vector version.

comonad's People

Contributors

justinhj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.