Advanced Octave A03 — Types and shapes across the Bridge

by Giux GX-TXT, octave-en, scripts-en 3 min read

Advanced GNU Octave with GX-TXT · Module 01

A03 — Tipi e forma attraverso il Bridge

A matrix is not only a sequence of numbers: its size establishes how to associate values, samples and variables. Let’s see how a public operation of GX-TXT receives data structured by GNU Octave and returns the result.

Objectives and prerequisites

We already know matrices, structs and cell arrays from introductory course and API controls from A01–A02 lessons. Now we distinguish the container of gxtxt_api_call arguments, the structure that describes a workmanship and the matrix contained in the result. The test uses GX-TXT dev112-P011-bis and GNU Octave 9.4.0.

A matrix and a climb

Import forma_bridge.m to the Octave Script Workspace, record it in the Session and run it from the Runner.

% Advanced Octave course A03: matrix shape across the public Bridge.
% SPDX-License-Identifier: GPL-3.0-or-later
gxtxt_api_require({'NUMERIC_API_v1@1'});
A = [1, 2; 3, 4];
a = struct('kind', 'matrix', 'value', A);
b = struct('kind', 'scalar', 'value', 2);
result = gxtxt_api_call('NUMERIC_API_v1', 'array_binary', ...
                        {'multiply', a, b});
fprintf('Input matrix: %d x %d\n', size(A,1), size(A,2));
fprintf('Result fields:\n');
disp(fieldnames(result));
disp(result);

The call uses a cell array for the positional arguments of the operation: the name multiply and two structures. In this example, a declares a matrix-type operation and b a climber. The operation expands the scale and multiplies each element. The returned structure contains the values field.

In the result observed the matrix is [2, 4; 6, 8]: the two rows and the two columns maintain the required layout. To use it later, you can assign B = result.values and check size(B) before associating it with labels or coordinates. A small example also allows you to control the order of values, not only the total number.

Form, type and meaning

For array_binary the numerical contract distinguishes expansion of a scalar and operations between two non-scale arrays: the latter must have a compatible form according to the rules of the API. Do not assume that a line vector and a column represent the same object. If the semantic requires a column, it uses an explicit transformation and verifies the size.

The Bridge also supports nested cells and structures; their meaning depends on the single operation. Complex numbers may require a specific contract, for example, separate real and imaginary components: do not assume that any real array operation accepts them. Always read the provider’s documentation before you build the topics.

Finally, a correct dimension does not show that the first line represents the right sample or that the units are consistent: such associations are part of the scientific model of the script.

Exercise

  1. Change the climb to 3 and predict the matrix before running the program.
  2. Why is result.values and result not the same type of object?
  3. How would you check that two columns from different Dataset refer to the same moments?

Worked solution

  1. [3, 6; 9, 12].
  2. The first is the numerical field contained in the returned structure; the second is the entire structure.
  3. By explicitly comparing time coordinates, units and lengths, without deducing alignment from the form alone.

The next lesson will distinguish empty values and missing information.

Download the Module 01 scripts (ZIP)

#GNU Octave #GX-TXT #GX-TXT public APIs

Other steps of this project

Leave a Reply

Your email address will not be published. Required fields are marked *