Code Monkey home page Code Monkey logo

Comments (2)

ryanrhymes avatar ryanrhymes commented on May 12, 2024

Thanks for the code @mars0i , it looks nice, I will implement the compare function in the next release.

from owl.

mars0i avatar mars0i commented on May 12, 2024

Great--I'm happy if this or the fold2 functions (#39) turn out to be useful.

Here is one more function--a compare function for use with Markus Mottle's partially ordered map library pomap. I'm not sure this belongs in owl, though. The set of people who want to implement a partial order on matrices may be very small.

let pomap_compare m1 m2 =
  let f acc e1 e2 =
    match acc with
    | Equal -> if e1 < e2 then Lower else 
               if e1 > e2 then Greater else Equal
    | Lower ->   if e1 <= e2 then Lower else Unknown
    | Greater -> if e1 >= e2 then Greater else Unknown
    | Unknown -> Unknown (* should never happen given short circuit *)
  in Utils.short_circuit_fold2 Unknown f Equal m1 m2

After writing that, I felt that the code was organized in a way that made it easier to read than my original Interval-oriented compare function above. Here's the original compare function rewritten in the same way:

let compare m1 m2 =
  let f acc e1 e2 =
    match acc with
         |  0 -> if e1 < e2 then -1 else
                 if e1 > e2 then 1 else 0
         | -1 -> if e1 <= e2 then -1 else failwith "incomparable"
         |  1 -> if e1 >= e2 then  1 else failwith "incomparable"
         |  _ -> failwith "bug: acc is not -1, 0, or 1" (* avoid match warning *)
  in Utils.fold2 f 0 m1 m2

Again, I know that you may be able to implement a more efficient version in any event. (No need to reply again.)

from owl.

Related Issues (20)

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.