I'm porting to kotlin this code ```snap_descriptor...
# science
e
I'm porting to kotlin this code
Copy code
snap_descriptors_np = extract_compute_np(
    lmp,
    "bgrid",
    0,
    2,
    (nz, ny, nx, self.fingerprint_length),
    use_fp64=use_fp64,
)
lmp.close()

# switch from x-fastest to z-fastest order (swaps 0th and 2nd dimension)
snap_descriptors_np = snap_descriptors_np.transpose([2, 1, 0, 3])
where
extract_compute_np
returns a flat doubleArray representing an ndarray of
[nz, ny, nx, self.fingerprint_length]
now, I have to swap the 0 and 2nd dimensions and I'm trying to do this:
Copy code
Array(nx) { x ->
    Array(ny) { y ->
        Array(nz) { z ->
            val ofsX = x * (ny * nz * fingerprintLength)
            val ofsY = y * (nz * fingerprintLength)
            val ofsZ = z * fingerprintLength
            DoubleArray(fingerprintLength) { doubles[ofsX + ofsY + ofsZ + it] }
        }
    }
}
but it looks like it's wrong, anyone spots the problem?
g
I tried solving the problem myself. All you have to do is to write a transformation to
Array<Array<Array<DoubleArray>>>
with initial ndarray
[nz, ny, nx, fingerprintLength]
and then replace
Array(nx) { x ->
with
Array(nz) { z ->
and vice versa to swap
x
and
z
dimensions. Here is how I solved it: https://pl.kotl.in/y3FM_tGzS
👍 1
e
thanks Gleb, that looks working!
I was going a little mad
a
I think that @Ролан did something similar in tensor extensions for KMath, but it makes sense only if you need a zero-copy solution.