Giter Site home page Giter Site logo

Tutorial / walkthrough please about easytensor HOT 8 OPEN

achirkin avatar achirkin commented on May 28, 2024 2
Tutorial / walkthrough please

from easytensor.

Comments (8)

achirkin avatar achirkin commented on May 28, 2024

Thanks for the comment, work on this is in progress!

In the meanwhile, you can find some rudimentary examples documentation-and-tutorials section of the readme.

from easytensor.

Rotaerk avatar Rotaerk commented on May 28, 2024

Just wanted to say I'm learning a lot reading through the implementation of easytensor. And slowly going crazy... :P

from easytensor.

achirkin avatar achirkin commented on May 28, 2024

Ha-ha, sorry :)
While I don't have time for a full tutorial at this moment, you may ask here about specific parts in the project and I will quickly haddock more elaborate descriptions.

from easytensor.

joelburget avatar joelburget commented on May 28, 2024

Documentation of functions / datatypes is not the problem for me. What I need is one or two simple examples for each project of how it's intended to be used.

from easytensor.

Rotaerk avatar Rotaerk commented on May 28, 2024

One thing I'm unclear on is why you would ever use XN n for any n > 0. What do you get out of statically knowing that that dimension has at least n elements?

For instance, in this snippet, the data frame will have 7 vertices; why specify that it's statically unknown but at least 3? Why not 0, or 7?

from easytensor.

achirkin avatar achirkin commented on May 28, 2024

@joelburget yes, I understand that. I will add the tutorial as soon as finish writing my thesis (likely in September , sorry for that)

@Rotaerk In general, XN n is meant for data import. Imagine something like this:

importCsv :: FilePath -> IO (Either String (DataFrame Vertex '[XN 1]))

The function above reads a non-empty data frame or fails. We cannot index DataFrame using Nat here, because we don't know dimensionality in advance. On the other hand, we may want to reject the imported file if it has too few lines.
In vulkan-triangles, the constraint comes not from the data, but from the program logic: shader pipeline requires at least 3 vertices to draw at least one triangle primitive. I decided, that would be handy to declare explicitly. Added a comment to the code.

from easytensor.

Rotaerk avatar Rotaerk commented on May 28, 2024

Well, I was going to write up something about having issues with getting XFrame matching to work, but it turns out it was resolved by adding more type annotations to unrelated functions in my code... However, the type errors were rather troublesome to make sense of, and I only accidentally got it working.

In the commit Rotaerk/vulkanTest@033701b, I wanted to move the XFrame matching outside of the createVertexBuffer and fillVertexbufferMemory functions. So I moved it up into the beginning of main, and indented the entire runResourceT block to be inside of it.

Problems I encountered while working on this change:

  1. It took me some work to figure out what type to give the revised fillVertexBufferMemory function. I initially tried DataFrame Vertex (ns :: [Nat]), but that gave me this error:

    src/Main.hs:723:70: error:
        • Overlapping instances for PrimBytes
                                      (Numeric.DataFrame.Internal.Array.Family.Array Vertex ns)
            arising from a use of ‘bSizeOf’
          Matching instances:
            instance [overlappable] (VulkanMarshalPrim a, Storable a) =>
                                    PrimBytes a
              -- Defined in ‘Graphics.Vulkan.Marshal.Create.DataFrame’
            instance (PrimBytes a, PrimBytes b) => PrimBytes (Either a b)
              -- Defined in ‘Numeric.PrimBytes’
            instance PrimBytes Int16 -- Defined in ‘Numeric.PrimBytes’
            ...plus 15 others
            ...plus 13 instances involving out-of-scope types
            (use -fprint-potential-instances to see them all)
          (The choice depends on the instantiation of ‘ns’
           To pick the first instance above, use IncoherentInstances
           when compiling the other instance declarations)
        • In the second argument of ‘($)’, namely ‘bSizeOf vertices’
          In the fourth argument of ‘mappedMemory’, namely
            ‘(fromIntegral $ bSizeOf vertices)’
          In the first argument of ‘with’, namely
            ‘(mappedMemory
                device vertexBufferMemory 0 (fromIntegral $ bSizeOf vertices))’
        |
    723 |       with (mappedMemory device vertexBufferMemory 0 (fromIntegral $ bSizeOf vertices)) $ \ptr ->
        |                                                                      ^^^^^^^^^^^^^^^^
    

    I'm still not really sure how I would give it a DataFrame type, but I was able to get it to work with the more generic type that it has now.

  2. In addition to making the obvious code changes, I also had to add type annotations to maxFramesInFlight and to evalStateTWith. Without them, I got some pretty strange type errors. It seems odd that this would be suddenly required just because these things are used inside of the XFrame case.

from easytensor.

achirkin avatar achirkin commented on May 28, 2024

Looks like I messed up with instances of PrimBytes. I have created an issue #9 to improve the situation with that.

In general, whenever you encounter Overlapping instances error, you should first check if there is any instance in scope that satisfies the class constraint.
In your case, GHC does not know which instance of Array type family is used inside the DataFrame and, thus, cannot find a suitable type class instance for PrimBytes. Thus, you need to provide the instances explicitly. The XNat-indexed DataFrame carries only a few instances for a Nat-indexed DataFrame behind its existential constructor. If you need any more instance in the scope of pattern match, you can use inference functions, e.g.

case xdf of
  XFrame df
    | E <- inferPrim df -> do
       ... -- df has an instance of PrimBytes here

Most commonly required inference functions are given by DataFrameInference class.

As for the second problem, cannot really say right now, without trying it myself.

from easytensor.

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.