Git Product home page Git Product logo

Comments (10)

foretspaisibles avatar foretspaisibles commented on June 16, 2024

I am just curious about the application scenario we are thinking of because it is not clear to me why we want to have more precise floats to render graphics. Do you have a high-level workflow in mind, describing the interaction between KONS-9 and an engineering program? Or any pointer to an ongoing conversation around here? Thanks!

from kons-9.

lukego avatar lukego commented on June 16, 2024

Do you have a high-level workflow in mind, describing the interaction between KONS-9 and an engineering program?

I'm using Kons-9 to visualize the results of Monte Carlo simulations running in the same Lisp image. My code is hungry for floating-point precision because it needs to do long chains of calculations on very small (log-)probability values. I definitely don't want any single-floats in my application-level calculations.

I agree with @awolven that it would be great for Kons-9 to interoperate more easily with this kind of application e.g. be able to load and run in an image that uses double-floats by default. Currently Bad Things Happen when Kons-9 is exposed to double-floats.

from kons-9.

foretspaisibles avatar foretspaisibles commented on June 16, 2024

I am not questioning at all why scientific computations need double precision but I would like to understand more why KONS-9 should also use double floats for graphic-related computations. So understanding better an example of a workflow would be useful to figure out how to make KONS-9 suitable for scientific and engineering computing while still using faster single floats when it comes to graphic computations.

from kons-9.

lukego avatar lukego commented on June 16, 2024

@foretspaisibles I believe the requirement here is only for Kons-9 to co-exist with code in the same image that uses double-floats. It can still use single-floats internally.

Here's an example that I think represents mine and @awolven's workflows that doesn't work today:

* (setq *read-default-float-format* 'double-float)
* ;; ... write and run some engineering code ...
* (require :kons-9)

Since we will be writing a bunch of engineering code in random files and in the REPL we set *READ-DEFAULT-FLOAT-FORMAT* to DOUBLE-FLOAT so that literals we write like 0.5 will be read as double-float objects. This is simply a user-friendly convenience to avoid writing suffixes like 0.5d0 to get double-floats.

The trouble is that kons-9 compilation breaks when we later try to load it into the same image:

* (setq *read-default-float-format* 'double-float)
* (require :kons-9)
...
; compiling file "/home/luke/git/kons-9/src/kernel/point-origin.lisp" (written 14 NOV 2022 06:52:36 AM):

; file: /home/luke/git/kons-9/src/kernel/point-origin.lisp
; in: DEFUN P-SMOOTH-LERP
;     (ORIGIN.VEC3:LERP KONS-9::P1 KONS-9::P2 (KONS-9::CUBIC KONS-9::F))
; 
; caught WARNING:
;   Derived type of
;   (+ (* -2.0 (* KONS-9::X KONS-9::X KONS-9::X)) (* 3.0 (* KONS-9::X KONS-9::X)))
;   is
;     (VALUES (OR DOUBLE-FLOAT (COMPLEX DOUBLE-FLOAT)) &OPTIONAL),
;   conflicting with its asserted type
;     SINGLE-FLOAT.
;   See also:
;     The SBCL Manual, Node "Handling of Types"

; in: DEFUN P-MIDPOINT
;     (ORIGIN.VEC3:SCALE (ORIGIN.VEC3:+ KONS-9::P1 KONS-9::P2) 0.5d0)
; 
; note: deleting unreachable code
; 
; caught WARNING:
;   Constant 0.5 conflicts with its asserted type SINGLE-FLOAT.
;   See also:
;     The SBCL Manual, Node "Handling of Types"

The reason is that kons-9 source code (and/or its dependencies) includes literals like 0.5 that it assumes will be read into single-float values but in fact won't be due to the customization in this image.

So it seems like kons-9 would ideally either explicitly suffix such literals as 0.5f0 to be agnostic to *READ-DEFAULT-FLOAT-FORMAT* or otherwise somehow (ASDF hook?) ensure that this variable has the necessary value during kons-9 compilation.

Is that a more helpful answer?

(I was going to assert that kons-9 also has problems with being accidentally passed double-float numbers via the API but I couldn't immediately formulate an example so maybe I am imagining that.)

from kons-9.

JMC-design avatar JMC-design commented on June 16, 2024

It's not just about reading. You would need to be able to switch between the two, because double floats are wasteful for the majority of things and most people don't care about them. Since points aren't generic you'll also need to switch between libraries.

from kons-9.

lukego avatar lukego commented on June 16, 2024

I made a separate issue #180 about the specific issue that kons-9's requirement that *read-default-float-format* be single-float is not documented (and potentially unfortunate.)

If that issue captures everything that is actionable here then perhaps we could close this issue.

from kons-9.

awolven avatar awolven commented on June 16, 2024

from kons-9.

kaveh808 avatar kaveh808 commented on June 16, 2024

It would be good to be able to have the user be able to specify if they want single or double floats when they are loading our system. There are definitely use cases for both.

Let''s figure out how in #180

from kons-9.

kaveh808 avatar kaveh808 commented on June 16, 2024

I'm using Kons-9 to visualize the results of Monte Carlo simulations running in the same Lisp image.

@lukego I'd love to hear more about your use of the system. Maybe post about it in discussion #78 ?

from kons-9.

foretspaisibles avatar foretspaisibles commented on June 16, 2024

@foretspaisibles I believe the requirement here is only for Kons-9 to co-exist with code in the same image that uses double-floats. It can still use single-floats internally. […]

Thank you @lukego that's a very helpful description of what you would like to do. I do not have experience with automated testing for Slime/Emacs or Sly/Emacs but we could start with a plain lisp test.

Yet that could be interesting to learn about UX-testing in Emacs for the future.

from kons-9.

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.