achirkin / easytensor Goto Github PK
View Code? Open in Web Editor NEWMany-dimensional type-safe numeric ops
Home Page: https://hackage.haskell.org/package/easytensor
License: BSD 3-Clause "New" or "Revised" License
Many-dimensional type-safe numeric ops
Home Page: https://hackage.haskell.org/package/easytensor
License: BSD 3-Clause "New" or "Revised" License
I'm trying to understand how to use the DataFrame operations, and need some help.
What I specifically need for my code right now is, given a Vector VkMemoryHeap 16
, I need to get the first N elements of that vector (determined at runtime). Then I need to filter them using a predicate. Then of the remaining ones, I need to sum their getField @"size"
values.
I used to do this by converting the Vector to a list, and then just use standard list operations, but the toList
function is no longer exported by easytensor.
I was looking at slice
, because it seems relevant, and I can't make sense of what it's trying to do, or how to use it.
Function getBytes
on ArrayBase
type can crash with the following message:
internal error: ARR_WORDS object (0x...) entered!
(GHC version 9.0.1 for x86_64_unknown_linux)
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
I have a workaround for that, but sadly it does not work anymore with GHC 9.0.1.
Here is the related issue:
https://gitlab.haskell.org/ghc/ghc/-/issues/19645
If I have a Ptr Foo
, where Foo has a bar :: Word32
field, I can get that field's value like:
bPeekByteOff @Word32 fooPtr $ bFieldOffsetOf @"bar" (undefined :: Foo)
It would be nice to not have to explicitly specify the type of the field when getting it, as that should be determinable by the field name. It would also be nice to have a single function that covers this, like readField
from Graphics.Vulkan.Marshal
.
dimensions
package is missing a CHANGELOG
Wouldn't 0 =< i < Dim d
be more programmer-friendly? I realize there is an escape hatch with fromEnum
, but I'm wondering if there is a specific reason behind this interface.
I don't see cabal files for easytensor anymore, so I can't build it. I'm guessing they're optional when using stack? Problem is that I don't use stack.
Hi, I am developing Vulkan in Haskell using easytensor and vulkan-api library.
Thank you for your contribution.
If vulkan-api and easytensor do not exist, Haskell's vulkan programming is not possible.
But easytensor is so hard for me to understanding... and English too.. T_T
I have a question.
I want to get pure List from XFrame as below but I had failed..
dataFrameToList :: DataFrame Vec3f (xns::[XNat]) -> [Vec3f]
Can you help me? Let me know how can I convert XFrame to List.
And I want to know how to apply map function to XFrame.
I will wait for your answer. Thank you.
And I hope more easy examples about easytensor.
Below are some of my project and easytensor notes.
https://github.com/ubuntunux/HulkanEngine3D
https://github.com/ubuntunux/PyEngine3D
https://wikidocs.net/47790
Sometimes LU factorization is very unstable, especially for Float
matrices.
We should fix this some day.
easytensor/easytensor/test/Numeric/MatrixFloatTest.hs
Lines 80 to 90 in 4cc9a38
In Numeric.Matrix: perspective
and orthogonal
currently follow OpenGL conventions. They require negative near
and far
values, otherwise they produce bogus Z values and messed up signs. The haddock comment on perspective
states "Near plane clipping distance (always positive)" which is wrong. I suppose the OpenGL convention sees them as z-coordinates of the planes in screen space instead of distances to the camera.
They also project onto Z values from -1 to 1. For Vulkan, they need to produce a Z range from 0 to 1.
The GLM library has different defines for those variants, but I don't believe compile time flags are a good solution. I suggest splitting the projections up into variants and naming them accordingly.
Hi I would like to use easytensor with ad but instance Quaternion (Reverse s Double)
is missing. Perhaps the methods of class Quaternion
can be ordinary functions on newtype Quater a = Quater (Vector a 4)
with SPECIALIZE pragmas for Double and Float. Then Numeric.Quaternion.Internal.QDouble
and QFloat
duplication will be gone, and maybe the numbers defined by ad will also work.
There's currently no such instance. I'll work on a patch..
dimensions-1.0.1.1$ cabal build -w ghc-8.10.7
...
src/Numeric/Dim.hs:123:29: error: Not in scope: type variable ‘k’
|
123 | pattern Dim :: forall (n :: k) . () => KnownDim n => Dim n
| ^
I'm not really sure how this would work, exactly, but it seems like there should be some mechanism for easily getting the offset of a field in a PrimBytes instance. In my code I have this:
data Vertex =
Vertex {
vtxPos :: Vec3f,
vtxColor :: Vec3f,
vtxTexCoord :: Vec2f
} deriving (Eq, Show, Generic)
instance PrimBytes Vertex
vertexAttributeDescriptionsAt :: Word32 -> [VkVertexInputAttributeDescription]
vertexAttributeDescriptionsAt binding =
createVk @VkVertexInputAttributeDescription <$> [
set @"binding" binding &*
set @"location" 0 &*
set @"format" VK_FORMAT_R32G32B32_SFLOAT &*
set @"offset" 0,
set @"binding" binding &*
set @"location" 1 &*
set @"format" VK_FORMAT_R32G32B32_SFLOAT &*
set @"offset" offset1,
set @"binding" binding &*
set @"location" 2 &*
set @"format" VK_FORMAT_R32G32_SFLOAT &*
set @"offset" offset2
]
where
offset1 = fromIntegral (sizeOf $ vtxPos undefined)
offset2 = offset1 + fromIntegral (sizeOf $ vtxColor undefined)
It'd be nice if I could just say something like offsetOf @"vtxColor"
. (And for that matter, why not sizeOf @"vtxColor"
or just or something.) Edit: Eh, not that sizeOf @Vec3f
sizeOf @Vec3f
is, itself, bad, but you wouldn't want to do that to get the size of the vtxColor
field, in case the type of that field changes.
The following works:
myVector :: DataFrame Double '[4]
myVector =
packDF @Double @4 @'[] 1 2 3 4
The following doesn't type-check
vertices :: DataFrame Vertex '[4]
vertices =
packDF @Vertex @4 @'[]
(Vertex (vec3 0 0 0) (vec2 0 0))
(Vertex (vec3 0 0 0) (vec2 0 0))
(Vertex (vec3 0 0 0) (vec2 0 0))
(Vertex (vec3 0 0 0) (vec2 0 0))
data Vertex =
Vertex {
vtxPos :: Vec3f,
vtxTexCoord :: Vec2f
} deriving (Eq, Show, Generic)
instance PrimBytes Vertex
The error is:
• Couldn't match type ‘DataFrame Vertex '[]’ with ‘Vertex’
Expected type: Vertex
-> Vertex -> Vertex -> Vertex -> DataFrame Vertex '[4]
Actual type: PackDF Vertex '[] 4 (DataFrame Vertex '[4])
• The expression ‘packDF @Vertex @4 @'[]’
is applied to four arguments,
but its type ‘PackDF Vertex '[] 4 (DataFrame Vertex '[4])’ has none
In the expression:
packDF
@Vertex
@4
@'[]
(Vertex (vec3 0 0 0) (vec2 0 0))
(Vertex (vec3 0 0 0) (vec2 0 0))
(Vertex (vec3 0 0 0) (vec2 0 0))
(Vertex (vec3 0 0 0) (vec2 0 0))
In an equation for ‘vertices’:
vertices
= packDF
@Vertex
@4
@'[]
(Vertex (vec3 0 0 0) (vec2 0 0))
(Vertex (vec3 0 0 0) (vec2 0 0))
(Vertex (vec3 0 0 0) (vec2 0 0))
(Vertex (vec3 0 0 0) (vec2 0 0))
|
295 | packDF @Vertex @4 @'[]
Why?
Not sure if that's a limitation of haddock, but pattern synonyms like Vec2
don't appear in the haddock output of Numeric.Vector
, despite being re-exported there. They should be mentioned somewhere, as they are needed for comfortable deconstruction :)
dimensions-1.0 is excellent and has removed all of the helpers I've written for hasktorch. The remnants of these are just KnownDim<N>
and Dimensions<N>
convenience constraints since we are prioritizing statically typed tensors, and we wind up with a high number of these one-off constraints (I've only gotten up to 2d auto differentiable convolution, and I've found KnownDim5
fairly useful). Would this be something that you might consider adding to dimensions
?
I just got back into vulkan coding after a 6-month hiatus, so I haven't been following all the changes you've been making... I upgraded to the latest easytensor and vulkan-api, and when I built them, easytensor-vulkan failed with this error:
src/Graphics/Vulkan/Marshal/Create/DataFrame.hs:184:10: error:
Not in scope: type constructor or class ‘VulkanMarshalPrim’
Perhaps you meant ‘VulkanMarshal’ (imported from Graphics.Vulkan.Marshal.Internal)
|
184 | instance VulkanMarshalPrim (VkDataFrame t ds) where
| ^^^^^^^^^^^^^^^^^
I think the right-hand side here should use sameDim
, not sameDim'
: https://github.com/achirkin/easytensor/blob/master/dimensions/src/Numeric/Dim.hs#L321
Is there some way to take, say, a Vector _ 10
and drop the last 5 elements to get a Vector _ 5
? In Vulkan, there are cases where the size of the array that Vulkan returned is much larger than the number of actual valid elements.
For example, within VkPhysicalDeviceMemoryProperties
, the memoryHeaps
field is an array that always has length VK_MAX_MEMORY_HEAPS
, but only the first memoryHeapCount
elements are actually valid.
I would like to be able to, say, fold over these elements. As it stands, the only way I can see to do it is to first convert it to a list, and then use the standard list functions for that.
For PrimBytes to be applied to FFI, instances for these C-types would be nice to have.
Citing from https://nix-cache.s3.amazonaws.com/log/bva35jjj8g57dp80cxd0ds11x76msq16-dimensions-0.3.0.0.drv:
Running 1 test suites...
Test suite dimensions-test: RUNNING...
Prelude.read: no parse
prepping for ghc-8.6, following https://gist.github.com/DanBurton/43b5f5155fdd1affd02f6e86f37da9ae, I get:
/Users/tonyday/haskell/easytensor/dimensions/src/Numeric/Dim.hs:65:44: error: parse error on input ‘*’
|
65 | , Nat, CmpNat, type (+), type (-), type (*), type (^)
| ^
Some sort of interaction between * and Type perhaps?
Building with OSX, easytensor-0.4.0.0 and nightly-2017-11-07 gives me:
src-base/Numeric/Array/Family/ArrayD.hs:56:37: error:
error: '##' cannot appear at end of macro expansion
|
56 | #define EL_ZERO 0.0##
| ^
#define EL_ZERO 0.0##
# gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
When a code requires PrimBytes (DataFrame t ds)
, GHC uses a
deriving instance PrimBytes (Array t ds) => PrimBytes (DataFrame t ds)
,
which, in turn, requires PrimBytes (Array t ds)
.
Array t ds
is a type family; only individual members of the type family have the instance.
To make things worse, there are other instances of PrimBytes
defined in easytensor-vulkan
.
And GHC starts to panic (Overlapping instances for PrimBytes
).
Need to try to reconsider a combination of TypeError
and OverlappingInstances
to improve this.
The issue comes from a comment #4 (comment).
A QuickCheck test prop_Comparisons
fails from time to time. QuickCheck generates DataFrames randomly, 100 tests for each property by default. Usually, this kind of problem happens due to floating point precision errors. But in this case, it is hard to find out what can cause such error.
These libraries (dimensions
/ easytensor
) look useful and interesting. Unfortunately it's not clear how to get started. Some examples / tutorial would be much appreciated!
I'm at the point in the vulkan tutorials where I have need of these transforms. I'd like to make an attempt at implementing them, but I'm unclear on the intent behind and plan for the existing HomTransform4
class. Basically, why is it a class at all, rather than just having free functions that are constrained to Floating t =>
or something? What other instances would there be besides Float and Double?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.