Skip to content

Commit

Permalink
Merge branch 'main' of github.com:vlang/vsl into feature/new-lapack
Browse files Browse the repository at this point in the history
* 'main' of github.com:vlang/vsl:
  fix kmeans.v (#199)
  Update maximum dimension checks in HDF5 file functions
  • Loading branch information
ulises-jeremias committed Feb 25, 2024
2 parents ea376ac + 89dda60 commit c7356d7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
28 changes: 14 additions & 14 deletions inout/h5/hdf5_nix.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub fn open_file(filename string) !Hdf5File {

// read_dataset1d reads a 1-d numeric array (vector) from a named HDF5 dataset in an HDF5 file.
// Replaces the value of the array.
// Maximum dimension is math.max_i32 or less (this is checked).
// Maximum dimension is max_i32 or less (this is checked).
pub fn (f &Hdf5File) read_dataset1d[T](dset_name string, mut dataset []T) {
mut rank := 0
mut class_id := Hdf5ClassT(0)
Expand All @@ -242,7 +242,7 @@ pub fn (f &Hdf5File) read_dataset1d[T](dset_name string, mut dataset []T) {
&class_id, &type_size)
assert errc >= 0
assert curdims[0] > 0
assert curdims[0] < math.max_i32
assert curdims[0] < max_i32

dtype := hdftype(dataset[0])
// note: V dims are int while hdf5 dims are u64
Expand All @@ -257,8 +257,8 @@ pub fn (f &Hdf5File) read_dataset1d[T](dset_name string, mut dataset []T) {

// read_dataset2d reads a 2-d numeric array from a named HDF5 dataset in an HDF5 file.
// Replaces the value of the array.
// Maximum of any dimension is math.max_i32 or less (this is checked).
// Maximum total elements is also math.max_i32.
// Maximum of any dimension is max_i32 or less (this is checked).
// Maximum total elements is also max_i32.
pub fn (f &Hdf5File) read_dataset2d[T](dset_name string, mut dataset [][]T) {
mut rank := 0
mut class_id := Hdf5ClassT(0)
Expand All @@ -274,8 +274,8 @@ pub fn (f &Hdf5File) read_dataset2d[T](dset_name string, mut dataset [][]T) {
assert errc >= 0
assert curdims[0] > 0
assert curdims[1] > 0
assert curdims[0] < math.max_i32
assert curdims[1] < math.max_i32
assert curdims[0] < max_i32
assert curdims[1] < max_i32

dtype := hdftype(dataset[0][0])
mut y := make1type[T](int(curdims[0] * curdims[1]))
Expand All @@ -291,8 +291,8 @@ pub fn (f &Hdf5File) read_dataset2d[T](dset_name string, mut dataset [][]T) {

// read_dataset3d reads a 3-d numeric array from a named HDF5 dataset in an HDF5 file.
// Replaces the value of the array with correctly dimensioned array.
// Maximum of any dimension is math.max_i32 or less (this is checked).
// Maximum total elements is also math.max_i32.
// Maximum of any dimension is max_i32 or less (this is checked).
// Maximum total elements is also max_i32.
pub fn (f &Hdf5File) read_dataset3d[T](dset_name string, mut dataset [][][]T) {
mut rank := 0
mut class_id := Hdf5ClassT(0)
Expand All @@ -309,9 +309,9 @@ pub fn (f &Hdf5File) read_dataset3d[T](dset_name string, mut dataset [][][]T) {
assert curdims[0] > 0
assert curdims[1] > 0
assert curdims[2] > 0
assert curdims[0] < math.max_i32
assert curdims[1] < math.max_i32
assert curdims[2] < math.max_i32
assert curdims[0] < max_i32
assert curdims[1] < max_i32
assert curdims[2] < max_i32

dtype := hdftype(dataset[0][0][0])
mut y := make1type[T](int(curdims[0] * curdims[1] * curdims[2]))
Expand Down Expand Up @@ -584,7 +584,7 @@ pub fn (f &Hdf5File) read_attribute[T](dset_name string, attr_name string, mut a

// read_attribute1d reads a 1-d numeric array (vector) from a named HDF5 dataset and named attribute in an HDF5 file.
// Replaces the value of the given array.
// Maximum dimension is math.max_i32 or less (this is checked).
// Maximum dimension is max_i32 or less (this is checked).
pub fn (f &Hdf5File) read_attribute1d[T](dset_name string, attr_name string, mut attr_value []T) !bool {
mut rank := 0
mut class_id := Hdf5ClassT(0)
Expand All @@ -603,8 +603,8 @@ pub fn (f &Hdf5File) read_attribute1d[T](dset_name string, attr_name string, mut
&class_id, &type_size)
assert errc >= 0
assert curdims[0] > 0
assert curdims[0] <= math.max_i32
if curdims[0] > math.max_i32 {
assert curdims[0] <= max_i32
if curdims[0] > max_i32 {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion ml/kmeans.v
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn Kmeans.new(mut data Data[f64], nb_classes int, name string) &Kmeans {

// bins
ndiv := [10, 10] // TODO: make this a parameter
bins := gm.Bins.new(stat.min_x, stat.max_x, ndiv) // TODO: make sure minx and maxx are 2D or 3D; i.e. nb_features ≤ 2
mut bins := gm.Bins.new(stat.min_x, stat.max_x, ndiv) // TODO: make sure minx and maxx are 2D or 3D; i.e. nb_features ≤ 2
mut o := Kmeans{
name: name
data: data
Expand Down
4 changes: 2 additions & 2 deletions prime/prime_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ fn test_is_prime() {
// true
assert is_prime(7_691)
assert is_prime(524_287)
assert is_prime(int(math.max_i32))
assert is_prime(int(max_i32))

// false
assert is_prime(int(math.max_i32) - 1) == false
assert is_prime(int(max_i32) - 1) == false
}

fn test_prime_sieve() {
Expand Down

0 comments on commit c7356d7

Please sign in to comment.