vlang / vtl Goto Github PK
View Code? Open in Web Editor NEWThe V Tensor Library
Home Page: https://vlang.github.io/vtl
License: MIT License
The V Tensor Library
Home Page: https://vlang.github.io/vtl
License: MIT License
We already have a tutorial here but it is not completed and needs more love ❤️
For this issue we want everyone to add more examples and tutorial steps
A numerical library needs a well defined behavior of floating point computations (incl. comparisons) on all platforms it supports. Currently it seems vnum is not limited to any platform (as vsl is not limited to any) with the exception of LAPACK/BLAS routines which usually do have well defined limitations and can't be run on all existing platforms.
V does NOT have well defined behavior of floating point comparisons and that's why I'm raising this issue here.
Refer to vlang/v#5180 (comment) for detailed analysis and a sketch of a possible solution.
We already have some tests for the ml/metrics module but we don't have any example at ml/metrics/examples
or any README.md showing usage examples. Add some!
VTL version:
master
OS:
win10
What did you do?
import vtl
fn main() {
println(vtl.random(0,1,[2,2]))
}
What did you expect to see?
a 2*2 matrix with elements 0.0~1.0
What did you see instead?
[[0.949985009492209, 0e+00],
[ 0e+00, 0e+00]]
Hello,
V doctor:
OS: linux, Pop!_OS 22.04 LTS
CC version: cc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
V full version: V 0.2.4 d336b7b.5a79a54 (master)
I tried to do the sum and the product of a Tensor element :
module main
import vtl
import vtl.stats
fn main(){
x := vtl.from_array([2.0, 4.0, 8.0], [3,1])
sum := stats.sum(x)
product := stats.prod(x)
println('sum(x) is $sum')
println('product(x) is $product')
}
What did you expect to see?
sum(x) is 14
product(x) is 64
What did you see instead?
---- Testing... ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
FAIL 318.976 ms /home/cmnemoi/Documents/Code/V/vtl/stats/stats_test.v
stats/stats.v:12:25: error: expected 0 arguments, but got 1
10 | // sum returns the sum of all elements of the given tensor
11 | pub fn sum<T>(t &vtl.Tensor<T>) T {
12 | mut iter := t.iterator(data.axis)
| ~~~~~~~~~
13 | mut acc := T(0)
14 | for {
stats/stats.v:48:25: error: expected 0 arguments, but got 1
46 | // axis
47 | pub fn prod<T>(t &vtl.Tensor<T>) T {
48 | mut iter := t.iterator(data.axis)
| ~~~~~~~~~
49 | mut acc := T(0)
50 | for {
The main difference (or rather the only one?) between Fortran and C is, that Fortran's semantics assumes no pointer aliasing by default (though Fortran as a language allows pointer aliasing) whereas C assumes pointer aliasing is always present.
Pointer aliasing is on of the few major complications almost preventing vectorization and thus the reason why C is so slow and hard to optimize.
To make exceptions to this C semantics rule, restrict
appeared in C99. Unfortunately restrict
might be quite error prone and thus it's being used mostly in macros or automatically generated code but much less manually. But V generates C, so this is great opportunity for major performance boost in certain use cases and a numerical library should be one of them.
I think to make vnum have excellent performance, restrict
will be necessary. See the corresponding V issue proposing using restrict
as an important optimization.
Thoughts?
V doctor:
OS: macos, macOS, 12.1, 21C52
Processor: 8 cpus, 64bit, little endian, Apple M1
CC version: Apple clang version 13.0.0 (clang-1300.0.29.3)
getwd: /Users/bishunjie/v/vtl/datasets/examples
vmodules: /Users/bishunjie/.vmodules
vroot: /Users/bishunjie/v
vexe: /Users/bishunjie/v/v
vexe mtime: 2022-08-14 14:24:25
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.0 0133ff2.90d9b20
Git version: git version 2.30.1 (Apple Git-130)
Git vroot status: weekly.2022.32-33-g90d9b200-dirty
.git/config present: true
thirdparty/tcc status: thirdparty-macos-arm64 173c526e
What did you do?
v -g -o vdbg cmd/v && vdbg imdb_not_ci.v
module main
import vtl.datasets
fn main() {
mut train_ds := datasets.load_imdb(.train, batch_size: 6)?
mut i := 0
for {
batch := train_ds.next() or { break }
println('Labels Batch #${i++}')
println(*batch.labels)
println('')
if i == 10 {
break
}
}
}
What did you expect to see?
as example
What did you see instead?
/Users/bishunjie/.vmodules/vtl/datasets/mnist.v:88:3: warning: unused variable: `elem`
86 | mut iter := lt.iterator()
87 | for {
88 | elem, i := iter.next() or { break }
| ~~~~
89 | lft.set(i, 1)
90 | }
==================
^~~~~~~~~~~~~~~
/tmp/v_501/imdb_not_ci.12623298804525476900.tmp.c:31512:56: error: used type 'string' (aka 'struct string') where arithmetic or pointer type is required
vtl__Tensor_T_string* ret = vtl__new_tensor_T_string(((string)(0)), shape, ((vtl__TensorData){.memory = vtl__MemoryFormat__row_major,}));
^ ~~~
/tmp/v_501/imdb_not_ci.12623298804525476900.tmp.c:32149:4: warning: expression result unused [-Wunused-value]
(*(bool*)_t1.data);
^~~~~~~~~~~~~~~~
/tmp/v_501/imdb_not_ci.12623298804525476900.tmp.c:32190:4: warning: expression result unused [-Wunused-value]
(*(bool*)_t1.data);
^~~~~~~~~~~~~~~~
/tmp/v_501/imdb_not_ci.12623298804525476900.tmp.c:32217:4: warning: expression result unused [-Wunused-value]
(*(bool*)_t6.data);
...
==================
(Use `v -cg` to print the entire error message)
builder error:
==================
C error. This should never happen.
This is a compiler bug, please report it using `v bug file.v`.
https://github.com/vlang/v/issues/new/choose
You can also use #help on Discord: https://discord.gg/vlang
There are some commented tests in this file. We need to fix the implementation of each related function
VTL version:
master
OS:
win10
What did you do?
import vtl
fn main() {
println(vtl.ones([2,2]).t())
}
What did you expect to see?
a 2*2 matrix with elements 1.0
What did you see instead?
[[0e+00, 0e+00],
[0e+00, 0e+00]]
https://github.com/tracel-ai/burn
.
.
No response
.
.
We need to improve the performance of the stats module on CPU
Redefine all the functions and avoid using the math.stats
module
We already have some examples for vtl, but we need more!
For that you can submit any PR adding examples to examples/
. You can use numpy, arraymancer or any other lib examples as inspiration!
You can also see the unit tests we already have for inspiration
For this ticket we want to add more datasets to the module vtl.datasets
. Every new dataset should implement the types defined at datasets/types.v
When I try compiling and running the code at the beginning of the README.md file, it throws an Unhandled Exception that means (A heap has been corrupted.)
I expected the program to compile, run and return the same thing as in the example.
The code throws the following error when I run "v run src/main.v":
Unhandled Exception 0xC0000374
print_backtrace_skipping_top_frames is not implemented
The steps can be reproduced on Windows with this code:
module main
import vtl
fn main() {
t := vtl.from_1d([1,2,3,4])!
println(t)
}
The vtl.from_1d method calls the vtl.from_array method. There is a bug in the vtl.from_array method that is causing the heap to be corrupted. One possible solution would be to investigate and see what part of the vtl.from_array method is causing the exception on Windows
I tried looking into the source of the vtl.from_array method, and this is what I found:
// from_varray takes a one dimensional array of T values
// and coerces it into an arbitrary shaped Tensor if possible.
// Panics if the shape provided does not hold the provided array
pub fn from_array[T](arr []T, shape []int, params TensorData) !&Tensor[T] {
size := size_from_shape(shape)
if size != arr.len {
return error('Bad shape for array, shape [${arr.len}] cannot fit into shape ${shape}')
}
data_storage := storage.from_array[T](arr)
if shape.len == 0 {
return &Tensor[T]{
memory: params.memory
strides: [1]
shape: []
size: size
data: data_storage
}
}
strides := strides_from_shape(shape, params.memory)
return &Tensor[T]{
shape: shape
strides: strides
memory: params.memory
size: size
data: data_storage
}
}
I think one of the returns is problematic, or maybe the strides are calculated incorrectly, but all I know is the error is related to the heap being corrupted, so it's probably one of the Tensor references being returned.
V 0.4.0 d53d959
0.2.0
V full version: V 0.4.0 3a91a5e.d53d959
OS: windows, Microsoft Windows 11 Pro v22621 64-bit
Processor: 12 cpus, 64bit, little endian,
getwd: C:\Users\tudor.vmodules\vtl\src
vexe: C:\Users\tudor\Documents\v_windows\v\v.exe
vexe mtime: 2023-07-27 16:15:47
vroot: OK, value: C:\Users\tudor\Documents\v_windows\v
VMODULES: OK, value: C:\Users\tudor.vmodules
VTMP: OK, value: C:\Users\tudor\AppData\Local\Temp\v_0
Git version: git version 2.41.0.windows.3
Git vroot status: weekly.2023.30-14-gd53d9599
.git/config present: true
CC version: Error: exec failed (CreateProcess) with code 2: The system cannot find the file specified.
cmd: cc --version
thirdparty/tcc: N/A
run: mv ./vtl ~/.vmodules
- name: Verify Fmt
# TODO: Remove continue-on-error when v fmt -verify is fixed for VSL on CI
continue-on-error: true
run: |
cd ~
v fmt -verify ~/.vmodules/vtl
run-tests:
runs-on: ${{ matrix.os }}
I am not a fan of this being here, and I am even more against having it re-licensed under a different license, without even asking on the original repository.
If you bothered to read the license, you would see the following clause:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
This is not being respected, given that the new license credits the "V Programming Language", and is now for some reason licensed under MIT?
The original repository states that work had paused until a stable release of v
was available with working generics. If you want to implement an n-dimensional container, feel free to take inspiration from vnum
, but I would appreciate it not being a copy-paste of my work without even consulting me.
(I guess V's op overload is now stable enough so...)
VTL version:
master
OS:
win10
What did you do?
(Just take plus op as an example)
import vtl
fn main() {
println(vtl.ones([2,2])+vtl.ones([2,2]))
}
What did you expect to see?
a 2*2 matrix with elements 2.0
What did you see instead?
sample.v:4:14: error: undefined operation `vtl.Tensor` + `vtl.Tensor`
2 |
3 | fn main() {
4 | println(vtl.ones([2,2])+vtl.ones([2,2]))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 | }
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.