Skip to content

Commit 0ad212a

Browse files
Guillaume Frauxantoinewdg
Guillaume Fraux
authored andcommitted
Update lumol-core dependencies
1 parent 740eee0 commit 0ad212a

File tree

3 files changed

+63
-87
lines changed

3 files changed

+63
-87
lines changed

src/core/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ name = "lumol"
1414
chemfiles = "0.7"
1515
rand = "0.3"
1616
log = "0.3"
17-
log-once = "0.1.1"
17+
log-once = "0.1"
1818
special = "0.7"
19-
bitflags = "0.7"
20-
ndarray = "0.6"
19+
bitflags = "0.8"
20+
ndarray = "0.8"
2121
lazy_static = "0.2"
2222
num-traits = "0.1"
2323

src/core/src/sys/cache.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl EnergyCache {
6666

6767
/// Clear all values in the cache by setting them to 0
6868
fn clear(&mut self) {
69-
self.pairs_cache.assign(0.0);
69+
self.pairs_cache.fill(0.0);
7070
self.pairs = 0.0;
7171
self.pairs_tail = 0.0;
7272
self.bonds = 0.0;
@@ -248,9 +248,9 @@ impl EnergyCache {
248248
cache.coulomb += coulomb_delta;
249249
cache.global += global_delta;
250250

251-
let (n, m) = new_pairs.shape();
251+
let (n, m) = new_pairs.dim();
252252
debug_assert_eq!(n, m);
253-
debug_assert_eq!((n, m), cache.pairs_cache.shape());
253+
debug_assert_eq!((n, m), cache.pairs_cache.dim());
254254
// only loop over the indices that actually changed
255255
for &i in &idxes {
256256
for j in 0..n {
@@ -333,9 +333,9 @@ impl EnergyCache {
333333
cache.coulomb = new_coulomb;
334334
cache.global = new_global;
335335

336-
let (n, m) = new_pairs.shape();
336+
let (n, m) = new_pairs.dim();
337337
debug_assert_eq!(n, m);
338-
debug_assert_eq!((n, m), cache.pairs_cache.shape());
338+
debug_assert_eq!((n, m), cache.pairs_cache.dim());
339339
for (i, mi) in system.molecules().iter().enumerate() {
340340
for mj in system.molecules().iter().skip(i + 1) {
341341
for pi in mi.iter() {

src/core/src/types/arrays.rs

+55-79
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Copyright (C) 2015-2016 Lumol's contributors — BSD license
33

44
//! Multi-dimensional arrays based on ndarray
5-
use ndarray::{Array, Ix};
5+
use ndarray;
66

7-
use std::ops::{Index, IndexMut};
7+
use std::ops::{Index, IndexMut, Deref, DerefMut};
88
use types::Zero;
99

1010
/// Two dimensional tensors, based on ndarray.
@@ -23,21 +23,7 @@ use types::Zero;
2323
/// assert_eq!(a[(0, 4)], 7.0);
2424
/// ```
2525
#[derive(Debug, Clone, PartialEq)]
26-
pub struct Array2<T>(Array<T, (Ix, Ix)>);
27-
28-
impl<T> Array2<T> {
29-
/// Get the shape of the array
30-
/// # Examples
31-
/// ```
32-
/// # use lumol::types::Array2;
33-
/// let a: Array2<f64> = Array2::zeros((3, 5));
34-
/// assert_eq!(a.shape(), (3, 5));
35-
/// ```
36-
pub fn shape(&self) -> (Ix, Ix) {
37-
let shape = self.0.shape();
38-
(shape[0], shape[1])
39-
}
40-
}
26+
pub struct Array2<T>(ndarray::Array2<T>);
4127

4228
impl<T: Zero + Clone> Array2<T> {
4329
/// Create a new `Array2` of the specified `size` filled with the
@@ -50,8 +36,8 @@ impl<T: Zero + Clone> Array2<T> {
5036
/// let a: Array2<f64> = Array2::zeros((8, 5));
5137
/// assert_eq!(a[(6, 2)], 0.0);
5238
/// ```
53-
pub fn zeros(size: (Ix, Ix)) -> Array2<T> {
54-
Array2(Array::<T, (Ix, Ix)>::zeros(size))
39+
pub fn zeros(size: (usize, usize)) -> Array2<T> {
40+
Array2(ndarray::Array2::zeros(size))
5541
}
5642

5743
/// Resize the array if the current size is not `size`, and fill the
@@ -73,28 +59,13 @@ impl<T: Zero + Clone> Array2<T> {
7359
/// a.resize_if_different((8, 9));
7460
/// assert_eq!(a[(3, 3)], 0.0);
7561
/// ```
76-
pub fn resize_if_different(&mut self, size: (Ix, Ix)) {
77-
if self.0.shape() != &[size.0, size.1] {
62+
pub fn resize_if_different(&mut self, size: (usize, usize)) {
63+
if self.dim() != size {
7864
*self = Array2::zeros(size);
7965
}
8066
}
8167
}
8268

83-
impl<T: Clone> Array2<T> {
84-
/// Assign the given scalar to all entries in this array
85-
/// # Examples
86-
/// ```
87-
/// # use lumol::types::Array2;
88-
/// let mut a = Array2::zeros((8, 5));
89-
/// a.assign(33.0);
90-
///
91-
/// assert_eq!(a[(3, 4)], 33.0);
92-
/// ```
93-
pub fn assign(&mut self, value: T) {
94-
self.0.assign_scalar(&value);
95-
}
96-
}
97-
9869
impl<T: Default> Array2<T> {
9970
/// Create a new `Array2` of the specified `size` filled with the
10071
/// `Default::default` return value.
@@ -108,30 +79,44 @@ impl<T: Default> Array2<T> {
10879
///
10980
/// assert_eq!(a, b);
11081
/// ```
111-
pub fn default(size: (Ix, Ix)) -> Array2<T> {
112-
Array2(Array::<T, (Ix, Ix)>::default(size))
82+
pub fn default(size: (usize, usize)) -> Array2<T> {
83+
Array2(ndarray::Array2::default(size))
11384
}
11485
}
11586

116-
impl<T> Index<(Ix, Ix)> for Array2<T> {
87+
impl<T> Index<(usize, usize)> for Array2<T> {
11788
type Output = T;
118-
fn index(&self, index: (Ix, Ix)) -> &T {
89+
fn index(&self, index: (usize, usize)) -> &T {
11990
unsafe {
12091
// ndarray does the check for us in debug builds
12192
self.0.uget(index)
12293
}
12394
}
12495
}
12596

126-
impl<T> IndexMut<(Ix, Ix)> for Array2<T> {
127-
fn index_mut(&mut self, index: (Ix, Ix)) -> &mut T {
97+
impl<T> IndexMut<(usize, usize)> for Array2<T> {
98+
fn index_mut(&mut self, index: (usize, usize)) -> &mut T {
12899
unsafe {
129100
// ndarray does the check for us in debug builds
130101
self.0.uget_mut(index)
131102
}
132103
}
133104
}
134105

106+
impl<T> Deref for Array2<T> {
107+
type Target = ndarray::Array2<T>;
108+
109+
fn deref(&self) -> &ndarray::Array2<T> {
110+
&self.0
111+
}
112+
}
113+
114+
impl<T> DerefMut for Array2<T> {
115+
fn deref_mut(&mut self) -> &mut ndarray::Array2<T> {
116+
&mut self.0
117+
}
118+
}
119+
135120
/******************************************************************************/
136121

137122
/// Three dimensional tensors, based on ndarray
@@ -150,23 +135,9 @@ impl<T> IndexMut<(Ix, Ix)> for Array2<T> {
150135
/// assert_eq!(a[(0, 4, 1)], 7.0);
151136
/// ```
152137
#[derive(Debug, Clone, PartialEq)]
153-
pub struct Array3<T>(Array<T, (Ix, Ix, Ix)>);
138+
pub struct Array3<T>(ndarray::Array3<T>);
154139

155140
impl<T> Array3<T> {
156-
/// Get the shape of the array.
157-
/// # Examples
158-
/// ```
159-
/// # use lumol::types::Array3;
160-
/// let a: Array3<f64> = Array3::zeros((3, 5, 7));
161-
/// assert_eq!(a.shape(), (3, 5, 7));
162-
/// ```
163-
pub fn shape(&self) -> (Ix, Ix, Ix) {
164-
let shape = self.0.shape();
165-
(shape[0], shape[1], shape[2])
166-
}
167-
}
168-
169-
impl<T: Zero + Clone> Array3<T> {
170141
/// Create a new `Array3` of the specified `size` filled with the
171142
/// `Zero::zero` return value.
172143
///
@@ -177,8 +148,8 @@ impl<T: Zero + Clone> Array3<T> {
177148
/// let a: Array3<f64> = Array3::zeros((8, 5, 2));
178149
/// assert_eq!(a[(6, 2, 0)], 0.0);
179150
/// ```
180-
pub fn zeros(size: (Ix, Ix, Ix)) -> Array3<T> {
181-
Array3(Array::<T, (Ix, Ix, Ix)>::zeros(size))
151+
pub fn zeros(size: (usize, usize, usize)) -> Array3<T> where T: Zero + Clone {
152+
Array3(ndarray::Array3::zeros(size))
182153
}
183154

184155
/// Resize the array if the current size is not `size`, and fill the
@@ -200,21 +171,12 @@ impl<T: Zero + Clone> Array3<T> {
200171
/// a.resize_if_different((8, 5, 6));
201172
/// assert_eq!(a[(3, 3, 3)], 0.0);
202173
/// ```
203-
pub fn resize_if_different(&mut self, size: (Ix, Ix, Ix)) {
174+
pub fn resize_if_different(&mut self, size: (usize, usize, usize)) where T: Zero + Clone {
204175
if self.0.shape() != &[size.0, size.1, size.2] {
205176
*self = Array3::zeros(size);
206177
}
207178
}
208-
}
209-
210-
impl<T: Clone> Array3<T> {
211-
/// Assign the given scalar to all entries in this array
212-
pub fn assign(&mut self, value: T) {
213-
self.0.assign_scalar(&value);
214-
}
215-
}
216179

217-
impl<T: Default> Array3<T> {
218180
/// Create a new `Array3` of the specified `size` filled with the
219181
/// `Default::default` return value.
220182
/// `Default::default` return value.
@@ -228,30 +190,44 @@ impl<T: Default> Array3<T> {
228190
///
229191
/// assert_eq!(a, b);
230192
/// ```
231-
pub fn default(size: (Ix, Ix, Ix)) -> Array3<T>{
232-
Array3(Array::<T, (Ix, Ix, Ix)>::default(size))
193+
pub fn default(size: (usize, usize, usize)) -> Array3<T> where T: Default{
194+
Array3(ndarray::Array3::default(size))
233195
}
234196
}
235197

236-
impl<T> Index<(Ix, Ix, Ix)> for Array3<T> {
198+
impl<T> Index<(usize, usize, usize)> for Array3<T> {
237199
type Output = T;
238-
fn index(&self, index: (Ix, Ix, Ix)) -> &T {
200+
fn index(&self, index: (usize, usize, usize)) -> &T {
239201
unsafe {
240202
// ndarray does the check for us in debug builds
241203
self.0.uget(index)
242204
}
243205
}
244206
}
245207

246-
impl<T> IndexMut<(Ix, Ix, Ix)> for Array3<T> {
247-
fn index_mut(&mut self, index: (Ix, Ix, Ix)) -> &mut T {
208+
impl<T> IndexMut<(usize, usize, usize)> for Array3<T> {
209+
fn index_mut(&mut self, index: (usize, usize, usize)) -> &mut T {
248210
unsafe {
249211
// ndarray does the check for us in debug builds
250212
self.0.uget_mut(index)
251213
}
252214
}
253215
}
254216

217+
impl<T> Deref for Array3<T> {
218+
type Target = ndarray::Array3<T>;
219+
220+
fn deref(&self) -> &ndarray::Array3<T> {
221+
&self.0
222+
}
223+
}
224+
225+
impl<T> DerefMut for Array3<T> {
226+
fn deref_mut(&mut self) -> &mut ndarray::Array3<T> {
227+
&mut self.0
228+
}
229+
}
230+
255231
#[cfg(test)]
256232
mod tests {
257233
mod array2 {
@@ -283,11 +259,11 @@ mod tests {
283259
#[test]
284260
fn resize() {
285261
let mut a: Array2<f64> = Array2::zeros((3, 4));
286-
assert_eq!(a.shape(), (3, 4));
262+
assert_eq!(a.dim(), (3, 4));
287263
a[(1, 1)] = 42.0;
288264

289265
a.resize_if_different((7, 90));
290-
assert_eq!(a.shape(), (7, 90));
266+
assert_eq!(a.dim(), (7, 90));
291267
assert_eq!(a[(1, 1)], 0.0);
292268

293269
a[(1, 1)] = 42.0;
@@ -355,11 +331,11 @@ mod tests {
355331
#[test]
356332
fn resize() {
357333
let mut a: Array3<f64> = Array3::zeros((3, 4, 5));
358-
assert_eq!(a.shape(), (3, 4, 5));
334+
assert_eq!(a.dim(), (3, 4, 5));
359335
a[(1, 1, 1)] = 42.0;
360336

361337
a.resize_if_different((7, 90, 8));
362-
assert_eq!(a.shape(), (7, 90, 8));
338+
assert_eq!(a.dim(), (7, 90, 8));
363339
assert_eq!(a[(1, 1, 1)], 0.0);
364340

365341
a[(1, 1, 1)] = 42.0;

0 commit comments

Comments
 (0)