nsi_intermediate/resolve/mod.rs
1//! Graph rewrites: turning ɴsɪ's scene-graph semantics into the flat
2//! facts a renderer wants.
3//!
4//! Both target renderers need this and neither should re-derive it.
5//! Mitsuba has no transform tree, only a `to_world` per shape; MoonRay
6//! resolves geometry to world space too. So the chain has to be
7//! composed here, once.
8
9use crate::{Edge, EdgeKind, HashSet, Node, OwnedArgument, OwnedData, Scene};
10use core::{cmp::Ordering, fmt};
11
12mod attributes;
13mod chain;
14mod instances;
15mod mesh;
16mod motion;
17mod outputs;
18mod primvar;
19
20// The types are here; the walks are in the five modules above. Split
21// at 2530 lines against a stated 300-500, along the seams the code
22// already had: a chain walk, a time rule, an attribute rule, the
23// instancer, and the output chain. `mod.rs` keeps what all five need
24// so none of them has to reach sideways.
25pub use chain::WorldTransforms;
26pub use instances::Instances;
27pub use mesh::{Face, Faces};
28pub use motion::Sampled;
29pub use primvar::{Interpolation, PrimitiveVariable};
30
31/// A 4x4 identity, row-major.
32#[rustfmt::skip]
33pub const IDENTITY: [f64; 16] = [
34 1.0, 0.0, 0.0, 0.0,
35 0.0, 1.0, 0.0, 0.0,
36 0.0, 0.0, 1.0, 0.0,
37 0.0, 0.0, 0.0, 1.0,
38];
39
40/// The ɴsɪ attribute holding a transform node's matrix.
41const TRANSFORMATION_MATRIX: &str = "transformationmatrix";
42
43/// An `instances` node's per-instance matrices.
44const MATRICES: &str = "transformationmatrices";
45
46/// Which prototype each instance draws.
47const MODEL_INDICES: &str = "modelindices";
48
49/// `mesh` topology, which only means something as a pair.
50const FACE_VERTEX_COUNTS: &str = "nvertices";
51const HOLE_COUNTS: &str = "nholes";
52
53/// Positions, and ɴsɪ's indirect-lookup suffix.
54const POSITIONS: &str = "P";
55const INDICES: &str = ".indices";
56
57// `outputlayer` attribute names, spelled once. The defaults they fall
58// back to live with `Scene::output_layer`, next to the specification
59// section that states them.
60const VARIABLE_NAME: &str = "variablename";
61const VARIABLE_SOURCE: &str = "variablesource";
62const LAYER_NAME: &str = "layername";
63const LAYER_TYPE: &str = "layertype";
64const SCALAR_FORMAT: &str = "scalarformat";
65const WITH_ALPHA: &str = "withalpha";
66const DITHERING: &str = "dithering";
67const FILTER: &str = "filter";
68const FILTER_WIDTH: &str = "filterwidth";
69const COLOR_PROFILE: &str = "colorprofile";
70const SORT_KEY: &str = "sortkey";
71
72/// The instances an `instances` node skips.
73const DISABLED: &str = "disabledinstances";
74
75/// Why a scene could not be resolved into flat facts.
76///
77/// Every variant is a scene ɴsɪ permits but this crate refuses to guess
78/// about. Returning a matrix or a binding anyway would be the silent
79/// failure the crate exists to prevent: it renders, with the wrong
80/// answer.
81#[derive(Debug, Clone, PartialEq)]
82#[non_exhaustive]
83pub enum ResolveError {
84 /// A node is connected to more than one parent.
85 ///
86 /// Usually through `objects`; a prototype connected to two
87 /// `instances` nodes is the same problem.
88 ///
89 /// That is ɴsɪ's lightweight instancing: the node appears once per
90 /// path, each with its own world transform. A single matrix cannot
91 /// describe it, so resolving one is refused rather than silently
92 /// answering for whichever parent was connected first.
93 MultipleParents {
94 /// The node with more than one parent.
95 handle: String,
96 /// Every parent, in connection order.
97 parents: Vec<String>,
98 },
99 /// A node carries motion-sampled placement data where a single
100 /// answer was asked for.
101 ///
102 /// Either a `transformationmatrix` on a node in the chain, or an
103 /// `instances` node's `transformationmatrices`, `modelindices` or
104 /// `disabledinstances`. Answering with the static value would hand
105 /// a motion-blurred scene back its unblurred pose, and answering
106 /// with an empty list -- which the instancer path used to do --
107 /// reads as "nothing to draw".
108 ///
109 /// Ask at a time instead:
110 /// [`Scene::world_transform_interpolated_at`],
111 /// [`Scene::placements_at`] or
112 /// [`Scene::instance_transforms_at`].
113 MotionSampledTransform {
114 /// The node whose transform is motion-sampled.
115 handle: String,
116 },
117 /// The transform chain revisits a node. ɴsɪ does not forbid a cycle;
118 /// no correct answer exists for one.
119 Cycle {
120 /// The node the walk arrived at twice.
121 handle: String,
122 },
123 /// The node is not connected to `.root`, directly or through
124 /// transforms.
125 ///
126 /// ɴsɪ: "A node can exist in an nsi context without being connected
127 /// to the root node but in that case it won't affect the render in
128 /// any way." It has no world transform and no gathered attributes,
129 /// and answering identity would put unrendered geometry at the
130 /// origin.
131 Detached {
132 /// The node that does not reach `.root`.
133 handle: String,
134 },
135 /// No node with that handle exists.
136 ///
137 /// Asking about an attribute of a node that was never created is a
138 /// caller mistake, and answering "not sampled" would read as a fact
139 /// about the scene rather than about the question.
140 UnknownHandle {
141 /// The handle that names nothing.
142 handle: String,
143 },
144 /// The node is an instancing prototype, so it has no single world
145 /// transform.
146 ///
147 /// A prototype reaches the scene through an `instances` node, and
148 /// ɴsɪ gives that node "a transformation matrix for each instance".
149 /// Answering with the instancer's own transform would put every
150 /// instance in the same, wrong place.
151 Instanced {
152 /// The `instances` node the prototype is connected to.
153 instancer: String,
154 },
155 /// An `instances` node's `transformationmatrices` is not a whole
156 /// number of 4x4 matrices.
157 MalformedInstanceMatrices {
158 /// The `instances` node.
159 instances: String,
160 /// How many values it carries.
161 values: usize,
162 },
163 /// Two prototype connections share one `index`.
164 ///
165 /// ɴsɪ: connections "must have an integer index attribute if there
166 /// are several, so the models effectively form an ordered list" --
167 /// which a duplicate does not.
168 DuplicateModelIndex {
169 /// The `instances` node.
170 instances: String,
171 /// The index used twice.
172 index: i32,
173 },
174 /// A `modelindices` entry matches no prototype connection's
175 /// `index`.
176 UnknownModelIndex {
177 /// The `instances` node.
178 instances: String,
179 /// The index that matches nothing.
180 model: i32,
181 },
182 /// [`Scene::relative_transform`] was given a node that is not on the
183 /// chain.
184 NotAnAncestor {
185 /// The node whose chain was walked.
186 handle: String,
187 /// The node that is not on it.
188 ancestor: String,
189 },
190 /// A node in the chain is motion-sampled, but has no sample at the
191 /// requested time.
192 ///
193 /// From the **exact-hit** accessors only -- [`Scene::world_transform_at`],
194 /// [`Scene::world_transform_samples`] and
195 /// [`Scene::instance_transforms`] answer where a sample exists and
196 /// refuse elsewhere, which is the right answer to "what did the
197 /// caller record".
198 ///
199 /// For "where is it mid-shutter", ask
200 /// [`Scene::world_transform_interpolated_at`],
201 /// [`Scene::placements_at`] or
202 /// [`Scene::instance_transforms_at`]. Those interpolate
203 /// element-wise, which is the renderer's own model rather than a
204 /// guess -- 3Delight's rotation blur fits component-wise far better
205 /// than slerp -- and they hold the end sample outside the sampled
206 /// range, as it does.
207 ///
208 /// The interpolating accessors still return this for a time that
209 /// names no sample at all, such as a NaN. An earlier version of
210 /// this said the crate never interpolates and that the
211 /// decomposition was the backend's; that stopped being true when
212 /// those accessors were added.
213 MissingSampleAtTime {
214 /// The node with no sample at that time.
215 handle: String,
216 /// The time that was asked for.
217 time: f64,
218 /// The times that node does have, ascending.
219 available: Vec<f64>,
220 },
221 /// A `mesh` has no `nvertices`, which ɴsɪ requires.
222 MissingFaceCounts {
223 /// The mesh.
224 handle: String,
225 },
226 /// A `<name>.indices` is not one entry per face-vertex, or points
227 /// outside the values it indexes.
228 ///
229 /// ɴsɪ says the indices say "which values of the other parameter to
230 /// use" and nothing about how many values there are, so the
231 /// indices are what must match the primitive.
232 MalformedIndices {
233 /// The primitive.
234 handle: String,
235 /// The attribute the indices belong to.
236 attribute: String,
237 /// How many indices there are.
238 indices: usize,
239 /// How many the primitive's face-vertices need.
240 face_vertices: usize,
241 /// How many values there are to index.
242 values: usize,
243 },
244 /// A primitive variable's value count matches none of the four
245 /// interpolations.
246 ///
247 /// Constant is one value, uniform is one per face, vertex is one
248 /// per vertex and face-varying is one per face-vertex. A count
249 /// that is none of those has no meaning ɴsɪ defines, and guessing
250 /// one renders -- plausibly, and wrongly, which is how a wrong
251 /// normal survives review.
252 AmbiguousInterpolation {
253 /// The primitive.
254 handle: String,
255 /// The attribute.
256 attribute: String,
257 /// How many values it carries.
258 values: usize,
259 /// How many faces the primitive has.
260 faces: usize,
261 /// How many vertices.
262 vertices: usize,
263 /// How many face-vertices.
264 face_vertices: usize,
265 },
266 /// `nholes` and `nvertices` disagree.
267 ///
268 /// ɴsɪ: with `nholes` set, the face count is the number of `nholes`
269 /// values, and each face takes `nholes + 1` values from
270 /// `nvertices` -- the outer perimeter and then one per hole. A
271 /// count that does not add up leaves the faces undefined, and a
272 /// backend that reads `nvertices` as one-count-per-face draws a
273 /// different mesh without reporting anything.
274 MalformedFaceCounts {
275 /// The mesh.
276 handle: String,
277 /// How many `nvertices` values the holes ask for.
278 expected: usize,
279 /// How many there are.
280 found: usize,
281 },
282}
283
284impl fmt::Display for ResolveError {
285 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
286 match self {
287 Self::MultipleParents { handle, parents } => write!(
288 f,
289 "ɴsɪ node {handle:?} has {} parents ({}); that is \
290 instancing, which has one world transform per path, not \
291 one overall",
292 parents.len(),
293 parents.join(", ")
294 ),
295 Self::MotionSampledTransform { handle } => write!(
296 f,
297 "ɴsɪ node {handle:?} carries motion-sampled placement \
298 data; the static value would be the wrong answer, so \
299 ask at a time instead"
300 ),
301 Self::Cycle { handle } => write!(
302 f,
303 "ɴsɪ transform chain revisits node {handle:?}; a cyclic \
304 scene has no world transform"
305 ),
306 Self::UnknownHandle { handle } => {
307 write!(f, "no ɴsɪ node is named {handle:?}")
308 }
309 Self::Detached { handle } => write!(
310 f,
311 "ɴsɪ node {handle:?} is not connected to {root:?}, so it \
312 is not in the scene and has no world transform",
313 root = crate::ROOT
314 ),
315 Self::Instanced { instancer } => write!(
316 f,
317 "ɴsɪ node is an instancing prototype of {instancer:?}, \
318 which carries one transform per instance; there is no \
319 single world transform for it"
320 ),
321 Self::MalformedInstanceMatrices { instances, values } => {
322 write!(
323 f,
324 "ɴsɪ node {instances:?} has {values} values in \
325 transformationmatrices, which is not a whole number \
326 of 4x4 matrices"
327 )
328 }
329 Self::DuplicateModelIndex { instances, index } => write!(
330 f,
331 "ɴsɪ node {instances:?} has two sourcemodels connections \
332 at index {index}, so its models are not an ordered list"
333 ),
334 Self::UnknownModelIndex { instances, model } => write!(
335 f,
336 "ɴsɪ node {instances:?} selects model index {model}, which \
337 matches no sourcemodels connection"
338 ),
339 Self::NotAnAncestor { handle, ancestor } => write!(
340 f,
341 "ɴsɪ node {ancestor:?} is not on {handle:?}'s chain, so \
342 there is no transform of one relative to the other"
343 ),
344 Self::MissingSampleAtTime {
345 handle,
346 time,
347 available,
348 } => write!(
349 f,
350 "ɴsɪ node {handle:?} has no transform sample at time \
351 {time}; it has {available:?}, and this crate does not \
352 interpolate between them"
353 ),
354 Self::MalformedIndices {
355 handle,
356 attribute,
357 indices,
358 face_vertices,
359 values,
360 } => write!(
361 f,
362 "ɴsɪ primitive {handle:?} has {indices} {attribute:?} \
363 indices for {face_vertices} face-vertices into {values} \
364 values; indices are read per face-vertex"
365 ),
366 Self::AmbiguousInterpolation {
367 handle,
368 attribute,
369 values,
370 faces,
371 vertices,
372 face_vertices,
373 } => write!(
374 f,
375 "ɴsɪ primitive {handle:?} has {values} {attribute:?} values, \
376 which is neither constant (1), per face ({faces}), per \
377 vertex ({vertices}) nor per face-vertex ({face_vertices})"
378 ),
379 Self::MissingFaceCounts { handle } => write!(
380 f,
381 "ɴsɪ mesh {handle:?} sets no \"nvertices\", which ɴsɪ \
382 requires; its faces are undefined"
383 ),
384 Self::MalformedFaceCounts {
385 handle,
386 expected,
387 found,
388 } => write!(
389 f,
390 "ɴsɪ mesh {handle:?} has \"nholes\" asking for {expected} \
391 \"nvertices\" values and carries {found}; with holes, each \
392 face takes its outer perimeter plus one count per hole"
393 ),
394 }
395 }
396}
397
398impl core::error::Error for ResolveError {}
399
400/// What an ɴsɪ `attributes` node resolves to for one piece of geometry.
401#[derive(Debug, Clone, PartialEq, Eq, Hash)]
402#[non_exhaustive]
403pub struct Binding {
404 /// Every `attributes` node gathered along the path, nearest the
405 /// geometry first, then in connection order.
406 ///
407 /// The `priority` on a `geometryattributes` connection deliberately
408 /// does **not** reorder this: 3Delight ignores it, whatever the
409 /// specification says. A priority on a *shader* connection is
410 /// honoured; see [`Binding::surface_shader`] and `research.md` D12.
411 ///
412 /// ɴsɪ gathers attributes along the whole path and considers
413 /// *every* node on it -- "one attributes node can set object
414 /// visibility and another can set the surface shader" -- so this is
415 /// a list, not a winner. A backend looking for one attribute takes
416 /// the first node in this list that defines it -- correct only while
417 /// no node sets `ATTR.priority` and the attribute is not a
418 /// visibility one. [`Scene::attribute_value`] applies those two
419 /// rules and is the safe way to ask.
420 ///
421 /// When this [`Binding`] came from a [`Placement`], ask
422 /// [`Scene::attribute_value_along`] with that placement's path
423 /// instead: `attribute_value` takes a geometry, so it refuses the
424 /// multi-parent node a placement exists for.
425 ///
426 /// The handles are returned rather than their contents because what
427 /// lives on them -- visibility flags above all -- is encoded
428 /// differently by each renderer, and inventing a common shape for it
429 /// here would be guesswork.
430 pub attributes: Vec<String>,
431 /// The shader reached through `surfaceshader`, resolved across every
432 /// gathered node by the same rule, using the priority of the
433 /// `surfaceshader` connection itself.
434 ///
435 /// `None` when nothing on the path sets one.
436 pub surface_shader: Option<String>,
437 /// The `displacementshader`, resolved the same way.
438 pub displacement_shader: Option<String>,
439 /// The `volumeshader`, resolved the same way.
440 pub volume_shader: Option<String>,
441}
442
443/// ɴsɪ's ray types: the suffixes a `visibility.<ray>` attribute takes.
444///
445/// Spelled out rather than accepting any suffix, because
446/// `visibility.set.subsurface` is a *connection* to a `set` node and not
447/// a per-ray visibility int; treating it as the more specific form of
448/// `visibility` would rank a connection against a flag.
449///
450/// Public because a backend building a visibility mask needs exactly
451/// this list, and a second copy of it would drift from this one.
452pub const RAY_TYPES: [&str; 8] = [
453 "camera",
454 "diffuse",
455 "hair",
456 "reflection",
457 "refraction",
458 "shadow",
459 "specular",
460 "volume",
461];
462
463/// One placement of a geometry in the scene.
464///
465/// ɴsɪ's *lightweight* instancing: connecting a node to two transforms
466/// draws it twice, once per path. Rendered, a quad under two transforms
467/// translated `-2` and `+2` appears at both positions, and putting
468/// `visibility 1` on one parent and `visibility 0` on the other draws
469/// **one** copy -- so a path carries its own attributes as well as its
470/// own transform, and a backend emitting one instance per placement
471/// needs both together.
472#[derive(Debug, Clone, PartialEq)]
473#[non_exhaustive]
474pub struct Placement {
475 /// The nodes from the geometry to `.root`, geometry first.
476 ///
477 /// Two placements of one geometry differ here, and that is what
478 /// makes them distinguishable: the handle alone does not.
479 pub path: Vec<String>,
480 /// The world transform along this path.
481 pub transform: [f64; 16],
482 /// What binds along this path, or `None` when nothing does.
483 ///
484 /// The same shape [`Scene::geometry_binding`] returns, resolved
485 /// against this path rather than against "the" path.
486 pub binding: Option<Binding>,
487}
488
489/// The winning definition of one attribute, gathered along a path.
490///
491/// Returned by [`Scene::attribute_value`].
492#[derive(Debug, Clone, Copy, PartialEq)]
493#[non_exhaustive]
494pub struct AttributeValue<'a> {
495 /// The node the winning definition sits on.
496 ///
497 /// Usually an `attributes` node. For a shader attribute it can be
498 /// the geometry itself, which ɴsɪ ranks above every container.
499 pub node: &'a str,
500 /// The attribute that actually won, which is not always the one
501 /// asked for: in [`Scene::attribute_value`] a `visibility.<ray>`
502 /// query falls back to the less specific `visibility`, and this is
503 /// how a backend tells the two apart.
504 /// [`Scene::shader_attribute_value`] performs no such fallback, so
505 /// there it always matches the query.
506 pub name: &'a str,
507 /// The definition itself, or `None` when the winning node carries
508 /// only `<name>.priority`.
509 ///
510 /// 3Delight reads a lone `ATTR.priority` as a definition of `ATTR`
511 /// **at its ɴsɪ default**, and it wins on the strength of that
512 /// priority; [`Scene::attribute_value`] has the rendered evidence.
513 /// This crate does not carry ɴsɪ's per-attribute defaults, so it
514 /// names the winner and leaves the value to the backend: `None`
515 /// means *the default of [`AttributeValue::name`]*, never
516 /// *undefined*.
517 pub arg: Option<&'a OwnedArgument>,
518 /// The `ATTR.priority` that selected it; `0` when none is set.
519 pub priority: i32,
520}
521
522/// One renderable output: a camera paired with a screen, and the AOVs
523/// written from it.
524/// `Eq` and `Hash` are absent for the reason `OwnedArgument`'s are
525/// (research D7): a layer carries `filter_width`, and a float has no
526/// total equality to derive one from.
527#[derive(Debug, Clone, PartialEq)]
528#[non_exhaustive]
529pub struct RenderOutput {
530 /// The camera the screen is connected to.
531 pub camera: String,
532 /// The screen, which is what carries resolution and oversampling.
533 pub screen: String,
534 /// AOVs in connection order; may be empty.
535 pub layers: Vec<OutputLayer>,
536}
537
538/// One instance, borrowing the matrix the scene already holds.
539///
540/// [`Scene::instance_transforms`] copies: for a set-dressing
541/// instancer with a million entries that is 136 MB of `Instance`
542/// against the 128 MB `doublematrix` array it was copied from.
543/// [`Scene::instances`] hands out these instead, which is the shape a
544/// renderer's own instancer wants -- a prototype index and a matrix it
545/// can read in place.
546#[derive(Debug, Clone, Copy, PartialEq)]
547#[non_exhaustive]
548pub struct InstanceRef<'a> {
549 /// Which prototype this instance draws, as a position in
550 /// [`Scene::instance_sources`].
551 pub source: usize,
552 /// This instance's transform, in the `instances` node's space.
553 pub transform: &'a [f64; 16],
554}
555
556/// One instance an `instances` node places.
557///
558/// ɴsɪ gives an `instances` node "a transformation matrix for each
559/// instance" and an optional `modelindices` selecting which prototype
560/// each uses. This pairs the two, so a backend building a MoonRay
561/// `InstanceGeometry` or a Mitsuba `shapegroup` reference does not have
562/// to.
563#[derive(Debug, Clone, PartialEq)]
564#[non_exhaustive]
565pub struct Instance {
566 /// Which prototype this instance draws, as a position in
567 /// [`Scene::instance_sources`].
568 ///
569 /// ɴsɪ matches `modelindices` against "the index attribute of the
570 /// model connection", not against connection order, so this is the
571 /// resolved position rather than the raw value.
572 pub source: usize,
573 /// This instance's transform, in the `instances` node's space.
574 pub transform: [f64; 16],
575}
576
577/// One AOV, resolved: what to output, how to encode it, and where it
578/// goes.
579///
580/// Every field but `handle` and `drivers` is an `outputlayer`
581/// attribute, **with the specification's default already applied** --
582/// `variablesource` "shader", `layertype` "color", `scalarformat`
583/// "uint8", `filter` "blackman-harris", `filterwidth` 3.0,
584/// `withalpha` and `dithering` off. A backend that re-derives these
585/// gets them subtly wrong: the defaults are stated once in the
586/// specification and nowhere in the scene, so a layer that sets none
587/// of them still means "a uint8 colour from a shader closure".
588#[derive(Debug, Clone, PartialEq)]
589#[non_exhaustive]
590pub struct OutputLayer {
591 /// The `outputlayer` node's handle.
592 pub handle: String,
593 /// The variable to output. `None` when the layer does not name one,
594 /// which is a scene error rather than a default.
595 pub variable_name: Option<String>,
596 /// Where the variable is read from: `"shader"`, `"attribute"` or
597 /// `"builtin"`. Defaults to `"shader"`.
598 pub variable_source: String,
599 /// The layer's name as the driver writes it -- the layer name
600 /// inside an EXR, say. `None` when unset; ɴsɪ gives no default, so
601 /// a driver picks its own.
602 pub layer_name: Option<String>,
603 /// `"scalar"`, `"color"`, `"vector"` or `"quad"`. Defaults to
604 /// `"color"`.
605 pub layer_type: String,
606 /// The quantisation: `"uint8"` through `"float"`. Defaults to
607 /// `"uint8"`, which surprises a backend expecting float AOVs.
608 pub scalar_format: String,
609 /// Whether an alpha channel is included. Defaults to `false`.
610 pub with_alpha: bool,
611 /// Whether integer scalars are dithered. Defaults to `false`.
612 pub dithering: bool,
613 /// The reconstruction filter. Defaults to `"blackman-harris"`.
614 pub filter: String,
615 /// The filter's diameter in pixels. Defaults to `3.0`, and ɴsɪ says
616 /// it is not applied for `"box"` or `"zmin"`.
617 pub filter_width: f64,
618 /// An ᴏᴄɪᴏ colour profile to apply before quantisation, if set.
619 pub color_profile: Option<String>,
620 /// The ordering key among layers on one driver, if set.
621 ///
622 /// See `drivers`: this crate applies it rather than leaving it to
623 /// the backend.
624 pub sort_key: Option<i32>,
625 /// A layer may fan out to several drivers -- a file and a display,
626 /// say.
627 ///
628 /// In connection order. ɴsɪ orders *layers* on a driver by
629 /// `sortkey`, not drivers on a layer, so this stays as connected.
630 pub drivers: Vec<String>,
631}
632
633/// Row-major 4x4 product, `a` then `b`.
634///
635/// ɴsɪ uses the RenderMan row-vector convention: a point is a row and
636/// transforms multiply on the right, so `p * a * b` applies `a` first.
637/// Composing a child with its parent is therefore `mul(child, parent)`,
638/// not the other way round.
639fn mul(a: [f64; 16], b: [f64; 16]) -> [f64; 16] {
640 let mut out = [0.0; 16];
641 for row in 0..4 {
642 for col in 0..4 {
643 let mut sum = 0.0;
644 for k in 0..4 {
645 sum += a[row * 4 + k] * b[k * 4 + col];
646 }
647 out[row * 4 + col] = sum;
648 }
649 }
650 out
651}
652
653#[cfg(test)]
654mod tests;